From 61c5eb2962f3d6ffb9bf432dd7997afb95924c1d Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 19 Jan 2023 18:10:31 +0100 Subject: [PATCH] Add javadoc to JUtils --- .../src/test/java/sop/external/JUtils.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/external-sop/src/test/java/sop/external/JUtils.java b/external-sop/src/test/java/sop/external/JUtils.java index d0d1601..38a5829 100644 --- a/external-sop/src/test/java/sop/external/JUtils.java +++ b/external-sop/src/test/java/sop/external/JUtils.java @@ -12,10 +12,25 @@ import static org.junit.jupiter.api.Assertions.fail; public class JUtils { + /** + * Return true, if the given
array
starts with
start
. + * + * @param array array + * @param start start + * @return true if array starts with start, false otherwise + */ public static boolean arrayStartsWith(byte[] array, byte[] start) { return arrayStartsWith(array, start, 0); } + /** + * Return true, if the given
array
contains the given
start
at offset
offset
. + * + * @param array array + * @param start start + * @param offset offset + * @return true, if array contains start at offset, false otherwise + */ public static boolean arrayStartsWith(byte[] array, byte[] start, int offset) { if (offset < 0) { throw new IllegalArgumentException("Offset cannot be negative"); @@ -33,6 +48,12 @@ public class JUtils { return true; } + /** + * Assert that the given
array
starts with
start
. + * + * @param array array + * @param start start + */ public static void assertArrayStartsWith(byte[] array, byte[] start) { if (!arrayStartsWith(array, start)) { byte[] actual = new byte[Math.min(start.length, array.length)]; @@ -43,6 +64,13 @@ public class JUtils { } } + /** + * Assert that the given
array
contains
start
at
offset
. + * + * @param array array + * @param start start + * @param offset offset + */ public static void assertArrayStartsWith(byte[] array, byte[] start, int offset) { if (!arrayStartsWith(array, start, offset)) { byte[] actual = new byte[Math.min(start.length, array.length - offset)]; @@ -53,6 +81,12 @@ public class JUtils { } } + /** + * Assert equality of the given two ascii armored byte arrays, ignoring armor header lines. + * + * @param first first ascii armored bytes + * @param second second ascii armored bytes + */ public static void assertAsciiArmorEquals(byte[] first, byte[] second) { byte[] firstCleaned = removeArmorHeaders(first); byte[] secondCleaned = removeArmorHeaders(second); @@ -60,6 +94,13 @@ public class JUtils { assertArrayEquals(firstCleaned, secondCleaned); } + /** + * Remove armor headers "Comment:", "Version:", "MessageID:", "Hash:" and "Charset:" along with their values + * from the given ascii armored byte array. + * + * @param armor ascii armored byte array + * @return ascii armored byte array with header lines removed + */ public static byte[] removeArmorHeaders(byte[] armor) { String string = new String(armor, StandardCharsets.UTF_8); string = string.replaceAll("Comment: .+\\R", "")