### Question:
EncryptionUtils { public static byte[] encrypt(PublicKey publicKey, String message) throws Exception { if (publicKey == null) { throw new NullPointerException("public key cannot be empty."); } if (message == null) { throw new NullPointerException("message cannot be null."); } if (message.isEmpty()) { throw new IllegalArgumentException("message cannot be empty."); } Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); return cipher.doFinal(message.getBytes()); } protected  EncryptionUtils(); static void init(PublicKey pubKey); static boolean isInitialized(); static byte[] encrypt(PublicKey publicKey, String message); static byte[] encrypt(String message); static byte[] decryptToBytes(PrivateKey privateKey, byte [] encrypted); static String decrypt(PrivateKey privateKey, byte [] encrypted); static PublicKey getPubKeyFromArray(byte[] bytes); static byte[] convertPublicKeyToByteArray(PublicKey publicKey); static KeyPair generateKeyPair();  }### Answer:
@Test (expected = NullPointerException.class) public void testEncryptNullPublicKey () throws Exception { byte[] data = EncryptionUtils.encrypt(null, "test message"); }
@Test (expected = NullPointerException.class) public void testEncryptNullMessage () throws Exception { byte[] data = EncryptionUtils.encrypt(generatePublicKey(), null); }
@Test (expected = IllegalArgumentException.class) public void testEncryptEmptyMessage () throws Exception { byte[] data = EncryptionUtils.encrypt(generatePublicKey(), ""); }
@Test public void testEncrypt () throws Exception { KeyPair keyPair = buildKeyPair(); PublicKey pubKey = keyPair.getPublic(); PrivateKey privateKey = keyPair.getPrivate(); assertEquals(true, pubKey.getEncoded().length > 0); byte[] data = EncryptionUtils.encrypt(pubKey, "test message"); assertNotNull(data); assertEquals(true, data.length > 0); }
@Test (expected = IllegalStateException.class) public void testEncryptWithoutInit () throws Exception { EncryptionUtils.pubKey = null; EncryptionUtils.encrypt("test message"); }