Skip to content

Commit

Permalink
Merge pull request #1307 from anthonyvdotbe/issue-1306
Browse files Browse the repository at this point in the history
Make Base64Test independent of JDK
  • Loading branch information
PhilipRoman committed Mar 7, 2023
2 parents 5f4eca3 + e90af48 commit 70092c6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/test/java/org/java_websocket/util/Base64Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,22 @@ public void testEncodeBytes() throws IOException {
Assert.assertEquals("", Base64.encodeBytes(new byte[0]));
Assert.assertEquals("QHE=",
Base64.encodeBytes(new byte[]{49, 121, 64, 113, -63, 43, -24, 62, 4, 48}, 2, 2, 0));
Assert.assertEquals("H4sIAAAAAAAAADMEALfv3IMBAAAA",
assertGzipEncodedBytes("H4sIAAAAAAAA", "MEALfv3IMBAAAA",
Base64.encodeBytes(new byte[]{49, 121, 64, 113, -63, 43, -24, 62, 4, 48}, 0, 1, 6));
Assert.assertEquals("H4sIAAAAAAAAAHMoBABQHKKWAgAAAA==",
assertGzipEncodedBytes("H4sIAAAAAAAA", "MoBABQHKKWAgAAAA==",
Base64.encodeBytes(new byte[]{49, 121, 64, 113, -63, 43, -24, 62, 4, 48}, 2, 2, 18));
Assert.assertEquals("F63=",
Base64.encodeBytes(new byte[]{49, 121, 64, 113, 63, 43, -24, 62, 4, 48}, 2, 2, 32));
Assert.assertEquals("6sg7---------6Bc0-0F699L-V----==",
assertGzipEncodedBytes("6sg7--------", "Bc0-0F699L-V----==",
Base64.encodeBytes(new byte[]{49, 121, 64, 113, 63, 43, -24, 62, 4, 48}, 2, 2, 34));
}

// see https://bugs.openjdk.org/browse/JDK-8253142
private void assertGzipEncodedBytes(String expectedPrefix, String expectedSuffix, String actual) {
Assert.assertTrue(actual.startsWith(expectedPrefix));
Assert.assertTrue(actual.endsWith(expectedSuffix));
}

@Test
public void testEncodeBytes2() throws IOException {
thrown.expect(IllegalArgumentException.class);
Expand Down

0 comments on commit 70092c6

Please sign in to comment.