### Question:
GrainUploader { public void uploadGrains(Set<Node> allNodes, List<GrainProperties> grainPropertiesList, ExitCriteriaModel exitModel, SaltConnector sc, ExitCriteria exitCriteria) throws Exception { if (!grainPropertiesList.isEmpty()) { for (GrainProperties grainProperties : grainPropertiesList) { handleGrainProperties(allNodes, exitModel, sc, exitCriteria, grainProperties); } } }  void uploadGrains(Set<Node> allNodes, List<GrainProperties> grainPropertiesList, ExitCriteriaModel exitModel, SaltConnector sc,
            ExitCriteria exitCriteria);  }### Answer:
@Test public void testWhenGrainPropertiesEmpty() throws Exception { underTest.uploadGrains(Set.of(), List.of(), exitCriteriaModel, saltConnector, exitCriteria); verify(saltCommandRunner, times(0)).runSaltCommand(eq(saltConnector), any(GrainAddRunner.class), eq(exitCriteriaModel), eq(exitCriteria)); }
@Test public void testAllGrainsAppendCalled() throws Exception { Set<Node> allNodes = Set.of(); GrainProperties gp1 = new GrainProperties(); GrainProperties gp2 = new GrainProperties(); gp1.put("HOST1", Map.of("GRAINKEY1", "GRAINVALUE1", "GRAINKEY2", "GRAINVALUE2")); gp1.put("HOST2", Map.of("GRAINKEY1", "GRAINVALUE1", "GRAINKEY2", "GRAINVALUE2")); gp1.put("HOST3", Map.of("GRAINKEY3", "GRAINVALUE3", "GRAINKEY2", "GRAINVALUE2")); gp1.put("HOST4", Map.of("GRAINKEY5", "GRAINVALUE5")); gp1.put("HOST5", Map.of("GRAINKEY6", "GRAINVALUE6", "GRAINKEY7", "GRAINVALUE7")); gp2.put("HOST8", Map.of("GRAINKEY8", "GRAINVALUE8", "GRAINKEY9", "GRAINVALUE9")); underTest.uploadGrains(allNodes, List.of(gp1, gp2), exitCriteriaModel, saltConnector, exitCriteria); ArgumentCaptor<GrainAddRunner> grainAddRunnerArgumentCaptor = ArgumentCaptor.forClass(GrainAddRunner.class); verify(saltCommandRunner, atLeastOnce()).runSaltCommand(eq(saltConnector), grainAddRunnerArgumentCaptor.capture(), eq(exitCriteriaModel), eq(exitCriteria)); List<GrainAddRunner> allValues = grainAddRunnerArgumentCaptor.getAllValues(); assertEquals(8, allValues.size()); assertGrainHasAllTheHosts(allValues, "GRAINKEY2", "GRAINVALUE2", "HOST1", "HOST2", "HOST3"); assertGrainHasAllTheHosts(allValues, "GRAINKEY1", "GRAINVALUE1", "HOST1", "HOST2"); assertGrainHasAllTheHosts(allValues, "GRAINKEY3", "GRAINVALUE3", "HOST3"); assertGrainHasAllTheHosts(allValues, "GRAINKEY5", "GRAINVALUE5", "HOST4"); assertGrainHasAllTheHosts(allValues, "GRAINKEY6", "GRAINVALUE6", "HOST5"); assertGrainHasAllTheHosts(allValues, "GRAINKEY7", "GRAINVALUE7", "HOST5"); assertGrainHasAllTheHosts(allValues, "GRAINKEY8", "GRAINVALUE8", "HOST8"); assertGrainHasAllTheHosts(allValues, "GRAINKEY9", "GRAINVALUE9", "HOST8"); }