use of org.mockito.internal.stubbing.answers.ThrowsException in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_add_throwable_for_void_method.
@Test
public void should_add_throwable_for_void_method() throws Throwable {
invocationContainerImpl.addAnswerForVoidMethod(new ThrowsException(new MyException()));
invocationContainerImpl.setMethodForStubbing(new InvocationMatcher(simpleMethod));
try {
invocationContainerImpl.answerTo(simpleMethod);
fail();
} catch (MyException e) {
}
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_get_results_for_methods.
@Test
public void should_get_results_for_methods() throws Throwable {
invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
invocationContainerImpl.addAnswer(new Returns("simpleMethod"));
Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
invocationContainerImpl.addAnswer(new ThrowsException(new MyException()));
assertEquals("simpleMethod", invocationContainerImpl.answerTo(simpleMethod));
try {
invocationContainerImpl.answerTo(differentMethod);
fail();
} catch (MyException e) {
}
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project mockito by mockito.
the class MocksSerializationTest method should_allow_method_delegation.
@Test
public void should_allow_method_delegation() throws Exception {
// given
Bar barMock = mock(Bar.class, withSettings().serializable());
Foo fooMock = mock(Foo.class);
when(barMock.doSomething()).thenAnswer(new ThrowsException(new RuntimeException()));
//when-serialize then-deserialize
serializeAndBack(barMock);
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project mockito by mockito.
the class MocksSerializationForAnnotationTest method should_allow_throws_exception_to_be_serializable.
@Test
public void should_allow_throws_exception_to_be_serializable() throws Exception {
// given
when(barMock.doSomething()).thenAnswer(new ThrowsException(new RuntimeException()));
//when-serialize then-deserialize
serializeAndBack(barMock);
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project mobile-center-sdk-android by Microsoft.
the class StorageHelperTest method readErrorAndCloseError.
@Test
public void readErrorAndCloseError() throws Exception {
mockStatic(MobileCenterLog.class);
FileReader fileReader = mock(FileReader.class, new ThrowsException(new IOException()));
whenNew(FileReader.class).withAnyArguments().thenReturn(fileReader);
assertNull(StorageHelper.InternalStorage.read(new File("")));
verify(fileReader).close();
verifyStatic();
MobileCenterLog.error(anyString(), anyString(), any(IOException.class));
}
Aggregations