wrdv / testme-idea

TestMe IntelliJ IDEA Plugin - Auto generates Unit Test code
http://weirddev.com/testme
Other
171 stars 65 forks source link

Feature/add verify #23

Closed huangliang992 closed 8 months ago

huangliang992 commented 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

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");
    }
}
yaronyam commented 8 months ago

Released in version 6.2.0