Java Code Examples for org.mockito.stubbing.Answer#answer()
The following examples show how to use
org.mockito.stubbing.Answer#answer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StubbedInvocationMatcher.java From astor with GNU General Public License v2.0 | 5 votes |
public Object answer(InvocationOnMock invocation) throws Throwable { //see ThreadsShareGenerouslyStubbedMockTest Answer a; synchronized(answers) { a = answers.size() == 1 ? answers.peek() : answers.poll(); } return a.answer(invocation); }
Example 2
Source File: ReturnsSmartNullsTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void shouldReturnAnObjectThatFailsOnAnyMethodInvocationForNonPrimitives() throws Throwable { Answer<Object> answer = new ReturnsSmartNulls(); Foo smartNull = (Foo) answer.answer(invocationOf(Foo.class, "get")); try { smartNull.get(); fail(); } catch (SmartNullPointerException expected) {} }
Example 3
Source File: ReturnsSmartNullsTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void shouldReturnAnObjectThatAllowsObjectMethods() throws Throwable { Answer<Object> answer = new ReturnsSmartNulls(); Foo smartNull = (Foo) answer.answer(invocationOf(Foo.class, "get")); assertContains("SmartNull returned by", smartNull + ""); assertContains("foo.get()", smartNull + ""); }
Example 4
Source File: ReturnsSmartNullsTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void shouldPrintTheParametersWhenCallingAMethodWithArgs() throws Throwable { Answer<Object> answer = new ReturnsSmartNulls(); Foo smartNull = (Foo) answer.answer(invocationOf(Foo.class, "withArgs", "oompa", "lumpa")); assertContains("foo.withArgs", smartNull + ""); assertContains("oompa", smartNull + ""); assertContains("lumpa", smartNull + ""); }
Example 5
Source File: ReturnsSmartNullsTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void shouldPrintTheParametersOnSmartNullPointerExceptionMessage() throws Throwable { Answer<Object> answer = new ReturnsSmartNulls(); Foo smartNull = (Foo) answer.answer(invocationOf(Foo.class, "withArgs", "oompa", "lumpa")); try { smartNull.get(); fail(); } catch (SmartNullPointerException e) { assertContains("oompa", e.getMessage()); assertContains("lumpa", e.getMessage()); } }
Example 6
Source File: StubbedInvocationMatcher.java From astor with GNU General Public License v2.0 | 5 votes |
public Object answer(InvocationOnMock invocation) throws Throwable { //see ThreadsShareGenerouslyStubbedMockTest Answer a; synchronized(answers) { a = answers.size() == 1 ? answers.peek() : answers.poll(); } return a.answer(invocation); }
Example 7
Source File: ReturnsSmartNullsTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void should_return_an_object_that_fails_on_any_method_invocation_for_non_primitives() throws Throwable { Answer<Object> answer = new ReturnsSmartNulls(); Foo smartNull = (Foo) answer.answer(invocationOf(Foo.class, "get")); try { smartNull.get(); fail(); } catch (SmartNullPointerException expected) {} }
Example 8
Source File: ReturnsSmartNullsTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void should_return_an_object_that_allows_object_methods() throws Throwable { Answer<Object> answer = new ReturnsSmartNulls(); Foo smartNull = (Foo) answer.answer(invocationOf(Foo.class, "get")); assertContains("SmartNull returned by", smartNull + ""); assertContains("foo.get()", smartNull + ""); }
Example 9
Source File: ReturnsSmartNullsTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void should_print_the_parameters_when_calling_a_method_with_args() throws Throwable { Answer<Object> answer = new ReturnsSmartNulls(); Foo smartNull = (Foo) answer.answer(invocationOf(Foo.class, "withArgs", "oompa", "lumpa")); assertContains("foo.withArgs", smartNull + ""); assertContains("oompa", smartNull + ""); assertContains("lumpa", smartNull + ""); }
Example 10
Source File: ReturnsSmartNullsTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void should_print_the_parameters_on_SmartNullPointerException_message() throws Throwable { Answer<Object> answer = new ReturnsSmartNulls(); Foo smartNull = (Foo) answer.answer(invocationOf(Foo.class, "withArgs", "oompa", "lumpa")); try { smartNull.get(); fail(); } catch (SmartNullPointerException e) { assertContains("oompa", e.getMessage()); assertContains("lumpa", e.getMessage()); } }
Example 11
Source File: PartitionWriteHandlerTest.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Override public T answer(InvocationOnMock invocation) throws Throwable{ Assert.assertTrue("Called too many times!",count<maxCount); Answer<T> stageAnswer = stageMap.get(count); Assert.assertNotNull("No Stage answer found!",stageAnswer); T ret = stageAnswer.answer(invocation); count++; return ret; }