### Question:
HDDSKeyGenerator { public KeyPair generateKey() throws NoSuchProviderException, NoSuchAlgorithmException { return generateKey(securityConfig.getSize(), securityConfig.getKeyAlgo(), securityConfig.getProvider()); } HDDSKeyGenerator(ConfigurationSource configuration);  HDDSKeyGenerator(SecurityConfig config); SecurityConfig getSecurityConfig(); KeyPair generateKey(); KeyPair generateKey(int size); KeyPair generateKey(int size, String algorithm, String provider);  }### Answer:
@Test public void testGenerateKey() throws NoSuchProviderException, NoSuchAlgorithmException { HDDSKeyGenerator keyGen = new HDDSKeyGenerator(config.getConfiguration()); KeyPair keyPair = keyGen.generateKey(); Assert.assertEquals(config.getKeyAlgo(), keyPair.getPrivate().getAlgorithm()); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyPair.getPrivate().getEncoded()); Assert.assertEquals("PKCS#8", keySpec.getFormat()); }
@Test public void testGenerateKeyWithSize() throws NoSuchProviderException, NoSuchAlgorithmException { HDDSKeyGenerator keyGen = new HDDSKeyGenerator(config.getConfiguration()); KeyPair keyPair = keyGen.generateKey(4096); PublicKey publicKey = keyPair.getPublic(); if(publicKey instanceof RSAPublicKey) { Assert.assertEquals(4096, ((RSAPublicKey)(publicKey)).getModulus().bitLength()); } }