JobAssignerUtilities { public List<Agent> getEligibleAgentsForJob(Job job, List<Agent> agents) { List<Agent> eligibleAgents = new ArrayList<>(); for (Agent agent : agents) { boolean isEligible = this.isAgentEligibleForJob(job, agent); if (isEligible) { eligibleAgents.add(agent); } } return eligibleAgents; }  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 getEligibleAgentsForJob_matchingResources_oneObject() { Job job = this.getJobWithResources(1); List<Agent> agents = this.getViableAgentsWithResources(1, 1); String expectedId = agents.get(AGENT_ZERO).getId(); int expectedCollectionSize = TestsConstants.TESTS_COLLECTION_SIZE_ONE_OBJECT; List<Agent> actualResult = this.jobAssignerUtilities.getEligibleAgentsForJob(job, agents); String actualId = actualResult.get(AGENT_ZERO).getId(); int actualCollectionSize = actualResult.size(); Assert.assertEquals(expectedId, actualId); Assert.assertEquals(expectedCollectionSize, actualCollectionSize); }
@Test public void getEligibleAgentsForJob_agentAssigned_noObject() { Job job = this.getJobWithResources(1); List<Agent> agents = this.getViableAgentsWithResources(1, 1); agents.get(AGENT_ZERO).setAssigned(true); int expectedCollectionSize = TestsConstants.TESTS_COLLECTION_SIZE_NO_OBJECTS; List<Agent> actualResult = this.jobAssignerUtilities.getEligibleAgentsForJob(job, agents); int actualCollectionSize = actualResult.size(); Assert.assertEquals(expectedCollectionSize, actualCollectionSize); }
@Test public void getEligibleAgentsForJob_nonMatchingResources_noObject() { Job job = this.getJobWithResources(1); List<Agent> agents = this.getViableAgentsWithResources(1, 1); agents.get(AGENT_ZERO).getResources().remove("Resource0"); agents.get(AGENT_ZERO).getResources().add("Non-matching resource"); int expectedCollectionSize = TestsConstants.TESTS_COLLECTION_SIZE_NO_OBJECTS; List<Agent> actualResult = this.jobAssignerUtilities.getEligibleAgentsForJob(job, agents); int actualCollectionSize = actualResult.size(); Assert.assertEquals(expectedCollectionSize, actualCollectionSize); }
@Test public void getEligibleAgentsForJob_notEnoughResources_noObject() { Job job = this.getJobWithResources(2); List<Agent> agents = this.getViableAgentsWithResources(1, 1); int expectedCollectionSize = TestsConstants.TESTS_COLLECTION_SIZE_NO_OBJECTS; List<Agent> actualResult = this.jobAssignerUtilities.getEligibleAgentsForJob(job, agents); int actualCollectionSize = actualResult.size(); Assert.assertEquals(expectedCollectionSize, actualCollectionSize); }
@Test public void getEligibleAgentsForJob_moreResourcesThanNecessary_oneObject() { Job job = this.getJobWithResources(1); List<Agent> agents = this.getViableAgentsWithResources(1, 2); String expectedId = agents.get(AGENT_ZERO).getId(); int expectedCollectionSize = TestsConstants.TESTS_COLLECTION_SIZE_ONE_OBJECT; List<Agent> actualResult = this.jobAssignerUtilities.getEligibleAgentsForJob(job, agents); String actualId = actualResult.get(AGENT_ZERO).getId(); int actualCollectionSize = actualResult.size(); Assert.assertEquals(expectedId, actualId); Assert.assertEquals(expectedCollectionSize, actualCollectionSize); }
@Test public void getEligibleAgentsForJob_someWithMatchingResources_oneObject() { Job job = this.getJobWithResources(1); List<Agent> agents = this.getViableAgentsWithResources(2, 1); agents.get(AGENT_ONE).getResources().remove("Resource0"); agents.get(AGENT_ONE).getResources().add("Non-matching resource"); String expectedId = agents.get(AGENT_ZERO).getId(); int expectedCollectionSize = TestsConstants.TESTS_COLLECTION_SIZE_ONE_OBJECT; List<Agent> actualResult = this.jobAssignerUtilities.getEligibleAgentsForJob(job, agents); String actualId = actualResult.get(AGENT_ZERO).getId(); int actualCollectionSize = actualResult.size(); Assert.assertEquals(expectedId, actualId); Assert.assertEquals(expectedCollectionSize, actualCollectionSize); }