use of org.mockitousage.IMethods in project mockito by mockito.
the class BasicStubbingTest method test_stub_only_not_verifiable.
@Test
public void test_stub_only_not_verifiable() throws Exception {
IMethods localMock = mock(IMethods.class, withSettings().stubOnly());
when(localMock.objectReturningMethod(isA(Integer.class))).thenReturn(100);
when(localMock.objectReturningMethod(200)).thenReturn(200);
assertEquals(200, localMock.objectReturningMethod(200));
assertEquals(100, localMock.objectReturningMethod(666));
assertEquals("default behavior should return null", null, localMock.objectReturningMethod("blah"));
try {
verify(localMock, atLeastOnce()).objectReturningMethod(eq(200));
fail();
} catch (CannotVerifyStubOnlyMock e) {
}
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class StubbingWithAdditionalAnswersTest method will_execute_a_void_based_on_strongly_typed_one_parameter_function.
@Test
public void will_execute_a_void_based_on_strongly_typed_one_parameter_function() throws Exception {
final IMethods target = mock(IMethods.class);
given(iMethods.simpleMethod(anyString())).will(answerVoid(new VoidAnswer1<String>() {
public void answer(String s) {
target.simpleMethod(s);
}
}));
// invoke on iMethods
iMethods.simpleMethod("string");
// expect the answer to write correctly to "target"
verify(target, times(1)).simpleMethod("string");
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class StubbingWithDelegateTest method null_wrapper_dont_throw_exception_from_org_mockito_package.
@Test
public void null_wrapper_dont_throw_exception_from_org_mockito_package() throws Exception {
IMethods methods = mock(IMethods.class, delegatesTo(new MethodsImpl()));
try {
// real method returns null
byte b = methods.byteObjectReturningMethod();
fail();
} catch (Exception e) {
assertThat(e.toString()).doesNotContain("org.mockito");
}
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class PrintingVerboseTypesWithArgumentsTest method should_not_show_types_when_types_are_the_same_even_if_to_string_gives_the_same_result.
@Test
public void should_not_show_types_when_types_are_the_same_even_if_to_string_gives_the_same_result() {
//given
IMethods mock = mock(IMethods.class);
mock.simpleMethod(new Foo(10));
try {
//when
verify(mock).simpleMethod(new Foo(20));
fail();
} catch (ArgumentsAreDifferent e) {
//then
assertThat(e).hasMessageContaining("simpleMethod(foo)");
}
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class SmartNullsStubbingTest method shouldSmartNPEPointToUnstubbedCall.
@Test
public void shouldSmartNPEPointToUnstubbedCall() throws Exception {
IMethods methods = unstubbedMethodInvokedHere(mock);
try {
methods.simpleMethod();
fail();
} catch (SmartNullPointerException e) {
assertThat(e).hasMessageContaining("unstubbedMethodInvokedHere(");
}
}
Aggregations