Last active
March 28, 2018 16:43
-
-
Save grommitz/14abb337a6b44696c0b1675fb8ca1424 to your computer and use it in GitHub Desktop.
Test to prove that java.util.Base64 class works identically to sun.misc.BASE64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testBase64() throws IOException { | |
String s = "the CAT sat on the MAT"; | |
String enc = "dGhlIENBVCBzYXQgb24gdGhlIE1BVA=="; | |
String sunMiscVersion = new String(new sun.misc.BASE64Decoder().decodeBuffer(enc), "utf8"); | |
String commonsVersion = new String(Base64.getDecoder().decode(enc), "utf8"); | |
Assert.assertThat(commonsVersion, is(sunMiscVersion)); | |
Assert.assertThat(commonsVersion, is(s)); | |
String encodedBySunMisc = new sun.misc.BASE64Encoder().encode(s.getBytes()); | |
String encodedByCommons = new String(Base64.getEncoder().encode(s.getBytes())); | |
assertThat(encodedByCommons, is(encodedBySunMisc)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment