Using Mockito in Java how to verify a method was called only once with exact parameters ignoring calls to other methods?
Sample code:
public class MockitoTest {
interface Foo {
void add(String str);
void clear();
}
@Test
public void testAddWasCalledOnceWith1IgnoringAllOtherInvocations() throws Exception {
// when
Foo foo = Mockito.mock(Foo.class);
foo.add("1");
foo.add("2"); // !!! don't allow it
foo.clear();
// then
Mockito.verify(foo, Mockito.times(1)).add("1");
// TODO: don't allow all other invocations with add()
}
}
What should be done in the TODO: don't allow all other invocations with add() section?
Aucun commentaire:
Enregistrer un commentaire