Search in sources :

Example 1 with InvalidUseOfMatchersException

use of org.mockito.exceptions.misusing.InvalidUseOfMatchersException in project mockito by mockito.

the class MockHandlerImplTest method should_remove_verification_mode_even_when_invalid_matchers.

@Test
public void should_remove_verification_mode_even_when_invalid_matchers() throws Throwable {
    // given
    Invocation invocation = new InvocationBuilder().toInvocation();
    @SuppressWarnings("rawtypes") MockHandlerImpl<?> handler = new MockHandlerImpl(new MockSettingsImpl());
    mockingProgress().verificationStarted(VerificationModeFactory.atLeastOnce());
    handler.matchersBinder = new MatchersBinder() {

        public InvocationMatcher bindMatchers(ArgumentMatcherStorage argumentMatcherStorage, Invocation invocation) {
            throw new InvalidUseOfMatchersException();
        }
    };
    try {
        // when
        handler.handle(invocation);
        // then
        fail();
    } catch (InvalidUseOfMatchersException ignored) {
    }
    assertNull(mockingProgress().pullVerificationMode());
}
Also used : InvalidUseOfMatchersException(org.mockito.exceptions.misusing.InvalidUseOfMatchersException) Invocation(org.mockito.invocation.Invocation) MatchersBinder(org.mockito.internal.invocation.MatchersBinder) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) StubbedInvocationMatcher(org.mockito.internal.stubbing.StubbedInvocationMatcher) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) ArgumentMatcherStorage(org.mockito.internal.progress.ArgumentMatcherStorage) Test(org.junit.Test)

Example 2 with InvalidUseOfMatchersException

use of org.mockito.exceptions.misusing.InvalidUseOfMatchersException in project mockito by mockito.

the class DetectingMisusedMatchersTest method should_report_argument_locations_when_argument_matchers_misused.

@Test
public void should_report_argument_locations_when_argument_matchers_misused() {
    try {
        Observer observer = mock(Observer.class);
        misplaced_anyInt_argument_matcher();
        misplaced_anyObject_argument_matcher();
        misplaced_anyBoolean_argument_matcher();
        observer.update(null, null);
        validateMockitoUsage();
        fail();
    } catch (InvalidUseOfMatchersException e) {
        assertThat(e).hasMessageContaining("DetectingMisusedMatchersTest.misplaced_anyInt_argument_matcher").hasMessageContaining("DetectingMisusedMatchersTest.misplaced_anyObject_argument_matcher").hasMessageContaining("DetectingMisusedMatchersTest.misplaced_anyBoolean_argument_matcher");
    }
}
Also used : InvalidUseOfMatchersException(org.mockito.exceptions.misusing.InvalidUseOfMatchersException) Observer(java.util.Observer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 InvalidUseOfMatchersException (org.mockito.exceptions.misusing.InvalidUseOfMatchersException)2 Observer (java.util.Observer)1 MockSettingsImpl (org.mockito.internal.creation.MockSettingsImpl)1 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)1 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)1 MatchersBinder (org.mockito.internal.invocation.MatchersBinder)1 ArgumentMatcherStorage (org.mockito.internal.progress.ArgumentMatcherStorage)1 StubbedInvocationMatcher (org.mockito.internal.stubbing.StubbedInvocationMatcher)1 Invocation (org.mockito.invocation.Invocation)1