Merge pull request #12471 from anuragkumawat/JAVA-13089

JAVA-13089 Verify Java Base64 Encoding and Decoding article
This commit is contained in:
kwoyke 2022-07-12 09:23:43 +02:00 committed by GitHub
commit 6f6612608d
1 changed files with 17 additions and 1 deletions

View File

@ -96,7 +96,23 @@ public class Java8EncodeDecodeUnitTest {
assertNotNull(decodedMime); assertNotNull(decodedMime);
} }
// @Test
public void whenEncodedStringHasValidCharacters_thenStringCanBeDecoded() {
final String encodedString = "dGVzdCMkaW5wdXQ+";
final byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
final String decodedString = new String(decodedBytes);
assertNotNull(decodedString);
}
@Test(expected = IllegalArgumentException.class)
public void whenEncodedStringHasInvalidCharacters_thenIllegalArgumentException() {
final String encodedString = "dGVzdCMkaW5wdXQ#";
final byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
final String decodedString = new String(decodedBytes);
assertNotNull(decodedString);
}
private static StringBuilder getMimeBuffer() { private static StringBuilder getMimeBuffer() {
final StringBuilder buffer = new StringBuilder(); final StringBuilder buffer = new StringBuilder();