### Question:
DatabaseConnectionService { public Boolean revokeAccess(AWSRdsDatabase db, AWSEnvironment awsEnvironment, RoleType roleType, String user) throws GKUnsupportedDBException{ Account account = accountInformationService.getAccountByAlias(awsEnvironment.getAccount()); boolean status = false; logger.info("Revoking access on " + db.getName() + "(" + db.getEndpoint() + ")"); try{ status = databaseConnectionFactory.getConnection(db.getEngine()) .revokeAccess(new RdsRevokeAccessQuery(account.getAlias(), account.getAccountId(), awsEnvironment.getRegion(), awsEnvironment.getSdlc(), getAddress(db.getEndpoint(), db.getDbName()), db.getName()) .withUser(user) .withRole(roleType)); logger.info("User " + user + " removed from " + db.getName() + "(" + db.getInstanceId() + ")? " + status); }catch(GKUnsupportedDBException e){ logger.info("Skipping access for " + db.getName() + " as Engine " + db.getEngine() + " is not supported"); }catch(Exception e){ logger.info("Failed to remove user from " + db.getName() + "(" + db.getInstanceId() + "), exception is as follows: "); e.printStackTrace(); } return status; } @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 testRevokeAccessHappy() throws Exception { ArgumentCaptor<RdsRevokeAccessQuery> argumentCaptor = ArgumentCaptor.forClass(RdsRevokeAccessQuery.class); String testUser = "tstuserhappy"; boolean outcome = databaseConnectionService.revokeAccess(database, environment, RoleType.READONLY, testUser); Mockito.verify(mockDBConnection).revokeAccess(argumentCaptor.capture()); expectedRevokeRequest.withUser(testUser) .withRole(RoleType.READONLY); RdsRevokeAccessQuery actualRevokeRequest = argumentCaptor.getValue(); Assert.assertEquals(expectedRevokeRequest, actualRevokeRequest); Assert.assertTrue(outcome); }
@Test public void testRevokeAccessUnsupportedDB() throws Exception { String testUser = "tstuserhappy"; database.setEngine(TEST_UNSUPPORTED_ENGINE); boolean outcome = databaseConnectionService.revokeAccess(database, environment, RoleType.READONLY, testUser); expectedRevokeRequest.withUser(testUser) .withRole(RoleType.READONLY); Assert.assertFalse(outcome); }
@Test public void testRevokeAccessException() throws Exception { String testUser = "tstuserhappy"; boolean outcome = databaseConnectionService.revokeAccess(database, environment, RoleType.READONLY, null); expectedRevokeRequest.withUser(testUser) .withRole(RoleType.READONLY); Assert.assertFalse(outcome); }