ResultListenerProxy implements ResultListener { @Override public void onResult(@Nullable Object result) { mMessageSender.deliver(new ResultListenerMessage(new ActorMethodInvokeException(), result)); } ResultListenerProxy(MessageSender messageSender); @Override void onResult(@Nullable Object result);  }
@Test public void onResult_invoke_withResult() throws Exception { ResultListenerProxy proxy = new ResultListenerProxy(mSender); proxy.onResult(mResult); Mockito.verify(mSender).deliver(mMessageCaptor.capture()); Message<ResultListener<Object>, Void> message = mMessageCaptor.getValue(); Assert.assertNotNull(message); message.invoke(mListener); Mockito.verify(mListener).onResult(mResult); }
@SuppressWarnings("ThrowableNotThrown") @Test public void onResult_setExceptionTemplate_withTemplateProvider() throws Exception { ResultListenerProxy proxy = new ResultListenerProxy(mSender); proxy.onResult(mResult); Mockito.verify(mSender).deliver(mMessageCaptor.capture()); Message<ResultListener<Object>, Void> message = mMessageCaptor.getValue(); Assert.assertNotNull(message); Mockito.doReturn(mException).when(mListenerWithExceptionTemplate).exception(); message.invoke(mListenerWithExceptionTemplate); Mockito.verify(mListenerWithExceptionTemplate).onResult(mResult); Assert.assertSame(mException, message.exception()); }
@SuppressWarnings("ResultOfMethodCallIgnored") @Test public void toString_returnFromResult_resultIsMessage() { Message result = Mockito.mock(Message.class); Mockito.doReturn("STRING FROM RESULT").when(result).toString(); ResultListenerProxy proxy = new ResultListenerProxy(mSender); proxy.onResult(result); Mockito.verify(mSender).deliver(mMessageCaptor.capture()); Message<ResultListener<Object>, Void> message = mMessageCaptor.getValue(); Assert.assertNotNull(message); Assert.assertEquals("STRING FROM RESULT", message.toString()); }
@SuppressWarnings("ResultOfMethodCallIgnored") @Test public void toString_returnDefault_resultIsNotMessage() { Mockito.doReturn("A").when(mResult).toString(); ResultListenerProxy proxy = new ResultListenerProxy(mSender); proxy.onResult(mResult); Mockito.verify(mSender).deliver(mMessageCaptor.capture()); Message<ResultListener<Object>, Void> message = mMessageCaptor.getValue(); Assert.assertNotNull(message); Assert.assertEquals(".onResult(A)", message.toString()); }