### Question:
RawSecretKeyFactory extends SecretKeyFactorySpi { @Override protected KeySpec engineGetKeySpec(SecretKey key, Class<?> keySpec) throws InvalidKeySpecException { if (SecretKeySpec.class.isAssignableFrom(keySpec) && key instanceof SecretKeySpec) { return (SecretKeySpec) key; } throw log.keyMustImplementSecretKeySpecAndKeySpecMustBeSecretKeySpec( key.getClass().getName() + ", " + keySpec.getName()); }    }### Answer:
@Test(expected = InvalidKeySpecException.class) public void shouldComplainAboutNotGivenASecretKey() throws GeneralSecurityException { rawFactory.engineGetKeySpec(keySpec, RSAPrivateKeySpec.class); }
@Test public void shouldGenerateSecretKeySpecFromSecretKey() throws GeneralSecurityException { assertThat(rawFactory.engineGetKeySpec(keySpec, SecretKeySpec.class), sameInstance(keySpec)); }