From 8ce08919d6ffdc5ddaa831c6dba8d26442617219 Mon Sep 17 00:00:00 2001 From: David Hook Date: Wed, 1 May 2024 12:32:05 +1000 Subject: [PATCH] minor reorg of test classes - relates to github #1634 --- ant/bc+-build.xml | 5 ++- .../bcpg/test/AbstractPacketTest.java | 10 +++--- .../bcpg/test/PacketDumpUtil.java | 35 +++++++++++++++++++ .../HexDumpUtil.java => test/DumpUtil.java} | 33 ++--------------- 4 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 pg/src/test/java/org/bouncycastle/bcpg/test/PacketDumpUtil.java rename pg/src/test/java/org/bouncycastle/{bcpg/HexDumpUtil.java => test/DumpUtil.java} (64%) diff --git a/ant/bc+-build.xml b/ant/bc+-build.xml index 8b6f7364d8..ee907cb747 100644 --- a/ant/bc+-build.xml +++ b/ant/bc+-build.xml @@ -860,7 +860,10 @@ - + + + + diff --git a/pg/src/test/java/org/bouncycastle/bcpg/test/AbstractPacketTest.java b/pg/src/test/java/org/bouncycastle/bcpg/test/AbstractPacketTest.java index 2e89f71ef4..ca4b36710d 100644 --- a/pg/src/test/java/org/bouncycastle/bcpg/test/AbstractPacketTest.java +++ b/pg/src/test/java/org/bouncycastle/bcpg/test/AbstractPacketTest.java @@ -1,7 +1,7 @@ package org.bouncycastle.bcpg.test; import org.bouncycastle.bcpg.ContainedPacket; -import org.bouncycastle.bcpg.HexDumpUtil; +import org.bouncycastle.test.DumpUtil; import org.bouncycastle.util.Arrays; import org.bouncycastle.util.test.SimpleTest; @@ -36,8 +36,8 @@ public void isEncodingEqual(String message, byte[] first, byte[] second) { sb.append(message).append("\n"); } - sb.append("Expected: \n").append(HexDumpUtil.hexdump(first)).append("\n"); - sb.append("Got: \n").append(HexDumpUtil.hexdump(second)); + sb.append("Expected: \n").append(DumpUtil.hexdump(first)).append("\n"); + sb.append("Got: \n").append(DumpUtil.hexdump(second)); isTrue(sb.toString(), first == second || Arrays.areEqual(first, second)); } @@ -69,8 +69,8 @@ public void isEncodingEqual(String message, ContainedPacket first, ContainedPack { sb.append(message).append("\n"); } - sb.append("Expected: \n").append(HexDumpUtil.hexdump(first)).append("\n"); - sb.append("Got: \n").append(HexDumpUtil.hexdump(second)); + sb.append("Expected: \n").append(PacketDumpUtil.hexdump(first)).append("\n"); + sb.append("Got: \n").append(PacketDumpUtil.hexdump(second)); isTrue(sb.toString(), first == second || Arrays.areEqual(first.getEncoded(), second.getEncoded())); } diff --git a/pg/src/test/java/org/bouncycastle/bcpg/test/PacketDumpUtil.java b/pg/src/test/java/org/bouncycastle/bcpg/test/PacketDumpUtil.java new file mode 100644 index 0000000000..e4c16364ff --- /dev/null +++ b/pg/src/test/java/org/bouncycastle/bcpg/test/PacketDumpUtil.java @@ -0,0 +1,35 @@ +package org.bouncycastle.bcpg.test; + +import java.io.IOException; + +import org.bouncycastle.bcpg.ContainedPacket; +import org.bouncycastle.test.DumpUtil; + +public class PacketDumpUtil +{ + /** + * Return a formatted hex dump of the packet encoding of the given packet. + * @param packet packet + * @return formatted hex dump + * @throws IOException if an exception happens during packet encoding + */ + public static String hexdump(ContainedPacket packet) + throws IOException + { + return DumpUtil.hexdump(packet.getEncoded()); + } + + /** + * Return a formatted hex dump of the packet encoding of the given packet. + * If startIndent is non-zero, the hex dump is shifted right by the startIndent octets. + * @param startIndent shift the encodings octet stream by a number of bytes + * @param packet packet + * @return formatted hex dump + * @throws IOException if an exception happens during packet encoding + */ + public static String hexdump(int startIndent, ContainedPacket packet) + throws IOException + { + return DumpUtil.hexdump(startIndent, packet.getEncoded()); + } +} diff --git a/pg/src/test/java/org/bouncycastle/bcpg/HexDumpUtil.java b/pg/src/test/java/org/bouncycastle/test/DumpUtil.java similarity index 64% rename from pg/src/test/java/org/bouncycastle/bcpg/HexDumpUtil.java rename to pg/src/test/java/org/bouncycastle/test/DumpUtil.java index 62d70b43a1..88f7138dfc 100644 --- a/pg/src/test/java/org/bouncycastle/bcpg/HexDumpUtil.java +++ b/pg/src/test/java/org/bouncycastle/test/DumpUtil.java @@ -1,12 +1,9 @@ -package org.bouncycastle.bcpg; +package org.bouncycastle.test; import org.bouncycastle.util.encoders.Hex; -import java.io.IOException; - -public class HexDumpUtil +public class DumpUtil { - /** * Return a formatted hex dump of the given byte array. * @param array byte array @@ -65,30 +62,4 @@ public static String hexdump(int startIndent, byte[] array) } return out.toString(); } - - /** - * Return a formatted hex dump of the packet encoding of the given packet. - * @param packet packet - * @return formatted hex dump - * @throws IOException if an exception happens during packet encoding - */ - public static String hexdump(ContainedPacket packet) - throws IOException - { - return hexdump(packet.getEncoded()); - } - - /** - * Return a formatted hex dump of the packet encoding of the given packet. - * If startIndent is non-zero, the hex dump is shifted right by the startIndent octets. - * @param startIndent shift the encodings octet stream by a number of bytes - * @param packet packet - * @return formatted hex dump - * @throws IOException if an exception happens during packet encoding - */ - public static String hexdump(int startIndent, ContainedPacket packet) - throws IOException - { - return hexdump(startIndent, packet.getEncoded()); - } }