From 4eb4f60cf9d36fcdbd88401a35cfcaefc90292ce Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Oct 2026 12:16:33 -0600 Subject: [PATCH] Standardize handshake test package --- AGENTS.md | 6 +++ .../tests/net/VoteForwarderHandshakeTest.java | 52 +++++++++++++++++++ .../net/VoteForwarderHandshakeTest.java | 35 ------------- 3 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 VotifierPlus/src/test/java/com/bencodez/votifierplus/tests/net/VoteForwarderHandshakeTest.java delete mode 100644 VotifierPlus/src/test/java/com/vexsoftware/votifier/net/VoteForwarderHandshakeTest.java diff --git a/AGENTS.md b/AGENTS.md index c7a16e2..e3ecc43 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -17,6 +17,12 @@ mvn -B -f VotifierPlus/pom.xml package Confirm current CI/POM settings. Use `package`, not developer/install profiles that copy artifacts to a server. Verify the fresh shaded JAR, actual test discovery, and `git diff --check`. +## Test package organization + +Put Java test classes and reusable test helpers under `com.bencodez.votifierplus.tests`, using subpackages for related areas. Match the directories below `src/test/java` to the declared package. Keep new and moved tests in this namespace and update imports, resource lookups, reflection references, and build selectors when relocating them. + +Preserve every existing test assertion and test discovery. Use a narrow test-only access helper when testing package-private implementation details; do not widen production APIs merely to move a test. Before finishing, verify the package declarations and run the required test/package build so the reorganization cannot silently drop coverage. + ## Architecture and trust boundaries - Bukkit entry point: `com.vexsoftware.votifier.VotifierPlus`. diff --git a/VotifierPlus/src/test/java/com/bencodez/votifierplus/tests/net/VoteForwarderHandshakeTest.java b/VotifierPlus/src/test/java/com/bencodez/votifierplus/tests/net/VoteForwarderHandshakeTest.java new file mode 100644 index 0000000..e7f4d4f --- /dev/null +++ b/VotifierPlus/src/test/java/com/bencodez/votifierplus/tests/net/VoteForwarderHandshakeTest.java @@ -0,0 +1,52 @@ +package com.bencodez.votifierplus.tests.net; + +import com.vexsoftware.votifier.net.VoteForwarder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.BufferedReader; +import java.io.StringReader; + +import org.junit.jupiter.api.Test; + +public class VoteForwarderHandshakeTest { + // Keep the production parser package-private while exercising the same method. + private static String readHandshakeLine(BufferedReader input) throws Exception { + Method parser = VoteForwarder.class.getDeclaredMethod("readHandshakeLine", BufferedReader.class); + parser.setAccessible(true); + try { + return (String) parser.invoke(null, input); + } catch (InvocationTargetException failure) { + if (failure.getCause() instanceof Exception cause) throw cause; + if (failure.getCause() instanceof Error cause) throw cause; + throw new AssertionError(failure.getCause()); + } + } + + @Test + public void crlfConsumesBothTerminatorBytesAndPreservesFollowingData() throws Exception { + BufferedReader input = new BufferedReader(new StringReader("VOTIFIER 2 challenge\r\nPAYLOAD\n")); + assertEquals("VOTIFIER 2 challenge", readHandshakeLine(input)); + assertEquals("PAYLOAD", input.readLine()); + } + + @Test + public void lfAndBareCrPreserveFollowingData() throws Exception { + BufferedReader lf = new BufferedReader(new StringReader("VOTIFIER 2 challenge\nPAYLOAD\n")); + assertEquals("VOTIFIER 2 challenge", readHandshakeLine(lf)); + assertEquals("PAYLOAD", lf.readLine()); + + BufferedReader cr = new BufferedReader(new StringReader("VOTIFIER 2 challenge\rPAYLOAD\n")); + assertEquals("VOTIFIER 2 challenge", readHandshakeLine(cr)); + assertEquals("PAYLOAD", cr.readLine()); + } + + @Test + public void oversizedHandshakeIsStillRejected() { + BufferedReader input = new BufferedReader(new StringReader("X".repeat(513) + "\r\n")); + assertThrows(IllegalStateException.class, () -> readHandshakeLine(input)); + } +} diff --git a/VotifierPlus/src/test/java/com/vexsoftware/votifier/net/VoteForwarderHandshakeTest.java b/VotifierPlus/src/test/java/com/vexsoftware/votifier/net/VoteForwarderHandshakeTest.java deleted file mode 100644 index e2b2d57..0000000 --- a/VotifierPlus/src/test/java/com/vexsoftware/votifier/net/VoteForwarderHandshakeTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.vexsoftware.votifier.net; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.io.BufferedReader; -import java.io.StringReader; - -import org.junit.jupiter.api.Test; - -public class VoteForwarderHandshakeTest { - @Test - public void crlfConsumesBothTerminatorBytesAndPreservesFollowingData() throws Exception { - BufferedReader input = new BufferedReader(new StringReader("VOTIFIER 2 challenge\r\nPAYLOAD\n")); - assertEquals("VOTIFIER 2 challenge", VoteForwarder.readHandshakeLine(input)); - assertEquals("PAYLOAD", input.readLine()); - } - - @Test - public void lfAndBareCrPreserveFollowingData() throws Exception { - BufferedReader lf = new BufferedReader(new StringReader("VOTIFIER 2 challenge\nPAYLOAD\n")); - assertEquals("VOTIFIER 2 challenge", VoteForwarder.readHandshakeLine(lf)); - assertEquals("PAYLOAD", lf.readLine()); - - BufferedReader cr = new BufferedReader(new StringReader("VOTIFIER 2 challenge\rPAYLOAD\n")); - assertEquals("VOTIFIER 2 challenge", VoteForwarder.readHandshakeLine(cr)); - assertEquals("PAYLOAD", cr.readLine()); - } - - @Test - public void oversizedHandshakeIsStillRejected() { - BufferedReader input = new BufferedReader(new StringReader("X".repeat(513) + "\r\n")); - assertThrows(IllegalStateException.class, () -> VoteForwarder.readHandshakeLine(input)); - } -}