### Question:
DefaultKeystoreService implements KeystoreService { @Override public void removeCredentialsForCluster(String clusterName, Set<String> aliases) throws KeystoreServiceException { synchronized (this) { KeyStore ks = getCredentialStoreForCluster(clusterName); if (ks != null) { try { for (String alias : aliases) { if (ks.containsAlias(alias)) { ks.deleteEntry(alias); } } removeFromCache(clusterName, aliases); final Path keyStoreFilePath = keyStoreDirPath.resolve(clusterName + CREDENTIALS_SUFFIX); writeKeyStoreToFile(ks, keyStoreFilePath, masterService.getMasterSecret()); } catch (KeyStoreException | IOException | CertificateException | NoSuchAlgorithmException e) { LOG.failedToRemoveCredentialForCluster(clusterName, e); } } } }  void setMasterService(MasterService ms); @Override void init(GatewayConfig config, Map<String, String> options); @Override void start(); @Override void stop(); @Override void createKeystoreForGateway(); @Override KeyStore getKeystoreForGateway(); @Override KeyStore getTruststoreForHttpClient(); @Override KeyStore getSigningKeystore(); @Override KeyStore getSigningKeystore(String keystoreName); @Override void addSelfSignedCertForGateway(String alias, char[] passphrase); @Override void addSelfSignedCertForGateway(String alias, char[] passphrase, String hostname); @Override void createCredentialStoreForCluster(String clusterName); @Override boolean isCredentialStoreForClusterAvailable(String clusterName); @Override boolean isKeystoreForGatewayAvailable(); @Override Key getKeyForGateway(char[] passphrase); @Override Key getKeyForGateway(String alias, char[] passphrase); @Override Certificate getCertificateForGateway(); @Override Key getSigningKey(String alias, char[] passphrase); @Override Key getSigningKey(String keystoreName, String alias, char[] passphrase); @Override KeyStore getCredentialStoreForCluster(String clusterName); @Override void addCredentialForCluster(String clusterName, String alias, String value); @Override void addCredentialsForCluster(String clusterName, Map<String, String> credentials); @Override char[] getCredentialForCluster(String clusterName, String alias); @Override char[] getCredentialForCluster(String clusterName, String alias, KeyStore ks); @Override void removeCredentialForCluster(String clusterName, String alias); @Override void removeCredentialsForCluster(String clusterName, Set<String> aliases); @Override String getKeystorePath(); static final String CREDENTIALS_SUFFIX; }### Answer:
@Test public void testRemoveCredentialsForCluster() throws Exception { char[] masterPassword = "master_password".toCharArray(); MasterService masterService = createMock(MasterService.class); expect(masterService.getMasterSecret()).andReturn(masterPassword).anyTimes(); replay(masterService); Path baseDir = testFolder.newFolder().toPath(); GatewayConfigImpl config = createGatewayConfig(baseDir); CountingDefaultKeystoreService keystoreService = new CountingDefaultKeystoreService(); keystoreService.setMasterService(masterService); keystoreService.init(config, Collections.emptyMap()); String clusterName = "cluster"; Map<String, String> testAliases = new HashMap<>(); testAliases.put("alias1", "value1"); testAliases.put("alias2", "value2"); testAliases.put("alias3", "value3"); Set<String> aliases = testAliases.keySet(); keystoreService.createCredentialStoreForCluster(clusterName); for (String alias : aliases) { keystoreService.addCredentialForCluster(clusterName, alias, testAliases.get(alias)); assertEquals(testAliases.get(alias), String.valueOf(keystoreService.getCredentialForCluster(clusterName, alias))); } keystoreService.clearCounts(); keystoreService.removeCredentialsForCluster(clusterName, aliases); assertEquals("Expected only a single load of the keystore file.", 1, keystoreService.loadCount); assertEquals("Expected only a single write to the keystore file.", 1, keystoreService.storeCount); for (String alias : aliases) { assertNull(keystoreService.getCredentialForCluster(clusterName, alias)); } verify(masterService); }