package com.bubelich;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import javax.xml.bind.DatatypeConverter;
import java.util.Random;

public class jBase64Test extends Assert{

    private byte [] input_t1 = null;
    private byte [] input_t2 = null;
    private byte [] input_t3 = null;
//    private static byte [] input_t1 = new byte[1024+0];
//    private static byte [] input_t2 = new byte[1024+1];
//    private static byte [] input_t3 = new byte[1024+2];

    @Before
    public void setUp(){

        Random rnd = new Random();

//        rnd.nextBytes(input_t1);
//        rnd.nextBytes(input_t2);
//        rnd.nextBytes(input_t3);

    }

    @Test
    @Ignore
    public void testEncode() throws Exception {

        // For one byte //
        assertEquals("Pw==",jBase64.encode(new byte[]{0x3f},jBase64.ALPHABET.BASE));

        // For two byte //
        assertEquals("P08=",jBase64.encode(new byte[]{0x3f,0x4f}, jBase64.ALPHABET.BASE));

        // For three bytes //
        assertEquals("P09f", jBase64.encode(new byte[]{0x3f, 0x4f, 0x5f}, jBase64.ALPHABET.BASE));

        // Text without padding //
        assertEquals("Encode input T1", DatatypeConverter.printBase64Binary(input_t1), jBase64.encode(input_t1, jBase64.ALPHABET.BASE));

        // Text with 1th padding //
        assertEquals("Encode input T2", DatatypeConverter.printBase64Binary(input_t2), jBase64.encode(input_t2, jBase64.ALPHABET.BASE));

        // Text with 2th padding //
        assertEquals("Encode input T3", DatatypeConverter.printBase64Binary(input_t3), jBase64.encode(input_t3, jBase64.ALPHABET.BASE));

        // For null //
        try { jBase64.encode(null, jBase64.ALPHABET.BASE); }
        catch (NullPointerException ex){ /* OK */}

        // Empty byte //
        try { jBase64.encode(new byte[]{}, jBase64.ALPHABET.BASE); }
        catch (RuntimeException ex){ /* OK */}

    }

    @Test
    @Ignore
    public void testDecode() throws Exception {

        // With padding //
        assertEquals("any carnal pleasur",new String(jBase64.decode("YW55IGNhcm5hbCBwbGVhc3Vy", jBase64.ALPHABET.BASE,true)));
        assertEquals("any carnal pleasu",new String(jBase64.decode("YW55IGNhcm5hbCBwbGVhc3U=", jBase64.ALPHABET.BASE,true)));
        assertEquals("any carnal pleas",new String(jBase64.decode("YW55IGNhcm5hbCBwbGVhcw==", jBase64.ALPHABET.BASE,true)));


        // Without padding //
        assertEquals("any carnal pleasur",new String(jBase64.decode("YW55IGNhcm5hbCBwbGVhc3Vy", jBase64.ALPHABET.BASE,true)));
        assertEquals("any carnal pleasu",new String(jBase64.decode("YW55IGNhcm5hbCBwbGVhc3U", jBase64.ALPHABET.BASE,true)));
        assertEquals("any carnal pleas",new String(jBase64.decode("YW55IGNhcm5hbCBwbGVhcw", jBase64.ALPHABET.BASE,true)));

        // Normal //
        assertArrayEquals(input_t1,jBase64.decode(jBase64.encode(input_t1, jBase64.ALPHABET.BASE), jBase64.ALPHABET.BASE,true));
        assertArrayEquals(input_t2,jBase64.decode(jBase64.encode(input_t2, jBase64.ALPHABET.BASE), jBase64.ALPHABET.BASE,true));
        assertArrayEquals(input_t2,jBase64.decode(jBase64.encode(input_t2, jBase64.ALPHABET.BASE), jBase64.ALPHABET.BASE,true));

        // Safe //
        assertArrayEquals(input_t1,jBase64.decode(jBase64.encode(input_t1, jBase64.ALPHABET.SAFE), jBase64.ALPHABET.SAFE,true));
        assertArrayEquals(input_t2,jBase64.decode(jBase64.encode(input_t2, jBase64.ALPHABET.SAFE), jBase64.ALPHABET.SAFE,true));
        assertArrayEquals(input_t2,jBase64.decode(jBase64.encode(input_t2, jBase64.ALPHABET.SAFE), jBase64.ALPHABET.SAFE,true));

        // Exception expect //
        try { jBase64.decode("", jBase64.ALPHABET.BASE, true); }
        catch (IllegalArgumentException ex){ /* OK */}

        try { jBase64.decode(null, jBase64.ALPHABET.BASE, true); }
        catch (NullPointerException ex){ /* OK */}

        // Wrong padding //
        try { jBase64.decode("YW55IGNhcm5hbCBwbGVhcw=x", jBase64.ALPHABET.BASE, true); }
        catch (IllegalArgumentException ex){ /* OK */}

        try { jBase64.decode("YW55IGNhcm5hbCBwbGVhcw=x", jBase64.ALPHABET.BASE, true); }
        catch (IllegalArgumentException ex){ /* OK */}

    }
}
@@ -224,16 +224,18 @@
 ssert%7B%0A%0A
+//
     priv
@@ -255,32 +255,34 @@
 nput_t1 = null;%0A
+//
     private byte
@@ -302,16 +302,18 @@
 = null;%0A
+//
     priv
@@ -333,34 +333,32 @@
 nput_t3 = null;%0A
-//
     private stat
@@ -392,19 +392,16 @@
 yte%5B
-1024
+255
 +0%5D;%0A
-//
     
@@ -447,19 +447,16 @@
 yte%5B
-1024
+255
 +1%5D;%0A
-//
     
@@ -502,12 +502,11 @@
 yte%5B
-1024
+255
 +2%5D;
@@ -581,18 +581,16 @@
 dom();%0A%0A
-//
         
@@ -614,18 +614,16 @@
 ut_t1);%0A
-//
         
@@ -647,18 +647,16 @@
 ut_t2);%0A
-//
         
@@ -694,36 +694,24 @@
 %0A%0A    @Test%0A
-    @Ignore%0A
     public v

Update JUnit test, bug fix for Travis. v4