Search in sources :

Example 21 with MockSettingsImpl

use of org.mockito.internal.creation.MockSettingsImpl 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 22 with MockSettingsImpl

use of org.mockito.internal.creation.MockSettingsImpl in project mockito by mockito.

the class InlineDelegateByteBuddyMockMakerTest method should_mock_interface.

@Test
public void should_mock_interface() {
    MockSettingsImpl<Set> mockSettings = new MockSettingsImpl<Set>();
    mockSettings.setTypeToMock(Set.class);
    mockSettings.defaultAnswer(new Returns(10));
    Set<?> proxy = mockMaker.createMock(mockSettings, new MockHandlerImpl<Set>(mockSettings));
    assertThat(proxy.size()).isEqualTo(10);
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl) Test(org.junit.Test)

Example 23 with MockSettingsImpl

use of org.mockito.internal.creation.MockSettingsImpl in project mockito by mockito.

the class InlineDelegateByteBuddyMockMakerTest method settingsFor.

protected static <T> MockCreationSettings<T> settingsFor(Class<T> type, Class<?>... extraInterfaces) {
    MockSettingsImpl<T> mockSettings = new MockSettingsImpl<T>();
    mockSettings.setTypeToMock(type);
    mockSettings.defaultAnswer(new Returns("bar"));
    if (extraInterfaces.length > 0)
        mockSettings.extraInterfaces(extraInterfaces);
    return mockSettings;
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl)

Example 24 with MockSettingsImpl

use of org.mockito.internal.creation.MockSettingsImpl in project mockito by mockito.

the class InlineDelegateByteBuddyMockMakerTest method should_mock_interface_to_string.

@Test
public void should_mock_interface_to_string() {
    MockSettingsImpl<Set> mockSettings = new MockSettingsImpl<Set>();
    mockSettings.setTypeToMock(Set.class);
    mockSettings.defaultAnswer(new Returns("foo"));
    Set<?> proxy = mockMaker.createMock(mockSettings, new MockHandlerImpl<Set>(mockSettings));
    assertThat(proxy.toString()).isEqualTo("foo");
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl) Test(org.junit.Test)

Example 25 with MockSettingsImpl

use of org.mockito.internal.creation.MockSettingsImpl in project mockito by mockito.

the class InlineDelegateByteBuddyMockMakerTest method should_mock_class_to_string.

/**
 * @see <a href="https://github.com/mockito/mockito/issues/2154">https://github.com/mockito/mockito/issues/2154</a>
 */
@Test
public void should_mock_class_to_string() {
    MockSettingsImpl<Object> mockSettings = new MockSettingsImpl<Object>();
    mockSettings.setTypeToMock(Object.class);
    mockSettings.defaultAnswer(new Returns("foo"));
    Object proxy = mockMaker.createMock(mockSettings, new MockHandlerImpl<Object>(mockSettings));
    assertThat(proxy.toString()).isEqualTo("foo");
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl) Test(org.junit.Test)

Aggregations

MockSettingsImpl (org.mockito.internal.creation.MockSettingsImpl)26 Test (org.junit.Test)19 Returns (org.mockito.internal.stubbing.answers.Returns)9 MockSettings (org.mockito.MockSettings)5 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)5 CollectionData (com.torodb.core.d2r.CollectionData)4 DocPartData (com.torodb.core.d2r.DocPartData)4 BackendTransactionJob (com.torodb.core.dsl.backend.BackendTransactionJob)4 InsertBackendJob (com.torodb.core.dsl.backend.InsertBackendJob)4 List (java.util.List)4 Optional (java.util.Optional)4 Invocation (org.mockito.invocation.Invocation)4 MockName (org.mockito.mock.MockName)4 MockCreationSettings (org.mockito.mock.MockCreationSettings)3 AddFieldDdlJob (com.torodb.core.dsl.backend.AddFieldDdlJob)2 AddScalarDddlJob (com.torodb.core.dsl.backend.AddScalarDddlJob)2 ImmutableMetaField (com.torodb.core.transaction.metainf.ImmutableMetaField)2 ImmutableMetaScalar (com.torodb.core.transaction.metainf.ImmutableMetaScalar)2 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)2 AddDocPartDdlJob (com.torodb.core.dsl.backend.AddDocPartDdlJob)1