use of org.mockitousage.IMethods in project mockito by mockito.
the class StubbingMocksThatAreConfiguredToReturnMocksTest method shouldAllowStubbingMocksConfiguredWithRETURNS_MOCKS.
@Test
public void shouldAllowStubbingMocksConfiguredWithRETURNS_MOCKS() {
IMethods mock = mock(IMethods.class, RETURNS_MOCKS);
when(mock.objectReturningMethodNoArgs()).thenReturn(null);
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class LoadsOfMocksTest method testSomething.
@Ignore("Use it for performance checks")
@Test
public void testSomething() {
List<IMethods> mocks = new LinkedList<IMethods>();
for (int i = 0; i < 50000; i++) {
System.out.println("Mock no: " + i);
IMethods mock = mock(IMethods.class);
mocks.add(mock);
when(mock.simpleMethod(1)).thenReturn("one");
when(mock.simpleMethod(2)).thenReturn("two");
assertEquals("one", mock.simpleMethod(1));
assertEquals("two", mock.simpleMethod(2));
verify(mock).simpleMethod(1);
verify(mock).simpleMethod(2);
}
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class SmartNullsStubbingTest method shouldReturnOrdinaryEmptyValuesForOrdinaryTypes.
@Test
public void shouldReturnOrdinaryEmptyValuesForOrdinaryTypes() throws Exception {
IMethods mock = mock(IMethods.class, RETURNS_SMART_NULLS);
assertEquals("", mock.stringReturningMethod());
assertEquals(0, mock.intReturningMethod());
assertEquals(true, mock.listReturningMethod().isEmpty());
assertEquals(0, mock.arrayReturningMethod().length);
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class StubbingWithAdditionalAnswersTest method can_return_based_on_strongly_typed_five_parameter_function.
@Test
public void can_return_based_on_strongly_typed_five_parameter_function() throws Exception {
final IMethods target = mock(IMethods.class);
given(iMethods.simpleMethod(anyString(), anyInt(), anyInt(), anyInt(), anyInt())).will(answer(new Answer5<String, String, Integer, Integer, Integer, Integer>() {
public String answer(String s1, Integer i1, Integer i2, Integer i3, Integer i4) {
target.simpleMethod(s1, i1, i2, i3, i4);
return "answered";
}
}));
assertThat(iMethods.simpleMethod("hello", 1, 2, 3, 4)).isEqualTo("answered");
verify(target, times(1)).simpleMethod("hello", 1, 2, 3, 4);
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class StubbingWithAdditionalAnswersTest method will_execute_a_void_based_on_strongly_typed_four_parameter_function.
@Test
public void will_execute_a_void_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(answerVoid(new VoidAnswer4<Integer, String, String, boolean[]>() {
public void answer(Integer i, String s1, String s2, boolean[] a) {
target.fourArgumentMethod(i, s1, s2, a);
}
}));
// invoke on iMethods
boolean[] booleanArray = { true, false };
iMethods.fourArgumentMethod(1, "string1", "string2", booleanArray);
// expect the answer to write correctly to "target"
verify(target, times(1)).fourArgumentMethod(1, "string1", "string2", booleanArray);
}
Aggregations