JobAssignerUtilities { public boolean isAgentEligibleForJob(Job job, Agent agent) { boolean isEligible = true; if ((agent == null) || !agent.isConnected() || !agent.isEnabled() || agent.isRunning() || agent.isAssigned()) { isEligible = false; } else { for (String resource : job.getResources()) { if (!(agent.getResources().contains(resource))) { isEligible = false; break; } } } return isEligible; }  Agent assignAgentToJob(Job job, List<Agent> agents); List<Agent> getEligibleAgentsForJob(Job job, List<Agent> agents); Agent pickMostSuitableAgent(List<Agent> agents); boolean isAgentEligibleForJob(Job job, Agent agent); boolean hasAssignableAgent(Job job, List<Agent> agents); boolean isAssignedAgentEligibleForJob(Job job, Agent agent);  }
@Test public void isAgentEligibleForJob_eligibleAgent_true() { Job job = this.getJobWithResources(3); List<Agent> agents = this.getViableAgentsWithResources(1, 3); Agent agent = agents.get(AGENT_ZERO); agent.setConnected(true); agent.setEnabled(true); agent.setRunning(false); boolean actualResult = this.jobAssignerUtilities.isAgentEligibleForJob(job, agent); Assert.assertTrue(actualResult); }
@Test public void isAgentEligibleForJob_agentIsNull_false() { Job job = new Job(); Agent agent = null; boolean actualResult = this.jobAssignerUtilities.isAgentEligibleForJob(job, agent); Assert.assertFalse(actualResult); }
@Test public void isAgentEligibleForJob_agentIsNotConnected_false() { Job job = new Job(); Agent agent = new Agent(); agent.setConnected(false); agent.setEnabled(true); agent.setRunning(false); boolean actualResult = this.jobAssignerUtilities.isAgentEligibleForJob(job, agent); Assert.assertFalse(actualResult); }
@Test public void isAgentEligibleForJob_agentIsNotEnabled_false() { Job job = new Job(); Agent agent = new Agent(); agent.setConnected(true); agent.setEnabled(false); agent.setRunning(false); boolean actualResult = this.jobAssignerUtilities.isAgentEligibleForJob(job, agent); Assert.assertFalse(actualResult); }
@Test public void isAgentEligibleForJob_agentIsRunning_false() { Job job = new Job(); Agent agent = new Agent(); agent.setConnected(true); agent.setEnabled(true); agent.setRunning(true); boolean actualResult = this.jobAssignerUtilities.isAgentEligibleForJob(job, agent); Assert.assertFalse(actualResult); }
@Test public void isAgentEligibleForJob_agentHasWrongResources_false() { Job job = this.getJobWithResources(1); List<Agent> agents = this.getViableAgentsWithResources(1, 0); Agent agent = agents.get(AGENT_ZERO); agent.setConnected(true); agent.setEnabled(true); agent.setRunning(false); agents.get(AGENT_ZERO).getResources().add("Non-matching resource"); boolean actualResult = this.jobAssignerUtilities.isAgentEligibleForJob(job, agent); Assert.assertFalse(actualResult); }