### Question:
CipherEncrypto implements Encrypto { @Override @NonNull public byte[] encrypt(@NonNull final byte[] data) throws CryptographyException { try { return cipher.doFinal(data); } catch (IllegalBlockSizeException | BadPaddingException e) { throw new CryptographyException("Encryption failed!", e); } } @SuppressWarnings("WeakerAccess")  CipherEncrypto(final Builder builder); @Override @NonNull byte[] encrypt(@NonNull final byte[] data);  }### Answer:
@Test public void testEncrypt() throws Exception { final KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(128); final Key key = keyGenerator.generateKey(); final Encrypto encrypto = new CipherEncrypto.Builder() .cipher(new CipherBuilder() .transformation(CipherCryptography.createTransformation( CipherCryptography.Algorithm.AES, CipherCryptography.Mode.ECB, CipherCryptography.Padding.PKCS7 )) .opMode(Cipher.ENCRYPT_MODE) .key(key) .build() ) .build(); final Decrypto decrypto = new CipherDecrypto.Builder() .cipher(new CipherBuilder() .transformation(CipherCryptography.createTransformation( CipherCryptography.Algorithm.AES, CipherCryptography.Mode.ECB, CipherCryptography.Padding.PKCS7 )) .opMode(Cipher.DECRYPT_MODE) .key(key) .build() ) .build(); final byte[] encryptedData = encrypto.encrypt("Android".getBytes(Cryptography.CHARSET_NAME)); assertThat(decrypto.decrypt(encryptedData), is("Android".getBytes(Cryptography.CHARSET_NAME))); }
@Test public void testEncryptWithIllegalBlockSize() throws Exception { final KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(128); final Key key = keyGenerator.generateKey(); final Encrypto encrypto = new CipherEncrypto.Builder() .cipher(new CipherBuilder() .transformation(CipherCryptography.createTransformation( CipherCryptography.Algorithm.AES, CipherCryptography.Mode.ECB, CipherCryptography.Padding.NO )) .opMode(Cipher.ENCRYPT_MODE) .key(key) .build() ) .build(); try { encrypto.encrypt("Android".getBytes(Cryptography.CHARSET_NAME)); } catch (CryptographyException e) { assertThat(e.getCause(), instanceOf(IllegalBlockSizeException.class)); return; } throw new AssertionError("No exception thrown when expected one."); }