package nu.studer.gradle.util;

import groovy.json.internal.Charsets;
import org.junit.Test;

import javax.xml.bind.DatatypeConverter;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

public final class Base64Java9CompatibilityTest {

    @Test
    public void librariesAreCompatibleInEncoding() {
        byte[] bytes = "some text".getBytes(Charsets.UTF_8);
        assertEquals(Base64.encodeBase64(bytes), DatatypeConverter.printBase64Binary(bytes));
    }

    @Test
    public void librariesAreCompatibleInDecoding() {
        byte[] bytes = "some text".getBytes(Charsets.UTF_8);
        String encoded = DatatypeConverter.printBase64Binary(bytes);
        assertArrayEquals(Base64.decodeBase64(encoded), DatatypeConverter.parseBase64Binary(encoded));
    }

    @Test
    public void librariesAreCompatibleInPrinting() {
        byte[] bytes = "some text".getBytes(Charsets.UTF_8);
        assertEquals(Base64.printHexBinary(bytes), DatatypeConverter.printHexBinary(bytes));
    }

}

@@ -29,46 +29,8 @@
 l;%0A%0A
-import groovy.json.internal.Charsets;%0A
 impo
@@ -89,16 +89,58 @@
 nverter;
+%0Aimport java.nio.charset.StandardCharsets;
 %0A%0Aimport
@@ -379,32 +379,40 @@
  text%22.getBytes(
+Standard
 Charsets.UTF_8);
@@ -612,32 +612,40 @@
  text%22.getBytes(
+Standard
 Charsets.UTF_8);
@@ -931,16 +931,24 @@
 etBytes(
+Standard
 Charsets

Make Java 8 compatible