DefaultKeyGenerator implements KeyGenerator { @Override public byte[] generate() { throw new UnsupportedOperationException("Knowing the key strength is required to generate a key."); }  @Override byte[] generate(); @Override byte[] generate(KeyGenerationParameters parameters);  }
@Test void generateWithoutArgument() { Throwable exception = assertThrows(UnsupportedOperationException.class, () -> generator.generate()); assertEquals("Knowing the key strength is required to generate a key.", exception.getMessage()); }
@Test void generateWithStrengthParameter() { KeyGenerationParameters params = new GenericKeyGenerationParameters(128); byte[] key = generator.generate(params); assertThat(key.length, equalTo(128)); assertThat(key, not(equalTo(generator.generate(params)))); assertThat(generator.generate(new GenericKeyGenerationParameters(16)).length, equalTo(16)); }