### Question:
DatabaseConnectionService { public String checkDb(DBInstance db, AWSEnvironment awsEnvironment) throws GKUnsupportedDBException{ Account account = accountInformationService.getAccountByAlias(awsEnvironment.getAccount()); List<String> issues = databaseConnectionFactory.getConnection(db.getEngine()).checkDb( new RdsQuery() .withAccount(account.getAlias()) .withAccountId(account.getAccountId()) .withRegion(awsEnvironment.getRegion()) .withSdlc(awsEnvironment.getSdlc()) .withAddress(getAddress(db.getEndpoint(), db.getDBName())) .withDbInstanceName(db.getDBInstanceIdentifier()) ); return issues.stream().collect(Collectors.joining(",")); } @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 testCheckDbRdsHappy() throws Exception { ArgumentCaptor<RdsQuery> argumentCaptor = ArgumentCaptor.forClass(RdsQuery.class); String result = databaseConnectionService.checkDb(rdsInstance, environment); Mockito.verify(mockDBConnection).checkDb(argumentCaptor.capture()); RdsQuery actualCall = argumentCaptor.getValue(); expectedRequest.withAddress(endpoint+":5432/testdb"); Assert.assertEquals(expectedRequest, actualCall); Assert.assertEquals("", result); }
@Test public void testCheckDbRdsUnhappy() throws Exception { rdsInstance.setDBInstanceIdentifier("failthetest"); String result = databaseConnectionService.checkDb(rdsInstance, environment); Assert.assertEquals("Failed", result); }
@Test public void testCheckDbAuroraHappy() throws Exception { ArgumentCaptor<RdsQuery> argumentCaptor = ArgumentCaptor.forClass(RdsQuery.class); String result = databaseConnectionService.checkDb(auroraCluster, environment); Mockito.verify(mockDBConnection).checkDb(argumentCaptor.capture()); RdsQuery actualCall = argumentCaptor.getValue(); expectedRequest.withAddress(endpoint+":5432/testdb"); Assert.assertEquals(expectedRequest, actualCall); Assert.assertEquals("", result); }
@Test public void testCheckDbAuroraUnhappy() throws Exception { auroraCluster.setDBClusterIdentifier("failthetest"); String result = databaseConnectionService.checkDb(auroraCluster, environment); Assert.assertEquals("Failed", result); }