package com.ft.membership.crypto.signature;

import org.junit.Assert;
import org.junit.Test;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class EncoderTest {

    @Test
    public void testGetBase64EncodedString() throws Exception {

        String testString = "foo";
        byte[] encodedBytes = Base64.getUrlEncoder().withoutPadding().encode(testString.getBytes());
        String expectedEncodedString = new String(encodedBytes, StandardCharsets.UTF_8);
        String actualEncodedString  = Encoder.getBase64EncodedString(testString.getBytes());

        Assert.assertEquals(expectedEncodedString, actualEncodedString);
    }

    @Test
    public void testGetBase64DecodedBytes() throws Exception {

        String testString = "foo";
        byte[] encodedBytes = Base64.getUrlEncoder().withoutPadding().encode(testString.getBytes());
        String encodedString = new String(encodedBytes, StandardCharsets.UTF_8);
        byte[] expectedDecodedBytes = Base64.getUrlDecoder().decode(encodedBytes);
        byte[] actualDecodedBytes = Encoder.getBase64DecodedBytes(encodedString).get();

        Assert.assertArrayEquals(expectedDecodedBytes, actualDecodedBytes);
    }

    @Test
    public void testEncodeThenDecode() throws Exception {

        String testString = "foo";
        String encodedString = Encoder.getBase64EncodedString(testString.getBytes());
        byte[] decodedBytes = Encoder.getBase64DecodedBytes(encodedString).get();

        Assert.assertEquals(testString, new String(decodedBytes, StandardCharsets.UTF_8));
    }
}
@@ -153,16 +153,51 @@
 .Base64;
+%0Aimport java.util.stream.IntStream;
 %0A%0Apublic
@@ -1608,9 +1608,1144 @@
 ;%0A    %7D%0A
+%0A    @Test%0A    public void testEncodingAndDecodingOfStringWithLatinChars() throws Exception %7B%0A%0A        String testString = %22%C3%AAfoo%C3%B1bar%22;%0A        String encodedString = Encoder.getBase64EncodedString(testString.getBytes());%0A        byte%5B%5D decodedBytes = Encoder.getBase64DecodedBytes(encodedString).get();%0A%0A        Assert.assertEquals(testString, new String(decodedBytes, StandardCharsets.UTF_8));%0A    %7D%0A%0A    @Test%0A    public void testEncodingAndDecodingOfAREALLLLLLLYYYYYYLOOOOOONGString() throws Exception %7B%0A%0A        StringBuilder stringBuilder = new StringBuilder();%0A%0A        IntStream.iterate(0, i -%3E i + 2)%0A                .limit(10000)%0A                .forEach(number -%3E %7B%0A                    char%5B%5D ch = Character.toChars(number);%0A                    stringBuilder.append(new String(ch));%0A                %7D);%0A%0A        String testString = stringBuilder.toString();%0A        String encodedString = Encoder.getBase64EncodedString(testString.getBytes());%0A        byte%5B%5D decodedBytes = Encoder.getBase64DecodedBytes(encodedString).get();%0A%0A        Assert.assertEquals(testString, new String(decodedBytes, StandardCharsets.UTF_8));%0A    %7D%0A%0A
 %7D

Add tests for string with special chars