title: How can I assert on returned mocked object with Mockito
body: <p>I am trying to test this code with Mockito:</p>
  
  <pre><code>@Override
  public Response killServer() {
      new Thread(new Runnable() {
          @Override
          public void run() {
              Slave slave = SlaveRunner.getSlave();
              slave.initiateShutdown();
          }
      }).start();
      String host = System.getenv("HOSTNAME");
      return Response.ok().entity(new String ("Stopping REST service on " + host)).build();
  }   
  </code></pre>
  
  <p>I can't run this in a unit test, as the system will exit. The <code>initiateShutdown()</code> method does a <code>System.exit();</code>. I have mocked this class with:</p>
  
  <pre><code>@Test
  public void killServer() throws RestInterfaceException {
      SlaveRestInterface mockedAgent = Mockito.mock(SlaveRemoteProxy.class);
      Response r = Mockito.mock(Response.class);      
      Mockito.when(mockedAgent.killServer()).thenReturn(r);
      Assert.assertEquals(r.readEntity(String.class), "Stopping REST service on " + System.getenv("HOSTNAME"));
      r.close();
  }
  </code></pre>
  
  <p>I can't do the assertion like this, as r will always be null. Is there any way to assert the response or do I just have to leave out assertions for this test?</p>