How to verify multiple method calls with different params

前端 未结 7 1683
自闭症患者
自闭症患者 2020-12-13 08:14

I have the following method that I wish to verify behaviour on.

public void methodToTest(Exception e, ActionErrors errors) {
    ...

    errors.add("exc         


        
7条回答
  •  庸人自扰
    2020-12-13 08:36

    Further reading has led me to try using ArgumentCaptors and the following works, although much more verbose than I would like.

    ArgumentCaptor argument = ArgumentCaptor.forClass(String.class);
    
    verify(errors, atLeastOnce()).add(argument.capture(), any(ActionMessage.class));
    
    List values = argument.getAllValues();
    
    assertTrue(values.contains("exception.message"));
    assertTrue(values.contains("exception.detail"));
    

提交回复
热议问题