### Question:
SingleKeyManagementService implements KeyManagementService<SecretKeySpec> { @Override public SecretKeySpec getRandomKey() throws GeneralSecurityException { SecretKey secretKey = keyGen.generateKey(); byte[] encoded = secretKey.getEncoded(); return new SecretKeySpec(encoded, keyGenAlgo); } SingleKeyManagementService(KMSConfig config, String defaultContainerKey); @Override void register(short accountId, short containerId); @Override void register(String context); @Override SecretKeySpec getKey(short accountId, short containerId); @Override SecretKeySpec getKey(String context); @Override SecretKeySpec getRandomKey(); @Override void close();  }### Answer:
@Test public void testRandomKey() throws Exception { int[] keySizes = {128, 192, 256}; for (int keySize : keySizes) { String key = TestUtils.getRandomKey(keySize); Properties props = getKMSProperties(key, keySize); VerifiableProperties verifiableProperties = new VerifiableProperties((props)); KeyManagementService<SecretKeySpec> kms = new SingleKeyManagementServiceFactory(verifiableProperties, CLUSTER_NAME, REGISTRY).getKeyManagementService(); SecretKeySpec randomKey = kms.getRandomKey(); Assert.assertNotNull("Random key cannot be null", randomKey); Assert.assertEquals("Key size mismatch", keySize, randomKey.getEncoded().length * 8); } }
@Test public void testSingleKMSFactory() throws Exception { Properties props = getKMSProperties("", DEFAULT_KEY_SIZE_CHARS); VerifiableProperties verifiableProperties = new VerifiableProperties((props)); try { new SingleKeyManagementServiceFactory(verifiableProperties, CLUSTER_NAME, REGISTRY).getKeyManagementService(); Assert.fail("SingleKeyManagementFactory instantiation should have failed as single default key is null "); } catch (IllegalArgumentException e) { } String key = TestUtils.getRandomKey(DEFAULT_KEY_SIZE_CHARS); props = getKMSProperties(key, DEFAULT_RANDOM_KEY_SIZE_BITS); verifiableProperties = new VerifiableProperties((props)); KeyManagementService<SecretKeySpec> kms = new SingleKeyManagementServiceFactory(verifiableProperties, CLUSTER_NAME, REGISTRY).getKeyManagementService(); }