Search in sources :

Example 6 with Returns

use of org.mockito.internal.stubbing.answers.Returns in project mockito by mockito.

the class ReporterTest method can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_dont_exists.

@Test(expected = MockitoException.class)
public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_dont_exists() throws Exception {
    Invocation dumb_invocation = new InvocationBuilder().toInvocation();
    IMethods mock_with_bogus_default_answer = mock(IMethods.class, new Returns(false));
    throw Reporter.delegatedMethodDoesNotExistOnDelegate(dumb_invocation.getMethod(), mock_with_bogus_default_answer, String.class);
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 7 with Returns

use of org.mockito.internal.stubbing.answers.Returns in project mockito by mockito.

the class InlineByteBuddyMockMakerTest method settingsFor.

private 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 8 with Returns

use of org.mockito.internal.stubbing.answers.Returns in project mockito by mockito.

the class InvocationContainerImplStubbingTest method should_get_results_for_methods_stub_only.

@Test
public void should_get_results_for_methods_stub_only() throws Throwable {
    invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
    invocationContainerImplStubOnly.addAnswer(new Returns("simpleMethod"));
    Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
    invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
    invocationContainerImplStubOnly.addAnswer(new ThrowsException(new MyException()));
    assertEquals("simpleMethod", invocationContainerImplStubOnly.answerTo(simpleMethod));
    try {
        invocationContainerImplStubOnly.answerTo(differentMethod);
        fail();
    } catch (MyException e) {
    }
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) Invocation(org.mockito.invocation.Invocation) ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 9 with Returns

use of org.mockito.internal.stubbing.answers.Returns in project mockito by mockito.

the class InvocationContainerImplStubbingTest method should_finish_stubbing_on_adding_return_value.

@Test
public void should_finish_stubbing_on_adding_return_value() throws Exception {
    state.stubbingStarted();
    invocationContainerImpl.addAnswer(new Returns("test"));
    state.validateState();
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) Test(org.junit.Test)

Example 10 with Returns

use of org.mockito.internal.stubbing.answers.Returns in project mockito by mockito.

the class InvocationContainerImplStubbingTest method should_get_results_for_methods.

@Test
public void should_get_results_for_methods() throws Throwable {
    invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
    invocationContainerImpl.addAnswer(new Returns("simpleMethod"));
    Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
    invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
    invocationContainerImpl.addAnswer(new ThrowsException(new MyException()));
    assertEquals("simpleMethod", invocationContainerImpl.answerTo(simpleMethod));
    try {
        invocationContainerImpl.answerTo(differentMethod);
        fail();
    } catch (MyException e) {
    }
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) Invocation(org.mockito.invocation.Invocation) ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Aggregations

Returns (org.mockito.internal.stubbing.answers.Returns)14 Test (org.junit.Test)9 Invocation (org.mockito.invocation.Invocation)6 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)5 MockSettingsImpl (org.mockito.internal.creation.MockSettingsImpl)4 Before (org.junit.Before)3 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Context (android.content.Context)2 ThrowsException (org.mockito.internal.stubbing.answers.ThrowsException)2 MockCreationSettings (org.mockito.mock.MockCreationSettings)2 Answer (org.mockito.stubbing.Answer)2 IMethods (org.mockitousage.IMethods)2 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)2 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 ContentValues (android.content.ContentValues)1 PackageInfo (android.content.pm.PackageInfo)1 Cursor (android.database.Cursor)1 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)1