Search in sources :

Example 6 with ThrowsException

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));
}
Also used : ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with ThrowsException

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));
}
Also used : ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with ThrowsException

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) {
    }
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) Invocation(org.mockito.invocation.Invocation) ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 9 with ThrowsException

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) {
    }
}
Also used : ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 10 with ThrowsException

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) {
    }
}
Also used : ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) MockitoException(org.mockito.exceptions.base.MockitoException) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)17 ThrowsException (org.mockito.internal.stubbing.answers.ThrowsException)17 IOException (java.io.IOException)8 File (java.io.File)4 FileReader (java.io.FileReader)4 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 FileNotFoundException (java.io.FileNotFoundException)3 OutputStream (java.io.OutputStream)3 MockitoException (org.mockito.exceptions.base.MockitoException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)2 Returns (org.mockito.internal.stubbing.answers.Returns)2 Invocation (org.mockito.invocation.Invocation)2 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)2 Neo4jJsonCodecTest (org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)2 Closeable (java.io.Closeable)1 SocketTimeoutException (java.net.SocketTimeoutException)1 CryptoProtocolVersion (org.apache.hadoop.crypto.CryptoProtocolVersion)1 ChecksumException (org.apache.hadoop.fs.ChecksumException)1