### Question:
SsmService { public Map<String, String> checkInstancesWithSsm(AWSEnvironment environment, List<String> instanceIds){ Map<String,String> instanceStatuses = new HashMap<>(); AWSSimpleSystemsManagement ssmClient = awsSessionService.getSsmSession(environment); for(int i = 0; i < instanceIds.size(); i+=50){ Integer upperBound = i+50 < instanceIds.size() ? i+50 : instanceIds.size(); List<String> partitionedList = instanceIds.subList(i, upperBound); DescribeInstanceInformationRequest describeInstanceInformationRequest = new DescribeInstanceInformationRequest(); InstanceInformationFilter filter = new InstanceInformationFilter(); filter.setKey("InstanceIds"); filter.setValueSet(partitionedList); List<InstanceInformationFilter> informationFilters = new ArrayList<>(); informationFilters.add(filter); describeInstanceInformationRequest.setInstanceInformationFilterList(informationFilters); describeInstanceInformationRequest.setMaxResults(50); DescribeInstanceInformationResult describeInstanceInformationResult = ssmClient.describeInstanceInformation(describeInstanceInformationRequest); describeInstanceInformationResult.getInstanceInformationList().forEach(instance -> instanceStatuses.put(instance.getInstanceId(), instance.getPingStatus())); while(describeInstanceInformationResult.getNextToken() != null) { describeInstanceInformationResult = ssmClient.describeInstanceInformation(describeInstanceInformationRequest.withNextToken(describeInstanceInformationResult.getNextToken())); describeInstanceInformationResult.getInstanceInformationList().forEach(instance -> instanceStatuses.put(instance.getInstanceId(), instance.getPingStatus())); } } return instanceStatuses; } @Autowired  SsmService(AwsSessionService awsSessionService,
                      GatekeeperSsmProperties gatekeeperSsmProperties,
                      GatekeeperEmailProperties gatekeeperEmailProperties); Map<String, String> checkInstancesWithSsm(AWSEnvironment environment, List<String> instanceIds); Map<String, String> createUserAccount(AWSEnvironment environment, List<String> instanceIds, String userName, String publicKey, String platform, String hours); Map<String, String> createUserAccount(AWSEnvironment environment, List<String> instanceIds, User user, AccessRequest accessRequest, String platform); Map<String, String> deleteUserAccount(AWSEnvironment environment, List<String> instanceIds, String userName, String platform);  }### Answer:
@Test public void testCheckInstancesWithSsm(){ List<String>instanceIds=new ArrayList<>(); instanceIds.add(firstInstanceInformation.getInstanceId()); Map<String,String> statusMap = ssmService.checkInstancesWithSsm(awsEnvironment,instanceIds); Assert.assertTrue("Verify only one instance is returned", statusMap.size()==1); Assert.assertTrue("Verify the correct instance is returned", statusMap.keySet().contains(firstInstanceInformation.getInstanceId())); Assert.assertTrue("Verify the correct status is returned", statusMap.get(firstInstanceInformation.getInstanceId()).equals(firstInstanceInformation.getPingStatus())); when(firstDescribeInstanceInformationResult.getNextToken()).thenReturn("ABC"); when(awsSimpleSystemsManagementClient.describeInstanceInformation(Mockito.any())).thenReturn(firstDescribeInstanceInformationResult).thenReturn(secondDescribeInstanceInformationResult); statusMap = ssmService.checkInstancesWithSsm(awsEnvironment,instanceIds); Assert.assertTrue("Verify three instances are now returned", statusMap.size()==2); Assert.assertTrue("Verify the correct instance is returned given first instance ID", statusMap.keySet().contains(firstInstanceInformation.getInstanceId())); Assert.assertTrue("Verify the correct instance is returned given second instance ID", statusMap.keySet().contains(secondInstanceInformation.getInstanceId())); Assert.assertTrue("Verify the correct status is returned given first instance ID", statusMap.get(firstInstanceInformation.getInstanceId()).equals(firstInstanceInformation.getPingStatus())); Assert.assertTrue("Verify the correct status is returned given second instance ID", statusMap.get(secondInstanceInformation.getInstanceId()).equals(secondInstanceInformation.getPingStatus())); }