コード例 #1
0
 @Before
 public void setUp() throws Exception {
   listener = spy(new CommandRequestListener());
   when(payload.getMessage(CommandRequest.class)).thenReturn(commandRequest);
   when(peerManager.getPeer(any(String.class))).thenReturn(sourcePeer);
   when(localPeer.bindHost(any(String.class))).thenReturn(host);
   doReturn(peerManager).when(listener).getPeerManager();
   doReturn(localPeer).when(peerManager).getLocalPeer();
 }
コード例 #2
0
  @Test
  public void testOnRequest() throws Exception {
    listener.onRequest(payload);

    verify(localPeer).executeAsync(any(RequestBuilder.class), eq(host), any(CommandCallback.class));

    doThrow(exception)
        .when(localPeer)
        .executeAsync(any(RequestBuilder.class), eq(host), any(CommandCallback.class));

    listener.onRequest(payload);

    verify(exception).printStackTrace(any(PrintStream.class));

    when(payload.getMessage(CommandRequest.class)).thenReturn(null);

    listener.onRequest(payload);

    verify(peerManager, times(2)).getPeer(any(String.class));
  }