From: David ‘Bombe’ Roden Date: Sun, 26 May 2024 10:50:35 +0000 (+0200) Subject: ✅ Add test for Freenet-specific Base64 implementation X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=0c7165b5bcbf6914802d465ffa8b7fde5ca61d5d;p=jFCPlib.git ✅ Add test for Freenet-specific Base64 implementation --- diff --git a/src/test/java/net/pterodactylus/fcp/FreenetBase64Test.java b/src/test/java/net/pterodactylus/fcp/FreenetBase64Test.java new file mode 100644 index 0000000..4033aed --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/FreenetBase64Test.java @@ -0,0 +1,45 @@ +package net.pterodactylus.fcp; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Arrays.asList; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import java.util.List; + +import org.junit.Test; + +/** + * Unit test for {@link FreenetBase64Test}. + */ +public class FreenetBase64Test { + + @Test + public void testEncodingVectorsFromRfc4648() { + getRfc4648TestVectors().forEach(vector -> assertThat(encoder.encode(vector[0].getBytes(UTF_8)), equalTo(vector[1]))); + } + + @Test + public void testDecodingVectorsFromRfc4648() { + getRfc4648TestVectors().forEach(vector -> assertThat(encoder.decode(vector[1]), equalTo(vector[0].getBytes(UTF_8)))); + } + + private static List getRfc4648TestVectors() { + return asList( + vector("", ""), + vector("f", "Zg=="), + vector("fo", "Zm8="), + vector("foo", "Zm9v"), + vector("foob", "Zm9vYg=="), + vector("fooba", "Zm9vYmE="), + vector("foobar", "Zm9vYmFy") + ); + } + + private static String[] vector(String plain, String encoded) { + return new String[] { plain, encoded }; + } + + private final FreenetBase64 encoder = new FreenetBase64(); + +}