use of org.mockito.StateMaster in project mockito by mockito.
the class InvalidStateDetectionTest method detectsAndCleansUp.
private void detectsAndCleansUp(DetectsInvalidState detector, Class<?> expected) {
try {
detector.detect(mock);
fail("Should throw an exception");
} catch (Exception e) {
assertEquals(expected, e.getClass());
}
//Make sure state is cleaned up
new StateMaster().validate();
}
use of org.mockito.StateMaster in project mockito by mockito.
the class InvalidUseOfMatchersTest method should_mention_matcher_when_misuse_detected.
@Test
public void should_mention_matcher_when_misuse_detected() {
// Given
// When
Result run = new JUnitCore().run(ObjectMatcherMisuseOnPrimitiveSite.class);
// Then
assertThat(run.getFailures()).hasSize(2);
assertThat(run.getFailures().get(0).getException()).isInstanceOf(NullPointerException.class).hasMessage(null);
assertThat(run.getFailures().get(1).getException()).isInstanceOf(InvalidUseOfMatchersException.class).hasMessageContaining("primitive alternatives");
new StateMaster().reset();
}
use of org.mockito.StateMaster in project mockito by mockito.
the class TestBase method cleanUpConfigInAnyCase.
@After
public void cleanUpConfigInAnyCase() {
ConfigurationAccess.getConfig().overrideCleansStackTrace(false);
ConfigurationAccess.getConfig().overrideDefaultAnswer(null);
StateMaster state = new StateMaster();
//catch any invalid state left over after test case run
//this way we can catch early if some Mockito operations leave weird state afterwards
state.validate();
//reset the state, especially, reset any ongoing stubbing for correct error messages of tests that assert unhappy paths
state.reset();
}
Aggregations