@SuppressWarnings("ConstantConditions") @Test public void testEncryptNullValue() { final Encrypto mockEncrypto = mock(Encrypto.class); final String encrypted = CryptoUtils.encrypt(null, mockEncrypto); assertThat(encrypted, is(nullValue())); verify(mockEncrypto, times(0)).encrypt(any(byte[].class)); }
@Nullable 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!"); } }
CryptoUtils { @Nullable 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!"); } } }
CryptoUtils { @Nullable 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  CryptoUtils(); }
CryptoUtils { @Nullable 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  CryptoUtils();  }
CryptoUtils { @Nullable 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  CryptoUtils();   }