Closed huangliang992 closed 8 months ago
add verify for void return type of method calls,
for exemple
public class Foo{ private TechFighter techFighter; private Supplier<Integer> result; public String fight(Fire withFire,String foeName) { techFighter.initSelfArming("gun"); String fail = techFighter.fight(withFire); ConvertedBean convertedBean = techFighter.surrender(new Fear(), new Ice(), 666); convertedBean.setSomeNum(result.get()); return "returning response from dependency "+ fail + " " + convertedBean.getMyString(); } }
add the verify for techFighter.initSelfArming method calls like
techFighter.initSelfArming
public class FooTest { @Mock TechFighter techFighter; @Mock Supplier<Integer> result; @InjectMocks Foo foo; @BeforeMethod public void setUp() { MockitoAnnotations.initMocks(this); } @Test public void testFight() { when(techFighter.fight(any())).thenReturn("fightResponse"); when(techFighter.surrender(any(), any(), anyInt())).thenReturn(new ConvertedBean()); when(result.get()).thenReturn(Integer.valueOf(0)); String result = foo.fight(new Fire(), "foeName"); verify(techFighter).initSelfArming(anyString()); Assert.assertEquals(result, "replaceMeWithExpectedResult"); } }
Released in version 6.2.0
add verify for void return type of method calls,
for exemple
add the verify for
techFighter.initSelfArming
method calls like