Skip to content

Commit a5ef06c

Browse files
added method for basic encoding without padding
1 parent f76247a commit a5ef06c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

core-java-8/src/main/java/com/demo/encoding/Java8EncodeDecode.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ public void whenStringIsEncoded_thenStringCanBeDecoded() throws UnsupportedEncod
3232
assertEquals(originalInput, decodedString);
3333

3434
}
35+
36+
@Test
37+
public void whenStringIsEncodedWithoutPadding() throws UnsupportedEncodingException {
38+
String originalInput = "test input";
39+
String encodedString = Base64.getEncoder().withoutPadding().encodeToString(originalInput.getBytes());
40+
assertNotNull(encodedString);
41+
assertNotEquals(originalInput, encodedString);
42+
}
43+
44+
@Test
45+
public void whenStringIsEncodedWithoutPadding_thenStringCanBeDecoded() throws UnsupportedEncodingException {
46+
String originalInput = "test input";
47+
String encodedString = Base64.getEncoder().withoutPadding().encodeToString(originalInput.getBytes());
48+
49+
byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
50+
String decodedString = new String(decodedBytes);
51+
52+
assertNotNull(decodedString);
53+
assertEquals(originalInput, decodedString);
54+
55+
}
56+
3557

3658
@Test
3759
public void whenURLIsEncoded() throws UnsupportedEncodingException {

0 commit comments

Comments
 (0)