0

I have a list of rows in the table and a moveUpButton, it will move selected rows to one step up. It works fine but I need to write unit test using white box for this method.

Here is my code:

public void registerMoveUpBut(final Button moveUpBut){
   this.moveUpBut = moveUpBut;
   moveUpBut.addActionListener(new ActionListener){

   public void actionPerformed(ActionEvent event){
      Transferevent obj = transModel.getElementAt(TransTable.getSelectedRow);

      TransferObj transferObj = new TransferObj(obj);
      transferObj.setEventType(TransferTypeEnum.UP);
      transferObj.setEventNum(obj.getEventNum()-1)
    } 
  }
}

Unit test I have so far is

@Test
public void testMoveUpBut(){
   Controller Con = mock(Controller.class)
   JButton moveUpBut = Whitebox.getInternalState(Con, "moveUpBut");
   //here i want to use something like addListener so that it will pass through my   
   //method and use ArgumentCaptor to verify whether it's population the data or 
   //not. Can you pls help with that, Thank you!
   moveUpBut.addActionerListener() //something like this
   ArgumentCaptor<Controller>argument = ArgumentCaptor.forClass(Controller.class);
   verify().doSomething(argumentCapture));
}
SiKing
  • 10,003
  • 10
  • 39
  • 90
putin
  • 21
  • 6

0 Answers0