### Question:
RawSecretKeyFactory extends SecretKeyFactorySpi { @Override protected SecretKey engineGenerateSecret(KeySpec keySpec) throws InvalidKeySpecException { if (keySpec instanceof SecretKeySpec) { return (SecretKeySpec) keySpec; } throw log.keySpecMustBeSecretKeySpec(keySpec.getClass().getName()); }    }### Answer:
@Test(expected = InvalidKeySpecException.class) public void shouldComplainAboutNotGivenASecretKeySpec() throws InvalidKeySpecException { rawFactory.engineGenerateSecret(new RSAPrivateKeySpec(BigInteger.ONE, BigInteger.ONE)); }
@Test public void shouldGenerateSecretKeyFromSecretKeySpec() throws InvalidKeySpecException { assertThat(rawFactory.engineGenerateSecret(keySpec), sameInstance(keySpec)); }