0

我有一个表中的行列表和一个 moveUpButton,它将选定的行向上移动一步。它工作正常,但我需要为此方法使用白盒编写单元测试。

这是我的代码:

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)
    } 
  }
}

我到目前为止的单元测试是

@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));
}
4

0 回答 0