ExecutorActorThread implements ActorThread { @NonNull @Override public <T> ActorRef<T> bind(@NonNull Class<T> cls, @NonNull T impl) { MessageSenderProxy<T> postman = new MessageSenderProxy<>(impl, mExecutor, mFailureHandler); T instance = mProxyFactory.newProxy(cls, postman); return new ActorRefImpl<>(instance); } ExecutorActorThread(@NonNull Executor executor, @NonNull ProxyFactory proxyFactory,
                                      @NonNull FailureHandler failureHandler); @NonNull @Override ActorRef<T> bind(@NonNull Class<T> cls, @NonNull T impl);  }
@SuppressWarnings("unchecked") @Test public void messageDeliverTest() throws Exception { ActorRef<Runnable> runnableRef = mThread.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()); final Message message = Mockito.mock(Message.class); final MessageSender postman = postmanCaptor.getValue(); postman.deliver(message); ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class); Mockito.verify(mExecutor).execute(runnableCaptor.capture()); Runnable runnable = runnableCaptor.getValue(); Assert.assertNotNull(runnable); runnable.run(); Mockito.verify(message).invoke(mActorImpl); }
@SuppressWarnings({"unchecked", "ThrowableNotThrown"}) @Test public void messageExceptionTest() throws Exception { ActorRef<Runnable> runnableRef = mThread.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()); final Message message = Mockito.mock(Message.class); final RuntimeException exception = Mockito.mock(RuntimeException.class); final ActorMethodInvokeException callException = Mockito.mock(ActorMethodInvokeException.class); Mockito.doThrow(exception).when(message).invoke(Mockito.any()); Mockito.doReturn(callException).when(message).exception(); final MessageSender postman = postmanCaptor.getValue(); postman.deliver(message); ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class); Mockito.verify(mExecutor).execute(runnableCaptor.capture()); Runnable runnable = runnableCaptor.getValue(); Assert.assertNotNull(runnable); runnable.run(); Mockito.verify(mFailureHandler).onUncaughtException(mActorImpl, message, callException); Mockito.verify(callException).initCause(exception); }