### Question:
KeyGeneratorFactory { public static KeyGenerator createKeyGenerator(final Class<? extends KeyGenerator> keyGeneratorClass) { try { return keyGeneratorClass.newInstance(); } catch (final InstantiationException | IllegalAccessException ex) { throw new IllegalArgumentException(String.format("Class %s should have public privilege and no argument constructor", keyGeneratorClass.getName())); } }  static KeyGenerator createKeyGenerator(final Class<? extends KeyGenerator> keyGeneratorClass);  }### Answer:
@Test public void assertCreateKeyGeneratorSuccess() { assertThat(KeyGeneratorFactory.createKeyGenerator(DefaultKeyGenerator.class), instanceOf(DefaultKeyGenerator.class)); }
@Test(expected = IllegalArgumentException.class) public void assertCreateKeyGeneratorFailureWithInstantiationError() { KeyGeneratorFactory.createKeyGenerator(InstantiationKeyGenerator.class); }
@Test(expected = IllegalArgumentException.class) public void assertCreateKeyGeneratorFailureWithIllegalAccess() { KeyGeneratorFactory.createKeyGenerator(IllegalAccessKeyGenerator.class); }