Ejemplo n.º 1
0
 /**
  * Prepare for test case execution by initialising the mocks.
  *
  * @throws Exception If there was a problem preparing the test cases.
  */
 @Before
 public void setUp() throws Exception {
   initMocks(this);
   ReflectionUtils.setVariableValueInObject(mojo, "monitorPort", 10000);
   ReflectionUtils.setVariableValueInObject(mojo, "monitorKey", "dummy");
   ReflectionUtils.setVariableValueInObject(wrongMojo, "monitorPort", 10000);
   ReflectionUtils.setVariableValueInObject(wrongMojo, "monitorKey", "jester");
   when(mojo.getLog()).thenReturn(log);
   when(wrongMojo.getLog()).thenReturn(log);
   when(server.isStarted(any(Logger.class))).thenReturn(true);
   when(server.isStopped(any(Logger.class))).thenReturn(true);
 }
Ejemplo n.º 2
0
 /**
  * Verify that stop logs an error if there is no monitor running.
  *
  * @throws Exception If there was an error.
  */
 @Test
 public void testStopWithNoServer() throws Exception {
   whenNew(Socket.class)
       .withParameterTypes(InetAddress.class, int.class)
       .withArguments(any(InetAddress.class), eq(10000))
       .thenThrow(new IOException());
   mojo.execute();
   verify(log).info(eq("Sending command \"stop\" to monitor"));
   verify(log).error(eq("Error sending command to monitor"), any(IOException.class));
   verifyZeroInteractions(server, logger, log, observer);
 }