Encryptor { public void setEncryptionKey(final String encryptionKey) { try { this.secretKeySpec = new SecretKeySpec(encryptionKey.getBytes(CHARSET_NAME), 0, KEY_LENGTH_IN_BYTES, ALGO); } catch (Exception e) { throw new SymmetricKeyValidationException("Encryption key must be string of length: " + KEY_LENGTH_IN_BYTES, e); } }  String encrypt(final String value); String decrypt(final String encrypted); void setEncryptionKey(final String encryptionKey);  }
@Test(expectedExceptions = { SymmetricKeyValidationException.class }) public void testCreateEncryptionWithTooShortOfAKey() { Encryptor encryption = new Encryptor(); encryption.setEncryptionKey("Too_short"); }
@Test public void testCreateEncryptionWithTooLongOfAKey() { try { Encryptor encryption = new Encryptor(); encryption.setEncryptionKey("Toooooooooo_loooooooooong"); } catch (Throwable e) { Assert.fail(); } }