use of org.mockitousage.IMethods in project mockito by mockito.
the class StubbingWithAdditionalAnswersTest method will_execute_a_void_based_on_strongly_typed_two_parameter_function.
@Test
public void will_execute_a_void_based_on_strongly_typed_two_parameter_function() throws Exception {
final IMethods target = mock(IMethods.class);
given(iMethods.simpleMethod(anyString(), anyInt())).will(answerVoid(new VoidAnswer2<String, Integer>() {
public void answer(String s, Integer i) {
target.simpleMethod(s, i);
}
}));
// invoke on iMethods
iMethods.simpleMethod("string", 1);
// expect the answer to write correctly to "target"
verify(target, times(1)).simpleMethod("string", 1);
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class StubbingWithAdditionalAnswersTest method can_return_based_on_strongly_typed_four_parameter_function.
@Test
public void can_return_based_on_strongly_typed_four_parameter_function() throws Exception {
final IMethods target = mock(IMethods.class);
given(iMethods.fourArgumentMethod(anyInt(), anyString(), anyString(), any(boolean[].class))).will(answer(new Answer4<String, Integer, String, String, boolean[]>() {
public String answer(Integer i, String s1, String s2, boolean[] a) {
target.fourArgumentMethod(i, s1, s2, a);
return "answered";
}
}));
boolean[] booleanArray = { true, false };
assertThat(iMethods.fourArgumentMethod(1, "string1", "string2", booleanArray)).isEqualTo("answered");
verify(target, times(1)).fourArgumentMethod(1, "string1", "string2", booleanArray);
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class StubbingWithAdditionalAnswersTest method can_return_based_on_strongly_typed_three_parameter_function.
@Test
public void can_return_based_on_strongly_typed_three_parameter_function() throws Exception {
final IMethods target = mock(IMethods.class);
given(iMethods.threeArgumentMethodWithStrings(anyInt(), anyString(), anyString())).will(answer(new Answer3<String, Integer, String, String>() {
public String answer(Integer i, String s1, String s2) {
target.threeArgumentMethodWithStrings(i, s1, s2);
return "answered";
}
}));
assertThat(iMethods.threeArgumentMethodWithStrings(1, "string1", "string2")).isEqualTo("answered");
verify(target, times(1)).threeArgumentMethodWithStrings(1, "string1", "string2");
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class StubbingWithAdditionalAnswersTest method will_execute_a_void_based_on_strongly_typed_five_parameter_function.
@Test
public void will_execute_a_void_based_on_strongly_typed_five_parameter_function() throws Exception {
final IMethods target = mock(IMethods.class);
given(iMethods.simpleMethod(anyString(), anyInt(), anyInt(), anyInt(), anyInt())).will(answerVoid(new VoidAnswer5<String, Integer, Integer, Integer, Integer>() {
public void answer(String s1, Integer i1, Integer i2, Integer i3, Integer i4) {
target.simpleMethod(s1, i1, i2, i3, i4);
}
}));
// invoke on iMethods
iMethods.simpleMethod("hello", 1, 2, 3, 4);
// expect the answer to write correctly to "target"
verify(target, times(1)).simpleMethod("hello", 1, 2, 3, 4);
}
use of org.mockitousage.IMethods 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_has_wrong_return_type.
@Test(expected = MockitoException.class)
public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_has_wrong_return_type() throws Exception {
Invocation dumb_invocation = new InvocationBuilder().toInvocation();
IMethods mock_with_bogus_default_answer = mock(IMethods.class, new Returns(false));
throw Reporter.delegatedMethodHasWrongReturnType(dumb_invocation.getMethod(), dumb_invocation.getMethod(), mock_with_bogus_default_answer, String.class);
}
Aggregations