added method for basic encoding without padding

This commit is contained in:
Vrajesh Jayswal 2015-08-15 10:50:58 +05:30
parent f76247aaa8
commit a5ef06c93f
1 changed files with 22 additions and 0 deletions

View File

@ -33,6 +33,28 @@ public class Java8EncodeDecode {
}
@Test
public void whenStringIsEncodedWithoutPadding() throws UnsupportedEncodingException {
String originalInput = "test input";
String encodedString = Base64.getEncoder().withoutPadding().encodeToString(originalInput.getBytes());
assertNotNull(encodedString);
assertNotEquals(originalInput, encodedString);
}
@Test
public void whenStringIsEncodedWithoutPadding_thenStringCanBeDecoded() throws UnsupportedEncodingException {
String originalInput = "test input";
String encodedString = Base64.getEncoder().withoutPadding().encodeToString(originalInput.getBytes());
byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
String decodedString = new String(decodedBytes);
assertNotNull(decodedString);
assertEquals(originalInput, decodedString);
}
@Test
public void whenURLIsEncoded() throws UnsupportedEncodingException {
String originalURL = "https://www.google.co.nz/?gfe_rd=cr&ei=dzbFVf&gws_rd=ssl#q=java";