Search in sources :

Example 1 with VoidAnswer2

use of org.mockito.stubbing.VoidAnswer2 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);
}
Also used : VoidAnswer2(org.mockito.stubbing.VoidAnswer2) IMethods(org.mockitousage.IMethods) BDDMockito.anyString(org.mockito.BDDMockito.anyString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 BDDMockito.anyString (org.mockito.BDDMockito.anyString)1 VoidAnswer2 (org.mockito.stubbing.VoidAnswer2)1 IMethods (org.mockitousage.IMethods)1