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(AppCenterLog.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();
AppCenterLog.error(anyString(), anyString(), any(IOException.class));
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project mobile-center-sdk-android by Microsoft.
the class StorageHelperTest method readFileNotFound.
@Test
public void readFileNotFound() throws Exception {
mockStatic(AppCenterLog.class);
FileReader fileReader = mock(FileReader.class, new ThrowsException(new FileNotFoundException()));
whenNew(FileReader.class).withAnyArguments().thenReturn(fileReader);
assertNull(StorageHelper.InternalStorage.read(new File("")));
verify(fileReader).close();
verifyStatic();
AppCenterLog.error(anyString(), anyString(), any(IOException.class));
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_get_results_for_methods_stub_only.
@Test
public void should_get_results_for_methods_stub_only() throws Throwable {
invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
invocationContainerImplStubOnly.addAnswer(new Returns("simpleMethod"));
Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
invocationContainerImplStubOnly.addAnswer(new ThrowsException(new MyException()));
assertEquals("simpleMethod", invocationContainerImplStubOnly.answerTo(simpleMethod));
try {
invocationContainerImplStubOnly.answerTo(differentMethod);
fail();
} catch (MyException e) {
}
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_validate_throwable.
@Test
public void should_validate_throwable() throws Throwable {
try {
invocationContainerImpl.addAnswer(new ThrowsException(null));
fail();
} catch (MockitoException e) {
}
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_validate_throwable_for_void_method.
@Test
public void should_validate_throwable_for_void_method() throws Throwable {
invocationContainerImpl.addAnswerForVoidMethod(new ThrowsException(new Exception()));
try {
invocationContainerImpl.setMethodForStubbing(new InvocationMatcher(simpleMethod));
fail();
} catch (MockitoException e) {
}
}
Aggregations