JobAssignerUtilities { public Agent pickMostSuitableAgent(List<Agent> agents) { Agent agentForJob = null; int numberOfResources = Integer.MAX_VALUE; for (Agent agent : agents) { if (agent.getResources().size() < numberOfResources) { numberOfResources = agent.getResources().size(); agentForJob = agent; } } return agentForJob; }  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 pickMostSuitableAgent_oneAgent_sameAgent() { List<Agent> agents = this.getViableAgentsWithResources(1, 1); String expectedResult = agents.get(AGENT_ZERO).getId(); String actualResult = this.jobAssignerUtilities.pickMostSuitableAgent(agents).getId(); Assert.assertEquals(expectedResult, actualResult); }
@Test public void pickMostSuitableAgent_twoAgents_AgentWithLessResources() { List<Agent> agents = this.getViableAgentsWithResources(2, 1); agents.get(AGENT_ZERO).getResources().remove("Resource0"); String expectedResult = agents.get(AGENT_ZERO).getId(); String actualResult = this.jobAssignerUtilities.pickMostSuitableAgent(agents).getId(); Assert.assertEquals(expectedResult, actualResult); }
@Test public void assignJobToAgent_noAgents_null() { List<Agent> agents = this.getViableAgentsWithResources(0, 0); Agent actualResult = this.jobAssignerUtilities.pickMostSuitableAgent(agents); Assert.assertNull(actualResult); }