ruthst00 commented on code in PR #6772:
URL: https://github.com/apache/jmeter/pull/6772#discussion_r4110675766


##########
src/components/src/test/java/org/apache/jmeter/extractor/TestBoundaryExtractor.java:
##########
@@ -108,4 +110,65 @@ public void testOnlyRightBoundary() {
         assertEquals("on", vars.get("varname_1"), "First match is incorrect");
         assertEquals("1", vars.get("varname_matchNr"), "MatchNumber is 
incorrect");
     }
+
+    /**
+     * matchNumber=0 means random: when there is exactly one match the result
+     * must equal that match (no ambiguity about which one is chosen).
+     */
+    @Test
+    public void testMatchNumberZeroRandomSingleMatch() {
+        vars.put("content", "left-VALUE-right");
+        extractor.setLeftBoundary("left-");
+        extractor.setRightBoundary("-right");
+        extractor.setMatchNumber(0);
+        extractor.setRefName("varname");
+        extractor.setScopeVariable("content");
+        extractor.setThreadContext(jmctx);
+        extractor.process();
+        assertEquals("VALUE", vars.get("varname"),
+                "matchNumber=0 (random) with a single match should return that 
match");
+        assertNull(vars.get("varname_matchNr"),
+                "matchNr variable should not be set for matchNumber=0");
+    }
+
+    /**
+     * matchNumber=0 means random: when there are multiple matches the result
+     * must be one of the available matches.
+     */
+    @Test
+    public void testMatchNumberZeroRandomMultipleMatches() {
+        vars.put("content", "left-A-right left-B-right left-C-right");
+        extractor.setLeftBoundary("left-");
+        extractor.setRightBoundary("-right");
+        extractor.setMatchNumber(0);
+        extractor.setRefName("varname");
+        extractor.setScopeVariable("content");
+        extractor.setThreadContext(jmctx);
+        extractor.process();
+        String found = vars.get("varname");
+        assertNotNull(found, "matchNumber=0 (random) should return a non-null 
result when matches exist");
+        assertTrue("A".equals(found) || "B".equals(found) || "C".equals(found),
+                "matchNumber=0 (random) result '" + found + "' should be one 
of the available matches");
+        assertNull(vars.get("varname_matchNr"),
+                "matchNr variable should not be set for matchNumber=0");
+    }
+
+    /**
+     * An empty Match No. field is stored as "" which resolves to 0 via

Review Comment:
   Fixed



##########
src/components/src/test/java/org/apache/jmeter/extractor/TestBoundaryExtractor.java:
##########
@@ -108,4 +110,65 @@ public void testOnlyRightBoundary() {
         assertEquals("on", vars.get("varname_1"), "First match is incorrect");
         assertEquals("1", vars.get("varname_matchNr"), "MatchNumber is 
incorrect");
     }
+
+    /**
+     * matchNumber=0 means random: when there is exactly one match the result
+     * must equal that match (no ambiguity about which one is chosen).
+     */
+    @Test
+    public void testMatchNumberZeroRandomSingleMatch() {
+        vars.put("content", "left-VALUE-right");
+        extractor.setLeftBoundary("left-");
+        extractor.setRightBoundary("-right");
+        extractor.setMatchNumber(0);
+        extractor.setRefName("varname");
+        extractor.setScopeVariable("content");
+        extractor.setThreadContext(jmctx);
+        extractor.process();
+        assertEquals("VALUE", vars.get("varname"),
+                "matchNumber=0 (random) with a single match should return that 
match");
+        assertNull(vars.get("varname_matchNr"),
+                "matchNr variable should not be set for matchNumber=0");
+    }
+
+    /**
+     * matchNumber=0 means random: when there are multiple matches the result
+     * must be one of the available matches.
+     */
+    @Test
+    public void testMatchNumberZeroRandomMultipleMatches() {
+        vars.put("content", "left-A-right left-B-right left-C-right");
+        extractor.setLeftBoundary("left-");
+        extractor.setRightBoundary("-right");
+        extractor.setMatchNumber(0);
+        extractor.setRefName("varname");
+        extractor.setScopeVariable("content");
+        extractor.setThreadContext(jmctx);
+        extractor.process();
+        String found = vars.get("varname");
+        assertNotNull(found, "matchNumber=0 (random) should return a non-null 
result when matches exist");
+        assertTrue("A".equals(found) || "B".equals(found) || "C".equals(found),
+                "matchNumber=0 (random) result '" + found + "' should be one 
of the available matches");
+        assertNull(vars.get("varname_matchNr"),
+                "matchNr variable should not be set for matchNumber=0");
+    }
+
+    /**
+     * An empty Match No. field is stored as "" which resolves to 0 via
+     * getIntValue(), so it must behave identically to matchNumber=0 (random).
+     */
+    @Test
+    public void testEmptyMatchNumberFieldBehavesLikeZero() {

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to