import org.junit.Test;
import java.util.Base64;
import org.junit.Assert.*;
import java.util.Random;
...
@Test
public void testEncoding(){
byte[] data = new byte[32];
new Random().nextBytes(data);
String base64 = Base64.getEncoder().encodeToString(data);
assertEquals(data, Base64.getDecoder().decode(base64));
}
@Test
public void testDecoding(){
String base64 = "ABCDEFGHIJKLRMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/A==";
byte[] data = Base64.getDecoder().decode(base64);
assertEquals(base64, Base64.getEncoder().encodeToString(data));
}
The testEncoding test fails with an AssertionError: Expected :[B@6bf2d08e Actual :[B@5eb5c224 And I can't see why.