wrdv / testme-idea

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

Feature/add verify #23

Closed huangliang992 closed 4 months ago

huangliang992 commented 4 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 3 months ago

Released in version 6.2.0