### Question:
DatabaseConnectionService { public List<String> checkUsersAndDbs(List<UserRole> roles, List<User> users, AWSRdsDatabase db, AWSEnvironment awsEnvironment) throws Exception{ Account account = accountInformationService.getAccountByAlias(awsEnvironment.getAccount()); List<String> userWithRoles = new ArrayList<>(); roles.forEach(role -> { users.forEach(user -> { userWithRoles.add(user.getUserId()+"_"+RoleType.valueOf(role.getRole().toUpperCase()).getShortSuffix()); }); }); List<String> outcome = new ArrayList<>(); try { outcome = databaseConnectionFactory.getConnection(db.getEngine()) .checkIfUsersHasTables( new RdsCheckUsersTableQuery(account.getAlias(), account.getAccountId(), awsEnvironment.getRegion(), awsEnvironment.getSdlc(), getAddress(db.getEndpoint(), db.getDbName()), db.getName()) .withUsers(userWithRoles)); }catch(Exception ex){ logger.error("Failed to check users on database: ", ex); } return outcome; } @Autowired  DatabaseConnectionService(DatabaseConnectionFactory databaseConnectionFactory, AccountInformationService accountInformationService); Boolean grantAccess(AWSRdsDatabase db, AWSEnvironment awsEnvironment, String user, RoleType roleType, String password, Integer timeDays); Boolean revokeAccess(AWSRdsDatabase db, AWSEnvironment awsEnvironment, RoleType roleType, String user); @PreAuthorize("@gatekeeperRoleService.isApprover()") List<String> forceRevokeAccessUsersOnDatabase(GatekeeperRDSInstance db, AWSEnvironment awsEnvironment, List<DbUser> users ); Map<RoleType, List<String>> getAvailableSchemasForDb(GatekeeperRDSInstance database, AWSEnvironment awsEnvironment); Map<RoleType, List<String>> getAvailableSchemasForDb(AWSRdsDatabase database, AWSEnvironment awsEnvironment); String checkDb(DBInstance db, AWSEnvironment awsEnvironment); String checkDb(DBCluster db, AWSEnvironment awsEnvironment); List<DbUser> getUsersForDb(GatekeeperRDSInstance db, AWSEnvironment awsEnvironment); List<String> getAvailableRolesForDb(DBInstance db, AWSEnvironment awsEnvironment); List<String> getAvailableRolesForDb(DBCluster db, AWSEnvironment awsEnvironment); List<String> checkUsersAndDbs(List<UserRole> roles, List<User> users, AWSRdsDatabase db, AWSEnvironment awsEnvironment);  }### Answer:
@Test public void testCheckUsersAndDbs() throws Exception { ArgumentCaptor<RdsCheckUsersTableQuery> argumentCaptor = ArgumentCaptor.forClass(RdsCheckUsersTableQuery.class); List<UserRole> roles = Arrays.asList(new UserRole().setRole("READONLY")); List<User> users = Arrays.asList(new User().setUserId("happyTestUser")); List<String> result = databaseConnectionService.checkUsersAndDbs(roles, users, database, environment); Mockito.verify(mockDBConnection).checkIfUsersHasTables(argumentCaptor.capture()); expectedCheckUsersRequest.withUsers(Arrays.asList("testUserHappy")); RdsCheckUsersTableQuery actualCall = argumentCaptor.getValue(); Assert.assertEquals(expectedRequest, actualCall); Assert.assertTrue(result.isEmpty()); }
@Test public void testCheckUsersAndDbsError() throws Exception { ArgumentCaptor<RdsCheckUsersTableQuery> argumentCaptor = ArgumentCaptor.forClass(RdsCheckUsersTableQuery.class); List<UserRole> roles = Arrays.asList(new UserRole().setRole("READONLY")); List<User> users = Arrays.asList(new User().setUserId("testUser"), new User().setUserId("happyTestUser")); List<String> result = databaseConnectionService.checkUsersAndDbs(roles, users, database, environment); Mockito.verify(mockDBConnection).checkIfUsersHasTables(argumentCaptor.capture()); expectedCheckUsersRequest.withUsers(Arrays.asList("testUserHappy")); RdsCheckUsersTableQuery actualCall = argumentCaptor.getValue(); Assert.assertEquals(expectedRequest, actualCall); Assert.assertTrue(result.isEmpty()); }