@SuppressWarnings("unchecked")
@Test
public void messageExceptionTest() throws Exception {

    final Throwable occurredException = new RuntimeException();
    final ActorMethodInvokeException baseCallException = Mockito.mock(ActorMethodInvokeException.class);
    final Message message = Mockito.mock(Message.class);
    Mockito.doThrow(occurredException).when(message).invoke(mActorImpl);
    //noinspection ThrowableNotThrown
    Mockito.doReturn(baseCallException).when(message).exception();
    final LooperActorThread actorThread = new LooperActorThread(mProxyFactory, mFailureHandler, mLooper);
    ActorRef<Runnable> runnableRef = actorThread.bind(Runnable.class, mActorImpl);
    Assert.assertSame(mProxy, runnableRef.tell());
    ArgumentCaptor<MessageSender> postmanCaptor = ArgumentCaptor.forClass(MessageSender.class);
    Mockito.verify(mProxyFactory).newProxy(Mockito.<Class>any(), postmanCaptor.capture());
    MessageSender postman = postmanCaptor.getValue();
    postman.deliver(message);
    // check that we did nothing on same thread
    Mockito.verify(message, Mockito.never()).invoke(Mockito.any());
    // Process all scheduled messages on looper thread and check that our actor's method was called
    mShadowLooper.runToEndOfTasks();
    // Check that exception was reported to FailureHandler
    Mockito.verify(mFailureHandler).onUncaughtException(mActorImpl, message, baseCallException);
    Mockito.verify(baseCallException).initCause(occurredException);
}