@SuppressWarnings("ConstantConditions") @Test public void testDecryptNullValue() { final Decrypto mockDecrypto = mock(Decrypto.class); final String decrypted = CryptoUtils.decrypt(null, mockDecrypto); assertThat(decrypted, is(nullValue())); verify(mockDecrypto, times(0)).decrypt(any(byte[].class)); }
@Nullable static String decrypt(@Nullable final String value, @NonNull final Decrypto decrypto) { if (value == null || value.length() == 0) { return value; } try { return new String( decrypto.decrypt(Base64.decode(value.getBytes(Cryptography.CHARSET_NAME), Base64.DEFAULT)), Cryptography.CHARSET_NAME ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new AssertionError(Cryptography.CHARSET_NAME + " encoding is not supported!"); } }
CryptoUtils { @Nullable static String decrypt(@Nullable final String value, @NonNull final Decrypto decrypto) { if (value == null || value.length() == 0) { return value; } try { return new String( decrypto.decrypt(Base64.decode(value.getBytes(Cryptography.CHARSET_NAME), Base64.DEFAULT)), Cryptography.CHARSET_NAME ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new AssertionError(Cryptography.CHARSET_NAME + " encoding is not supported!"); } } }
CryptoUtils { @Nullable static String decrypt(@Nullable final String value, @NonNull final Decrypto decrypto) { if (value == null || value.length() == 0) { return value; } try { return new String( decrypto.decrypt(Base64.decode(value.getBytes(Cryptography.CHARSET_NAME), Base64.DEFAULT)), Cryptography.CHARSET_NAME ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new AssertionError(Cryptography.CHARSET_NAME + " encoding is not supported!"); } } private  CryptoUtils(); }
CryptoUtils { @Nullable static String decrypt(@Nullable final String value, @NonNull final Decrypto decrypto) { if (value == null || value.length() == 0) { return value; } try { return new String( decrypto.decrypt(Base64.decode(value.getBytes(Cryptography.CHARSET_NAME), Base64.DEFAULT)), Cryptography.CHARSET_NAME ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new AssertionError(Cryptography.CHARSET_NAME + " encoding is not supported!"); } } private  CryptoUtils();  }
CryptoUtils { @Nullable static String decrypt(@Nullable final String value, @NonNull final Decrypto decrypto) { if (value == null || value.length() == 0) { return value; } try { return new String( decrypto.decrypt(Base64.decode(value.getBytes(Cryptography.CHARSET_NAME), Base64.DEFAULT)), Cryptography.CHARSET_NAME ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new AssertionError(Cryptography.CHARSET_NAME + " encoding is not supported!"); } } private  CryptoUtils();   }