Search in sources :

Example 6 with NoInteractionsWanted

use of org.mockito.exceptions.verification.NoInteractionsWanted in project mockito by mockito.

the class NoMoreInteractionsTest method noMoreInteractionsExceptionMessageShouldDescribeMock.

@Test
public void noMoreInteractionsExceptionMessageShouldDescribeMock() {
    // given
    NoMoreInteractions n = new NoMoreInteractions();
    IMethods mock = mock(IMethods.class, "a mock");
    InvocationMatcher i = new InvocationBuilder().mock(mock).toInvocationMatcher();
    InvocationContainerImpl invocations = new InvocationContainerImpl(new MockSettingsImpl());
    invocations.setInvocationForPotentialStubbing(i);
    try {
        // when
        n.verify(new VerificationDataImpl(invocations, null));
        // then
        fail();
    } catch (NoInteractionsWanted e) {
        Assertions.assertThat(e.toString()).contains(mock.toString());
    }
}
Also used : InvocationContainerImpl(org.mockito.internal.stubbing.InvocationContainerImpl) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl) NoInteractionsWanted(org.mockito.exceptions.verification.NoInteractionsWanted) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) IMethods(org.mockitousage.IMethods) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 7 with NoInteractionsWanted

use of org.mockito.exceptions.verification.NoInteractionsWanted in project mockito by mockito.

the class StaticMockingExperimentTest method verify_no_more_interactions.

@Test
public void verify_no_more_interactions() throws Throwable {
    // works for now because there are not interactions
    verifyNoMoreInteractions(mock);
    // register staticMethod call on mock
    Invocation invocation = Mockito.framework().getInvocationFactory().createInvocation(mock, withSettings().build(Foo.class), staticMethod, realMethod, "foo");
    handler.handle(invocation);
    // fails now because we have one static invocation recorded
    try {
        verifyNoMoreInteractions(mock);
        fail();
    } catch (NoInteractionsWanted e) {
    }
}
Also used : Invocation(org.mockito.invocation.Invocation) NoInteractionsWanted(org.mockito.exceptions.verification.NoInteractionsWanted) Test(org.junit.Test)

Aggregations

NoInteractionsWanted (org.mockito.exceptions.verification.NoInteractionsWanted)7 Test (org.junit.Test)5 MockSettingsImpl (org.mockito.internal.creation.MockSettingsImpl)2 LocationImpl (org.mockito.internal.debugging.LocationImpl)2 ScenarioPrinter (org.mockito.internal.exceptions.util.ScenarioPrinter)2 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)2 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)2 InvocationContainerImpl (org.mockito.internal.stubbing.InvocationContainerImpl)2 IMethods (org.mockitousage.IMethods)2 InOrder (org.mockito.InOrder)1 MockitoException (org.mockito.exceptions.base.MockitoException)1 Invocation (org.mockito.invocation.Invocation)1 Location (org.mockito.invocation.Location)1