@Test public void testEncrypt() throws Exception { final Encrypto mockEncrypto = mock(Encrypto.class); when(mockEncrypto.encrypt("data".getBytes(Cryptography.CHARSET_NAME))).thenReturn("data".getBytes(Cryptography.CHARSET_NAME)); final String encrypted = CryptoUtils.encrypt("data", mockEncrypto); assertThat(encrypted, is(Base64.encodeToString("data".getBytes(Cryptography.CHARSET_NAME), Base64.NO_WRAP))); verify(mockEncrypto).encrypt("data".getBytes(Cryptography.CHARSET_NAME)); }
@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();   }