package test;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
public class MockitoTest {
private static class Collaborator {
public String doStuff(int number) {
throw new RuntimeException();
}
}
private static class Container {
private final Collaborator collaborator;
public Container(Collaborator collaborator) {
this.collaborator = collaborator;
}
public String doStuff(int number) {
return collaborator.doStuff(number);
}
}
@Rule
public MockitoRule rule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);
@Mock
private Collaborator collaborator;
@Test
public void testVerifyZeroInteractions() throws Exception {
Container container = new Container(collaborator);
when(collaborator.doStuff(42)).thenReturn("yeah");
String output = container.doStuff(42);
assertEquals("yeah", output);
verifyZeroInteractions(collaborator);
}
}
Well, do you get the RuntimeException sent by Collaborator.doStuff()? From reading your code, it seems that you would.
In that case, the test would fail before reaching the call to verifyZeroInteractions().
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+unsubscribe@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/87e23df0-60fe-43d3-b2db-8dd53731f928%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+unsubscribe@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/CA%2BThcyXdmJxrvJ8m5NOZZ-zWxhR0aZ7YkKB%3Dc4Toq0hhrtihSg%40mail.gmail.com.