AgentStatusCommand implements Action { @Override public Object execute() throws Exception { if( this.agents != null ) { for( AgentMessagingInterface agent : this.agents ) { try { System.out.println( agent.agentStatus()); System.out.println( "" ); } catch( Exception e ) { this.logger.warning( "An error occurred while giving agent status. " + e.getMessage()); Utils.logException( this.logger, e ); } } } return null; }  @Override Object execute();  }
@Test public void testExecute_noAgentStatus() throws Exception { AgentStatusCommand cmd = new AgentStatusCommand(); Assert.assertNull( cmd.execute()); }
@Test public void testExecute_emptyAgentList() throws Exception { AgentStatusCommand cmd = new AgentStatusCommand(); cmd.agents = new ArrayList<>( 0 ); Assert.assertNull( cmd.execute()); }
@Test public void testExecute_twoAgentStatus() throws Exception { AgentStatusCommand cmd = new AgentStatusCommand(); AgentMessagingInterface am1 = Mockito.mock( AgentMessagingInterface.class ); AgentMessagingInterface am2 = Mockito.mock( AgentMessagingInterface.class ); cmd.agents = Arrays.asList( am1, am2 ); Assert.assertNull( cmd.execute()); Mockito.verify( am1, Mockito.only()).agentStatus(); Mockito.verify( am2, Mockito.only()).agentStatus(); }
@Test public void testExecute_testException() throws Exception { AgentStatusCommand cmd = new AgentStatusCommand(); AgentMessagingInterface am1 = Mockito.mock( AgentMessagingInterface.class ); Mockito.doThrow( new RuntimeException( "for test" )).when( am1 ).agentStatus(); cmd.agents = Arrays.asList( am1 ); Assert.assertNull( cmd.execute()); Mockito.verify( am1, Mockito.only()).agentStatus(); }