### Question:
CryptographyUtils { @Nullable public static String encrypt(@Nullable final String value, @NonNull final Encrypto encrypto) { if (value == null || value.length() == 0) { return value; } try { return new String( Base64.encode(encrypto.encrypt(value.getBytes(Cryptography.CHARSET_NAME)), Base64.NO_WRAP), Cryptography.CHARSET_NAME ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new AssertionError(Cryptography.CHARSET_NAME + " encoding is not supported!"); } } private  CryptographyUtils(); @Nullable static String encrypt(@Nullable final String value, @NonNull final Encrypto encrypto); @Nullable static String decrypt(@Nullable final String value, @NonNull final Decrypto decrypto); @Nullable static String makeSHA1(@Nullable final String value);  }### Answer:
@Test public void testEncrypt() throws Exception { final Encrypto mockEncrypto = mock(Encrypto.class); when(mockEncrypto.encrypt("android".getBytes(Cryptography.CHARSET_NAME))).thenReturn("android".getBytes(Cryptography.CHARSET_NAME)); final String encrypted = CryptographyUtils.encrypt("android", mockEncrypto); assertThat(encrypted, is(Base64.encodeToString("android".getBytes(Cryptography.CHARSET_NAME), Base64.NO_WRAP))); verify(mockEncrypto).encrypt("android".getBytes(Cryptography.CHARSET_NAME)); }
@Test public void testEncryptEmptyValue() { final Encrypto mockEncrypto = mock(Encrypto.class); final String encrypted = CryptographyUtils.encrypt("", mockEncrypto); assertThat(encrypted, is("")); verifyZeroInteractions(mockEncrypto); }
@SuppressWarnings("ConstantConditions") @Test public void testEncryptNullValue() { final Encrypto mockEncrypto = mock(Encrypto.class); final String encrypted = CryptographyUtils.encrypt(null, mockEncrypto); assertThat(encrypted, is(nullValue())); verifyZeroInteractions(mockEncrypto); }