You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2022/04/18 15:41:39 UTC

[jmeter] branch master updated (d8a6876169 -> 89f4a76c61)

This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


    from d8a6876169 Specify the char encoding when decoding bytes into strings
     new ab461ecd4b Correct mail address in changes.xml
     new 1e93c67a59 Get rid of error prone warnings because of missing explicit default character encoding
     new fb6322030f Make error prone happy by re-throwing catched exception
     new a91c28d82b Make error prone happier by using static inner class
     new b351b6df75 Silence warning about mutable enums
     new 1527a8fcb1 Get rid of warning about converting long to float
     new 32b03e9334 Remove unused variable
     new d27bc1fb17 Suppress warning about comparing references
     new cf4ae32816 Use ArrayList instead of LinkedList
     new 9fb66c4ab0 Use newer time API to make error prone happy
     new ee2353ed1c Add override annotations to make error prone happy
     new 16340ba1b8 Suppress warning about calling wait without a loop
     new 522b86aa89 Suppress warnings about old date API
     new bcb2f2261c Suppress diverse warnings in test code
     new 14ab8da63b Silence warnings in test code and use correct parameter when calling chained constructor
     new 89f4a76c61 Updated a few dependencies

The 16 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 checksum.xml                                       |   3 +
 gradle.properties                                  |  26 +-
 .../jmeter/assertions/TestJSONPathAssertion.java   |  40 +--
 .../jmeter/assertions/XMLSchemaAssertionTest.java  |  31 ++-
 .../apache/jmeter/control/TestIfController.java    |  51 ++--
 .../jmeter/control/TestTransactionController.java  |  12 +-
 .../jmeter/extractor/TestJSONPostProcessor.java    |   3 +-
 .../json/jmespath/TestJMESPathExtractor.java       |   3 +-
 .../jmeter/timers/ConstantThroughputTimerTest.java |  91 ++++---
 .../PreciseThroughputTimerTest.java                |   3 -
 .../test/java/org/apache/jmeter/JMeterTest.java    |  11 +-
 .../jmeter/engine/DistributedRunnerTest.java       |   5 +-
 .../org/apache/jmeter/engine/TestTreeCloner.java   |   1 +
 .../gui/logging/TestGuiLogEventAppender.java       |   7 +-
 .../apache/jmeter/junit/JMeterTestCaseJUnit.java   |   4 +-
 .../org/apache/jmeter/resources/PackageTest.java   |  26 +-
 .../jmeter/resources/ResourceKeyUsageTest.java     |   6 +-
 .../samplers/TestDataStrippingSampleSender.java    |   2 +-
 .../apache/jmeter/samplers/TestSampleResult.java   | 160 ++++++------
 .../apache/jmeter/threads/TestJMeterThread.java    |   6 +-
 .../jmeter/util/LogRecordingDelegatingLogger.java  |   4 +-
 .../java/org/apache/jmeter/junit/JMeterTest.java   |   4 +-
 .../org/apache/jmeter/save/TestSaveService.java    |  10 +-
 src/dist/src/dist/expected_release_jars.csv        |  34 +--
 .../org/apache/jmeter/functions/PackageTest.java   |  25 +-
 .../apache/jmeter/functions/SplitFunctionTest.java |   4 +-
 .../apache/jmeter/functions/SumFunctionTest.java   |  20 +-
 .../org/apache/jmeter/functions/Synchronizer.java  |   1 +
 .../apache/jmeter/functions/TestChangeCase.java    |   4 +-
 .../functions/TestDateTimeConvertFunction.java     |  36 +--
 .../jmeter/functions/TestDigestFunction.java       |  34 +--
 .../jmeter/functions/TestEscapeOroRegexpChars.java |  33 ++-
 .../apache/jmeter/functions/TestFileToString.java  |   4 +-
 .../jmeter/functions/TestGroovyFunction.java       |   4 +-
 .../apache/jmeter/functions/TestIsPropDefined.java |   4 +-
 .../apache/jmeter/functions/TestIsVarDefined.java  |  14 +-
 .../jmeter/functions/TestJavascriptFunction.java   |  32 +--
 .../functions/TestJavascriptFunctionWithRhino.java |   2 +
 .../apache/jmeter/functions/TestJexl2Function.java |  35 ++-
 .../apache/jmeter/functions/TestMachineIPName.java |  19 +-
 .../functions/TestRandomFromMultipleVars.java      |  24 +-
 .../apache/jmeter/functions/TestRegexFunction.java | 288 +++++++++++----------
 .../jmeter/functions/TestSamplerNameFunction.java  |  19 +-
 .../apache/jmeter/functions/TestSetProperty.java   |   4 +-
 .../jmeter/functions/TestSimpleFunctions.java      |  25 +-
 .../apache/jmeter/functions/TestTimeFunction.java  |  80 +++---
 .../functions/TestTimeRandomDateFunction.java      |  46 ++--
 .../jmeter/functions/TestTimeShiftFunction.java    |  20 +-
 .../jmeter/functions/TestUrlEncodeDecode.java      |  19 +-
 .../org/apache/jorphan/util/TestConverter.java     |   4 +-
 .../protocol/http/control/TestAuthManager.java     |  12 +-
 .../http/control/TestCacheManagerBase.java         |  44 ++--
 .../control/TestCacheManagerThreadIteration.java   |  29 ++-
 .../protocol/http/parser/TestHTMLParser.java       |  16 +-
 .../protocol/http/proxy/NonGuiProxySample.java     |   2 +-
 .../protocol/http/proxy/TestHttpRequestHdr.java    |  23 +-
 .../protocol/http/sampler/PostWriterTest.java      |  22 +-
 .../TestHTTPSamplersAgainstHttpMirrorServer.java   |   7 +-
 .../protocol/http/util/TestHTTPFileArgs.java       |   4 +-
 .../mail/sampler/TestMailReaderSampler.java        |   8 +-
 xdocs/changes.xml                                  |  19 +-
 61 files changed, 777 insertions(+), 752 deletions(-)


[jmeter] 15/16: Silence warnings in test code and use correct parameter when calling chained constructor

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 14ab8da63b820feb66ab1539cdab4976b77ae4e1
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 17:26:38 2022 +0200

    Silence warnings in test code and use correct parameter when calling chained constructor
    
    When chaining the constructor to add a default UA, we lost one parameter (replaced it
    with another). That seems wrong, so I changed it back to the (hopefully) correct one.
    
    While we are here, suppress a few other warnings from error prone, that can't be
    fixed in a quick way. Feel free, to fix them.
---
 .../jmeter/protocol/http/parser/TestHTMLParser.java      | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java
index 1566cbc601..8155eb1796 100644
--- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java
@@ -90,6 +90,7 @@ public class TestHTMLParser extends JMeterTestCaseJUnit implements Describable {
         }
     }
 
+    @SuppressWarnings("ClassCanBeStatic")
     private class TestClass // Can't instantiate
     {
         private TestClass() {
@@ -99,7 +100,7 @@ public class TestHTMLParser extends JMeterTestCaseJUnit implements Describable {
     private static class TestData {
         private String fileName;
 
-        private String baseURL;
+        private String baseUrl;
 
         private String expectedSet;
 
@@ -113,10 +114,9 @@ public class TestHTMLParser extends JMeterTestCaseJUnit implements Describable {
          * @param baseUrl Base URL
          * @param expectedSet Set of expected URLs
          * @param expectedList List of expected URLs
-         * @param userAgent User Agent
          */
         private TestData(String htmlFileName, String baseUrl, String expectedSet, String expectedList) {
-            this(htmlFileName, baseUrl, expectedList, expectedList, DEFAULT_UA);
+            this(htmlFileName, baseUrl, expectedSet, expectedList, DEFAULT_UA);
         }
         /**
          *
@@ -128,7 +128,7 @@ public class TestHTMLParser extends JMeterTestCaseJUnit implements Describable {
          */
         private TestData(String htmlFileName, String baseUrl, String expectedSet, String expectedList, String userAgent) {
             this.fileName = htmlFileName;
-            this.baseURL = baseUrl;
+            this.baseUrl = baseUrl;
             this.expectedSet = expectedSet;
             this.expectedList = expectedList;
             this.userAgent = userAgent;
@@ -359,26 +359,28 @@ public class TestHTMLParser extends JMeterTestCaseJUnit implements Describable {
 
     public void testParserSet() throws Exception {
         HTMLParser p = (HTMLParser) BaseParser.getParser(parserName);
-        filetest(p, TESTS[testNumber].fileName, TESTS[testNumber].baseURL, TESTS[testNumber].expectedSet, null,
+        filetest(p, TESTS[testNumber].fileName, TESTS[testNumber].baseUrl, TESTS[testNumber].expectedSet, null,
                 false, TESTS[testNumber].userAgent);
     }
 
+    @SuppressWarnings("JdkObsolete")
     public void testParserList() throws Exception {
         HTMLParser p = (HTMLParser) BaseParser.getParser(parserName);
-        filetest(p, TESTS[testNumber].fileName, TESTS[testNumber].baseURL, TESTS[testNumber].expectedList,
+        filetest(p, TESTS[testNumber].fileName, TESTS[testNumber].baseUrl, TESTS[testNumber].expectedList,
                 new Vector<URLString>(), true, TESTS[testNumber].userAgent);
     }
 
     public void testSpecificParserList() throws Exception {
         HTMLParser p = (HTMLParser) BaseParser.getParser(parserName);
         filetest(p, SPECIFIC_PARSER_TESTS[testNumber].fileName,
-                SPECIFIC_PARSER_TESTS[testNumber].baseURL,
+                SPECIFIC_PARSER_TESTS[testNumber].baseUrl,
                 SPECIFIC_PARSER_TESTS[testNumber].expectedList,
                 new ArrayList<URLString>(), true,
                 SPECIFIC_PARSER_TESTS[testNumber].userAgent);
     }
 
 
+    @SuppressWarnings("URLEqualsHashCode")
     private static void filetest(HTMLParser p, String file, String url, String resultFile, Collection<URLString> c,
             boolean orderMatters, // Does the order matter?
             String userAgent)


[jmeter] 01/16: Correct mail address in changes.xml

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit ab461ecd4b2b4a432ce3bc6b5f1623c39dec532d
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 17:18:04 2022 +0200

    Correct mail address in changes.xml
---
 xdocs/changes.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index a14681778a..39650534bd 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -217,7 +217,7 @@ however, the profile can't be updated while the test is running.
   <li><pr>692></pr>Fix a few deprecation warnings for Gradle. Contributed by Sampath Kumar Krishnasamy (sampathkumar.krishnasamykuppusamy at aexp.com)</li>
   <li><pr>697></pr>Junit 5 tests to use asserts from Junit 5 API. Contributed by Sampath Kumar Krishnasamy (sampathkumar.krishnasamykuppusamy at aexp.com)</li>
   <li><bug>65983</bug><pr>707</pr>Use current screenshot for save-to-file listener in documentation. Based on patch by NaveenKumar Namachivayam (catch.nkn at gmail.com)</li>
-  <li><pr>708</pr>Make errorprone happier. Based on patch by Wilson Kurniawan (wilson at visenze.comr)></li>
+  <li><pr>708</pr>Make errorprone happier. Based on patch by Wilson Kurniawan (wilson at visenze.com)></li>
 </ul>
 
  <!-- =================== Bug fixes =================== -->


[jmeter] 05/16: Silence warning about mutable enums

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit b351b6df75b49605013f2fdabb8f52faf727f71f
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 16:36:36 2022 +0200

    Silence warning about mutable enums
    
    We are probably not using the enum as a pattern correctly, but it works
    for us now. Might be worth to look further into this.
---
 .../test/java/org/apache/jmeter/extractor/TestJSONPostProcessor.java   | 3 ++-
 .../apache/jmeter/extractor/json/jmespath/TestJMESPathExtractor.java   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/components/src/test/java/org/apache/jmeter/extractor/TestJSONPostProcessor.java b/src/components/src/test/java/org/apache/jmeter/extractor/TestJSONPostProcessor.java
index 891a849d5c..7705bee083 100644
--- a/src/components/src/test/java/org/apache/jmeter/extractor/TestJSONPostProcessor.java
+++ b/src/components/src/test/java/org/apache/jmeter/extractor/TestJSONPostProcessor.java
@@ -43,12 +43,13 @@ class TestJSONPostProcessor {
 
     private static final String VAR_NAME = "varName";
 
+    @SuppressWarnings("ImmutableEnumChecker")
     private enum AccessMode {
         ALL(AbstractScopedTestElement::setScopeAll),
         PARENT(AbstractScopedTestElement::setScopeParent),
         CHILDREN(AbstractScopedTestElement::setScopeChildren);
 
-        private Consumer<AbstractScopedTestElement> applier;
+        private final Consumer<AbstractScopedTestElement> applier;
 
         AccessMode(Consumer<AbstractScopedTestElement> applier) {
             this.applier = applier;
diff --git a/src/components/src/test/java/org/apache/jmeter/extractor/json/jmespath/TestJMESPathExtractor.java b/src/components/src/test/java/org/apache/jmeter/extractor/json/jmespath/TestJMESPathExtractor.java
index 008f18df19..b10f6e1a5a 100644
--- a/src/components/src/test/java/org/apache/jmeter/extractor/json/jmespath/TestJMESPathExtractor.java
+++ b/src/components/src/test/java/org/apache/jmeter/extractor/json/jmespath/TestJMESPathExtractor.java
@@ -193,7 +193,8 @@ class TestJMESPathExtractor {
         PARENT(AbstractScopedTestElement::setScopeParent),
         CHILDREN(AbstractScopedTestElement::setScopeChildren);
 
-        private Consumer<AbstractScopedTestElement> applier;
+        @SuppressWarnings("ImmutableEnumChecker")
+        private final Consumer<AbstractScopedTestElement> applier;
 
         AccessMode(Consumer<AbstractScopedTestElement> applier) {
             this.applier = applier;


[jmeter] 10/16: Use newer time API to make error prone happy

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 9fb66c4ab00c8198b97f49962f262b46ce877438
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 17:11:15 2022 +0200

    Use newer time API to make error prone happy
---
 .../apache/jmeter/threads/TestJMeterThread.java    |  6 +--
 .../functions/TestTimeRandomDateFunction.java      | 46 +++++++++++-----------
 .../jmeter/functions/TestTimeShiftFunction.java    | 20 +++++-----
 .../http/control/TestCacheManagerBase.java         | 44 +++++++++++----------
 .../control/TestCacheManagerThreadIteration.java   | 29 +++++++-------
 5 files changed, 75 insertions(+), 70 deletions(-)

diff --git a/src/core/src/test/java/org/apache/jmeter/threads/TestJMeterThread.java b/src/core/src/test/java/org/apache/jmeter/threads/TestJMeterThread.java
index 9cbbc3be42..7ad315d949 100644
--- a/src/core/src/test/java/org/apache/jmeter/threads/TestJMeterThread.java
+++ b/src/core/src/test/java/org/apache/jmeter/threads/TestJMeterThread.java
@@ -20,7 +20,7 @@ package org.apache.jmeter.threads;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Date;
+import java.time.Instant;
 
 import org.apache.jmeter.control.LoopController;
 import org.apache.jmeter.samplers.AbstractSampler;
@@ -156,9 +156,9 @@ class TestJMeterThread {
         jMeterThread.setScheduled(true);
         jMeterThread.setEndTime(System.currentTimeMillis() + maxDuration);
         jMeterThread.setThreadGroup(threadGroup);
-        long startTime = new Date().getTime();
+        Instant startTime = Instant.now();
         jMeterThread.run();
-        long duration = new Date().getTime() - startTime;
+        long duration = Instant.now().toEpochMilli() - startTime.toEpochMilli();
 
         assertFalse("Sampler should not be called", dummySampler.isCalled());
 
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeRandomDateFunction.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeRandomDateFunction.java
index b53f7bdf01..b0e99fd660 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeRandomDateFunction.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeRandomDateFunction.java
@@ -21,10 +21,9 @@ import static org.apache.jmeter.functions.FunctionTestHelper.makeParams;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 
 import java.time.LocalDate;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.Collection;
 
@@ -34,6 +33,7 @@ import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -46,7 +46,7 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
     private String value;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         jmctx = JMeterContextService.getContext();
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
@@ -56,12 +56,12 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
     }
 
     @Test
-    public void testParameterCount() throws Exception {
+    void testParameterCount() throws Exception {
         checkInvalidParameterCounts(function, 3, 5);
     }
 
     @Test
-    public void testDefault() throws Exception {
+    void testDefault() throws Exception {
         String endDate = "2099-01-01";
         String formatDate = "yyyy-dd-MM";
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatDate);
@@ -69,22 +69,22 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
         function.setParameters(params);
         value = function.execute(result, null);
         LocalDate result = LocalDate.parse(value, formatter);
-        LocalDate now = LocalDate.now();
+        LocalDate now = LocalDate.now(ZoneId.systemDefault());
         LocalDate max = LocalDate.parse(endDate, formatter);
-        assertTrue(now.isBefore(result) && result.isBefore(max));
+        Assertions.assertTrue(now.isBefore(result) && result.isBefore(max));
     }
 
     @Test
-    public void testDefault2() throws Exception {
+    void testDefault2() throws Exception {
         String endDate = "2099-01-01";
         Collection<CompoundVariable> params = makeParams("yyyy-dd-MM", "", endDate, "", "");
         function.setParameters(params);
         value = function.execute(result, null);
-        assertEquals(10, value.length());
+        Assertions.assertEquals(10, value.length());
     }
 
     @Test
-    public void testFormatDate() throws Exception {
+    void testFormatDate() throws Exception {
         String endDate = "01 01 2099";
         String formatDate = "dd MM yyyy";
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatDate);
@@ -92,23 +92,23 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
         function.setParameters(params);
         value = function.execute(result, null);
         LocalDate result = LocalDate.parse(value, formatter);
-        LocalDate now = LocalDate.now();
+        LocalDate now = LocalDate.now(ZoneId.systemDefault());
         LocalDate max = LocalDate.parse(endDate, formatter);
-        assertTrue(now.isBefore(result) && result.isBefore(max));
+        Assertions.assertTrue(now.isBefore(result) && result.isBefore(max));
     }
 
     @Test
-    public void testFormatDate2() throws Exception {
+    void testFormatDate2() throws Exception {
         String endDate = "01012099";
         String formatDate = "ddMMyyyy";
         Collection<CompoundVariable> params = makeParams(formatDate, "", endDate, "", "");
         function.setParameters(params);
         value = function.execute(result, null);
-        assertEquals(8, value.length());
+        Assertions.assertEquals(8, value.length());
     }
 
     @Test
-    public void testFormatDate3() throws Exception {
+    void testFormatDate3() throws Exception {
         String startDate = "29 Aug 2111";
         String endDate = "30 Aug 2111";
         String formatDate = "dd MMM yyyy";
@@ -120,7 +120,7 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
     }
 
     @Test
-    public void testFrenchFormatDate() throws Exception {
+    void testFrenchFormatDate() throws Exception {
         String startDate = "29 mars 2111";
         String endDate = "30 mars 2111";
         String formatDate = "dd MMM yyyy";
@@ -132,7 +132,7 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
     }
 
     @Test
-    public void testEmptyFormatDate() throws Exception {
+    void testEmptyFormatDate() throws Exception {
         String startDate = "2111-03-29";
         String endDate = "2111-03-30";
         String formatDate = "";
@@ -144,7 +144,7 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
     }
 
     @Test
-    public void testEndDateBeforeStartDate() throws Exception {
+    void testEndDateBeforeStartDate() throws Exception {
         String startDate = "2111-03-29";
         String endDate = "2011-03-30";
         String formatDate = "";
@@ -156,7 +156,7 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
     }
 
     @Test
-    public void testEndDateBeforeStartDateNullVariable() throws Exception {
+    void testEndDateBeforeStartDateNullVariable() throws Exception {
         String startDate = "2111-03-29";
         String endDate = "2111-03-30";
         String formatDate = "";
@@ -168,7 +168,7 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
     }
 
     @Test
-    public void testEndDateBeforeStartDateWithVariable() throws Exception {
+    void testEndDateBeforeStartDateWithVariable() throws Exception {
         String startDate = "2111-03-29";
         String endDate = "2111-03-30";
         String formatDate = "";
@@ -181,7 +181,7 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
     }
 
     @Test
-    public void testInvalidFormat() throws Exception {
+    void testInvalidFormat() throws Exception {
         String startDate = "2111-03-29";
         String endDate = "2011-03-30";
         String formatDate = "abcd";
@@ -193,7 +193,7 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
     }
 
     @Test
-    public void testInvalidStartDateFormat() throws Exception {
+    void testInvalidStartDateFormat() throws Exception {
         String startDate = "23-2111-03";
         String endDate = "2011-03-30";
         String formatDate = "abcd";
@@ -205,7 +205,7 @@ public class TestTimeRandomDateFunction extends JMeterTestCase {
     }
 
     @Test
-    public void testInvalidEndDateFormat() throws Exception {
+    void testInvalidEndDateFormat() throws Exception {
         String startDate = "2011-03-30";
         String endDate = "23-2111-03";
         String formatDate = "abcd";
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeShiftFunction.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeShiftFunction.java
index f3d53da157..a307ed8334 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeShiftFunction.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeShiftFunction.java
@@ -98,7 +98,7 @@ class TestTimeShiftFunction extends JMeterTestCase {
         long resultat = Long.parseLong(value);
         LocalDateTime nowFromFunction = LocalDateTime.ofInstant(Instant.ofEpochMilli(resultat),
                 TimeZone.getDefault().toZoneId());
-        assertThat(nowFromFunction, within(5, ChronoUnit.SECONDS, LocalDateTime.now()));
+        assertThat(nowFromFunction, within(5, ChronoUnit.SECONDS, LocalDateTime.now(ZoneId.systemDefault())));
     }
 
     @Test
@@ -106,7 +106,7 @@ class TestTimeShiftFunction extends JMeterTestCase {
         Collection<CompoundVariable> params = makeParams("yyyy-MM-dd", "", "P1d", "");
         function.setParameters(params);
         value = function.execute(result, null);
-        LocalDate tomorrow = LocalDate.now().plusDays(1);
+        LocalDate tomorrow = LocalDate.now(ZoneId.systemDefault()).plusDays(1);
         LocalDate tomorrowFromFunction = LocalDate.parse(value);
         assertThat(tomorrowFromFunction, sameDay(tomorrow));
     }
@@ -120,16 +120,18 @@ class TestTimeShiftFunction extends JMeterTestCase {
         Collection<CompoundVariable> params = makeParams("yyyy-MM-dd'T'HH:mm:ss", "", "P10DT-1H-5M5S", "");
         function.setParameters(params);
         value = function.execute(result, null);
-        LocalDateTime futureDate = LocalDateTime.now().plusDays(10).plusHours(-1).plusMinutes(-5).plusSeconds(5);
+        LocalDateTime futureDate = LocalDateTime.now(ZoneId.systemDefault())
+                .plusDays(10).plusHours(-1).plusMinutes(-5).plusSeconds(5);
         LocalDateTime futureDateFromFunction = LocalDateTime.parse(value);
         assertThat(futureDateFromFunction, within(1, ChronoUnit.SECONDS, futureDate));
     }
 
-    private BooleanSupplier dstChangeAhead(String duration) {
+    private static BooleanSupplier dstChangeAhead(String duration) {
         return () -> {
             ZoneId defaultZoneId = ZoneId.systemDefault();
-            Instant now = LocalDateTime.now().atZone(defaultZoneId).toInstant();
-            Instant then = LocalDateTime.now().plus(Duration.parse(duration)).atZone(defaultZoneId).toInstant();
+            Instant now = LocalDateTime.now(defaultZoneId).atZone(defaultZoneId).toInstant();
+            Instant then = LocalDateTime.now(defaultZoneId).plus(Duration.parse(duration))
+                    .atZone(defaultZoneId).toInstant();
             ZoneRules rules = defaultZoneId.getRules();
             Duration nowDST = rules.getDaylightSavings(now);
             Duration thenDST = rules.getDaylightSavings(then);
@@ -180,7 +182,7 @@ class TestTimeShiftFunction extends JMeterTestCase {
         long resultat = Long.parseLong(value);
         LocalDateTime nowFromFunction = LocalDateTime.ofInstant(Instant.ofEpochMilli(resultat),
                 TimeZone.getDefault().toZoneId());
-        assertThat(nowFromFunction, within(5, ChronoUnit.SECONDS, LocalDateTime.now()));
+        assertThat(nowFromFunction, within(5, ChronoUnit.SECONDS, LocalDateTime.now(ZoneId.systemDefault())));
     }
 
     @Test
@@ -200,13 +202,13 @@ class TestTimeShiftFunction extends JMeterTestCase {
         function.setParameters(params);
         value = function.execute(result, null);
         LocalDateTime randomFutureDate = LocalDateTime.parse(value);
-        LocalDateTime checkFutureDate = LocalDateTime.now().plusMinutes(randomInt);
+        LocalDateTime checkFutureDate = LocalDateTime.now(ZoneId.systemDefault()).plusMinutes(randomInt);
         assertThat(randomFutureDate, within(5, ChronoUnit.SECONDS, checkFutureDate));
         randomInt = r.ints(1, 60).limit(1).findFirst().getAsInt();
         vars.put("random", String.valueOf(randomInt));
         value = function.execute(result, null);
         randomFutureDate = LocalDateTime.parse(value);
-        checkFutureDate = LocalDateTime.now().plusMinutes(randomInt);
+        checkFutureDate = LocalDateTime.now(ZoneId.systemDefault()).plusMinutes(randomInt);
         assertThat(randomFutureDate, within(5, ChronoUnit.SECONDS, checkFutureDate));
     }
 
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java
index b2e0def17e..e776c2842f 100644
--- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java
@@ -25,11 +25,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.lang.reflect.Field;
 import java.net.URL;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.Locale;
 import java.util.Map;
-import java.util.TimeZone;
 
 import org.apache.jmeter.junit.JMeterTestCase;
 import org.apache.jmeter.protocol.http.control.CacheManager.CacheEntry;
@@ -43,22 +43,23 @@ import org.junit.jupiter.api.parallel.ExecutionMode;
 public abstract class TestCacheManagerBase extends JMeterTestCase {
     protected static final String LOCAL_HOST = "http://localhost/";
     protected static final String EXPECTED_ETAG = "0xCAFEBABEDEADBEEF";
-    protected static final TimeZone GMT = TimeZone.getTimeZone("GMT");
+    protected static final ZoneId GMT = ZoneId.of("GMT");
     protected CacheManager cacheManager;
     protected String currentTimeInGMT;
     protected String vary = null;
     protected URL url;
     protected HTTPSampleResult sampleResultOK;
 
-    protected String makeDate(Date d) {
-        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
-        simpleDateFormat.setTimeZone(GMT);
-        return simpleDateFormat.format(d);
+    protected String makeDate(Instant d) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z")
+                .withLocale(Locale.US)
+                .withZone(GMT);
+        return formatter.format(d);
     }
 
     public void setUp() throws Exception {
         this.cacheManager = new CacheManager();
-        this.currentTimeInGMT = makeDate(new Date());
+        this.currentTimeInGMT = makeDate(Instant.now());
         this.url = new URL(LOCAL_HOST);
 
         this.sampleResultOK = getSampleResultWithSpecifiedResponseCode("200");
@@ -106,7 +107,7 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         this.cacheManager.testIterationStart(null);
         assertNoSuchEntry();
         long start = System.currentTimeMillis();
-        setExpires(makeDate(new Date(start + 2000)));
+        setExpires(makeDate(Instant.ofEpochMilli(start + 2000)));
         cacheResultWithGivenCode("304");
         assertValidEntry();
         sleepTill(start + 2010);
@@ -119,7 +120,7 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         this.cacheManager.testIterationStart(null);
         assertNoSuchEntry();
         long start = System.currentTimeMillis();
-        setExpires(makeDate(new Date(start + 2000)));
+        setExpires(makeDate(Instant.ofEpochMilli(start + 2000)));
         cacheResult(sampleResultOK);
         assertValidEntry();
         sleepTill(start + 2010);
@@ -131,7 +132,7 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         this.cacheManager.setUseExpires(false);
         this.cacheManager.testIterationStart(null);
         assertNoSuchEntry();
-        setExpires(makeDate(new Date(System.currentTimeMillis() + 2000)));
+        setExpires(makeDate(Instant.ofEpochMilli(System.currentTimeMillis() + 2000)));
         cacheResult(sampleResultOK);
         assertInvalidEntry();
     }
@@ -142,7 +143,7 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         this.cacheManager.testIterationStart(null);
         assertNoSuchEntry();
         long start = System.currentTimeMillis();
-        setExpires(makeDate(new Date(start)));
+        setExpires(makeDate(Instant.ofEpochMilli(start)));
         setCacheControl("public, max-age=1");
         cacheResult(sampleResultOK);
         assertValidEntry();
@@ -213,7 +214,7 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         this.cacheManager.testIterationStart(null);
         assertNull(getThreadCacheEntry(LOCAL_HOST), "Should not find entry");
         assertFalse(this.cacheManager.inCache(url, origHeaders), "Should not find valid entry");
-        setExpires(makeDate(new Date(System.currentTimeMillis())));
+        setExpires(makeDate(Instant.ofEpochMilli(System.currentTimeMillis())));
         setCacheControl("public, max-age=5");
         sampleResultOK.setRequestHeaders(asString(origHeaders));
         this.vary = vary;
@@ -230,7 +231,7 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         this.cacheManager.setUseExpires(true);
         this.cacheManager.testIterationStart(null);
         assertNoSuchEntry();
-        setExpires(makeDate(new Date(System.currentTimeMillis())));
+        setExpires(makeDate(Instant.ofEpochMilli(System.currentTimeMillis())));
         setCacheControl("public, max-age=5");
         HTTPSampleResult sampleResultHEAD = getSampleResultWithSpecifiedResponseCode("200");
         sampleResultHEAD.setHTTPMethod("HEAD");
@@ -244,7 +245,7 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         this.cacheManager.testIterationStart(null);
         assertNoSuchEntry();
         long start = System.currentTimeMillis();
-        setExpires(makeDate(new Date(start)));
+        setExpires(makeDate(Instant.ofEpochMilli(start)));
         setCacheControl("private, max-age=1");
         cacheResult(sampleResultOK);
         assertValidEntry();
@@ -264,7 +265,7 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         // be fresh for the next 10% of X seconds == 0.1*X seconds
         long start = System.currentTimeMillis();
         long age = 30 * 1000; // 30 seconds
-        setLastModified(makeDate(new Date(start - age)));
+        setLastModified(makeDate(Instant.ofEpochMilli(start - age)));
         cacheResult(sampleResultOK);
         assertValidEntry();
         sleepTill(start + age / 10 + 1010);
@@ -283,7 +284,7 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         // be fresh for the next 10% of X seconds == 0.1*X seconds
         long start = System.currentTimeMillis();
         long age = 30 * 1000; // 30 seconds
-        setLastModified(makeDate(new Date(start - age)));
+        setLastModified(makeDate(Instant.ofEpochMilli(start - age)));
         cacheResult(sampleResultOK);
         assertValidEntry();
         sleepTill(start + age / 10 + 1010);
@@ -296,7 +297,7 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         this.cacheManager.testIterationStart(null);
         assertNoSuchEntry();
         long start = System.currentTimeMillis();
-        setExpires(makeDate(new Date(start + 2000)));
+        setExpires(makeDate(Instant.ofEpochMilli(start + 2000)));
         setCacheControl("private");
         cacheResult(sampleResultOK);
         assertValidEntry();
@@ -340,7 +341,7 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         this.cacheManager.testIterationStart(null);
         assertNoSuchEntry();
         long start = System.currentTimeMillis();
-        setExpires(makeDate(new Date(start)));
+        setExpires(makeDate(Instant.ofEpochMilli(start)));
         setCacheControl("public, max-age=1, no-transform");
         cacheResult(sampleResultOK);
         assertValidEntry();
@@ -352,7 +353,8 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
     private void assertInvalidEntry() throws Exception {
         CacheEntry cachedEntry = getThreadCacheEntry(LOCAL_HOST);
         assertNotNull(getThreadCacheEntry(LOCAL_HOST), "Should find entry");
-        assertFalse(this.cacheManager.inCache(url), "Should not find valid entry. Found: " + cachedEntry + " at " + System.currentTimeMillis());
+        assertFalse(this.cacheManager.inCache(url),
+                () -> "Should not find valid entry. Found: " + cachedEntry + " at " + System.currentTimeMillis());
     }
 
     @SuppressWarnings("deprecation")
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerThreadIteration.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerThreadIteration.java
index cbf6e6a590..68c260cc9f 100644
--- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerThreadIteration.java
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerThreadIteration.java
@@ -25,13 +25,13 @@ import static org.junit.Assert.assertTrue;
 import java.lang.reflect.Field;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
-import java.util.TimeZone;
 
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
@@ -62,7 +62,7 @@ public class TestCacheManagerThreadIteration {
     private static final String SAME_USER="__jmv_SAME_USER";
     protected static final String LOCAL_HOST = "http://localhost/";
     protected static final String EXPECTED_ETAG = "0xCAFEBABEDEADBEEF";
-    protected static final TimeZone GMT = TimeZone.getTimeZone("GMT");
+    protected static final ZoneId GMT = ZoneId.of("GMT");
     protected CacheManager cacheManager;
     protected String currentTimeInGMT;
     protected String vary = null;
@@ -226,10 +226,11 @@ public class TestCacheManagerThreadIteration {
         }
     }
 
-    protected String makeDate(Date d) {
-        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
-        simpleDateFormat.setTimeZone(GMT);
-        return simpleDateFormat.format(d);
+    protected String makeDate(Instant d) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z")
+                .withLocale(Locale.US)
+                .withZone(GMT);
+        return formatter.format(d);
     }
 
     protected HTTPSampleResult getSampleResultWithSpecifiedResponseCode(String code) {
@@ -246,7 +247,7 @@ public class TestCacheManagerThreadIteration {
     @BeforeEach
     public void setUp() throws Exception {
         this.cacheManager = new CacheManager();
-        this.currentTimeInGMT = makeDate(new Date());
+        this.currentTimeInGMT = makeDate(Instant.now());
         this.url = new URL(LOCAL_HOST);
         this.sampleResultOK = getSampleResultWithSpecifiedResponseCode("200");
         this.httpMethod = new HttpPostStub();
@@ -311,7 +312,7 @@ public class TestCacheManagerThreadIteration {
         Header[] headers = new Header[1];
         assertFalse("Should not find valid entry", this.cacheManager.inCache(url, headers));
         long start = System.currentTimeMillis();
-        setExpires(makeDate(new Date(start)));
+        setExpires(makeDate(Instant.ofEpochMilli(start)));
         setCacheControl("public, max-age=1");
         cacheResult(sampleResultOK);
         assertNotNull("Before iternation, should find entry", getThreadCacheEntry(LOCAL_HOST));
@@ -357,7 +358,7 @@ public class TestCacheManagerThreadIteration {
         Header[] headers = new Header[1];
         assertFalse("Should not find valid entry", this.cacheManager.inCache(url, headers));
         long start = System.currentTimeMillis();
-        setExpires(makeDate(new Date(start)));
+        setExpires(makeDate(Instant.ofEpochMilli(start)));
         setCacheControl("public, max-age=1");
         cacheResult(sampleResultOK);
         this.cacheManager.setThreadContext(jmctx);
@@ -373,7 +374,7 @@ public class TestCacheManagerThreadIteration {
         jmctx.setVariables(jmvars);
         this.cacheManager.setThreadContext(jmctx);
         start = System.currentTimeMillis();
-        setExpires(makeDate(new Date(start)));
+        setExpires(makeDate(Instant.ofEpochMilli(start)));
         setCacheControl("public, max-age=1");
         cacheResult(sampleResultOK);
         assertNotNull("Before iternation, should find entry", getThreadCacheEntry(LOCAL_HOST));
@@ -396,7 +397,7 @@ public class TestCacheManagerThreadIteration {
         Header[] headers = new Header[1];
         assertFalse("Should not find valid entry", this.cacheManager.inCache(url, headers));
         long start = System.currentTimeMillis();
-        setExpires(makeDate(new Date(start)));
+        setExpires(makeDate(Instant.ofEpochMilli(start)));
         setCacheControl("public, max-age=1");
         cacheResult(sampleResultOK);
         this.cacheManager.setThreadContext(jmctx);
@@ -411,7 +412,7 @@ public class TestCacheManagerThreadIteration {
         jmctx.setVariables(jmvars);
         this.cacheManager.setThreadContext(jmctx);
         start = System.currentTimeMillis();
-        setExpires(makeDate(new Date(start)));
+        setExpires(makeDate(Instant.ofEpochMilli(start)));
         setCacheControl("public, max-age=1");
         cacheResult(sampleResultOK);
         assertNotNull("Before iteration, should find entry", getThreadCacheEntry(LOCAL_HOST));


[jmeter] 08/16: Suppress warning about comparing references

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit d27bc1fb17ce7369a03ca0580c9763ae57112d86
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 16:52:50 2022 +0200

    Suppress warning about comparing references
    
    We really want to test for the same reference here.
---
 src/core/src/test/java/org/apache/jmeter/engine/TestTreeCloner.java | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/core/src/test/java/org/apache/jmeter/engine/TestTreeCloner.java b/src/core/src/test/java/org/apache/jmeter/engine/TestTreeCloner.java
index 53ce8e233d..143f5691c1 100644
--- a/src/core/src/test/java/org/apache/jmeter/engine/TestTreeCloner.java
+++ b/src/core/src/test/java/org/apache/jmeter/engine/TestTreeCloner.java
@@ -36,6 +36,7 @@ import org.junit.jupiter.api.Test;
 public class TestTreeCloner extends JMeterTestCase {
 
     @Test
+    @SuppressWarnings("ReferenceEquality")
     public void testCloning() throws Exception {
         ListedHashTree original = new ListedHashTree();
         GenericController controller = new GenericController();


[jmeter] 04/16: Make error prone happier by using static inner class

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit a91c28d82bbf8631c9051830bb5e78336da9266f
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 16:33:26 2022 +0200

    Make error prone happier by using static inner class
    
    While we are here, switch to junit5 methods.
---
 .../org/apache/jmeter/control/TestTransactionController.java | 12 +++++++-----
 .../jmeter/samplers/TestDataStrippingSampleSender.java       |  2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/components/src/test/java/org/apache/jmeter/control/TestTransactionController.java b/src/components/src/test/java/org/apache/jmeter/control/TestTransactionController.java
index f9bcb6f9fc..ac54f06479 100644
--- a/src/components/src/test/java/org/apache/jmeter/control/TestTransactionController.java
+++ b/src/components/src/test/java/org/apache/jmeter/control/TestTransactionController.java
@@ -17,8 +17,6 @@
 
 package org.apache.jmeter.control;
 
-import static org.junit.Assert.assertEquals;
-
 import java.util.ArrayList;
 import java.util.List;
 
@@ -35,6 +33,7 @@ import org.apache.jmeter.threads.ListenerNotifier;
 import org.apache.jmeter.threads.TestCompiler;
 import org.apache.jmeter.threads.ThreadGroup;
 import org.apache.jorphan.collections.ListedHashTree;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
 
@@ -81,11 +80,14 @@ public class TestTransactionController extends JMeterTestCase {
         thread.setOnErrorStopThread(true);
         thread.run();
 
-        assertEquals("Must one transaction samples with parent debug sample", 1, listener.events.size());
-        assertEquals("Number of samples in transaction : 1, number of failing samples : 1", listener.events.get(0).getResult().getResponseMessage());
+        Assertions.assertEquals(1, listener.events.size(),
+                "Must one transaction samples with parent debug sample");
+        Assertions.assertEquals("Number of samples in transaction : 1, number of failing samples : 1",
+                listener.events.get(0).getResult().getResponseMessage());
     }
 
-    public class TestSampleListener extends ResultCollector implements SampleListener {
+    public static class TestSampleListener extends ResultCollector implements SampleListener {
+        private static final long serialVersionUID = -1373192220822942714L;
         public List<SampleEvent> events = new ArrayList<>();
 
         @Override
diff --git a/src/core/src/test/java/org/apache/jmeter/samplers/TestDataStrippingSampleSender.java b/src/core/src/test/java/org/apache/jmeter/samplers/TestDataStrippingSampleSender.java
index cac17a5d78..a2168564ef 100644
--- a/src/core/src/test/java/org/apache/jmeter/samplers/TestDataStrippingSampleSender.java
+++ b/src/core/src/test/java/org/apache/jmeter/samplers/TestDataStrippingSampleSender.java
@@ -92,7 +92,7 @@ class TestDataStrippingSampleSender extends JMeterTestCase implements JMeterSeri
         return result;
     }
 
-    private class SimpleSender implements SampleSender {
+    private static class SimpleSender implements SampleSender {
 
         private SampleResult result;
 


[jmeter] 14/16: Suppress diverse warnings in test code

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit bcb2f2261c79a7c0c8e73b901d6f6c7b6f5ff4c7
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 17:23:48 2022 +0200

    Suppress diverse warnings in test code
    
    * It might not be nice to catch and print the stack trace, but it
      has been done this way for a long time. (Fix it, if you like)
    * Get rid of unnecessary toString and with it a warning about default
      char encoding
---
 .../org/apache/jmeter/protocol/http/proxy/NonGuiProxySample.java  | 2 +-
 .../jmeter/protocol/mail/sampler/TestMailReaderSampler.java       | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/NonGuiProxySample.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/NonGuiProxySample.java
index 696e731ae0..3af17cf158 100644
--- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/NonGuiProxySample.java
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/NonGuiProxySample.java
@@ -78,7 +78,7 @@ public class NonGuiProxySample {
         try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
             SaveService.saveTree(treeModel.getTestPlan(), out);
             out.close();
-            System.out.println(out.toString());
+            System.out.println(out);
         }
 
     }
diff --git a/src/protocol/mail/src/test/java/org/apache/jmeter/protocol/mail/sampler/TestMailReaderSampler.java b/src/protocol/mail/src/test/java/org/apache/jmeter/protocol/mail/sampler/TestMailReaderSampler.java
index 2298d0b058..406d55b998 100644
--- a/src/protocol/mail/src/test/java/org/apache/jmeter/protocol/mail/sampler/TestMailReaderSampler.java
+++ b/src/protocol/mail/src/test/java/org/apache/jmeter/protocol/mail/sampler/TestMailReaderSampler.java
@@ -17,18 +17,18 @@
 
 package org.apache.jmeter.protocol.mail.sampler;
 
-import static org.junit.Assert.assertEquals;
-
 import java.io.File;
 import java.io.IOException;
 import java.util.Locale;
 import java.util.Properties;
 
 import org.apache.jmeter.util.JMeterUtils;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
 public class TestMailReaderSampler {
 
+    @SuppressWarnings("CatchAndPrintStackTrace")
     public static void createJMeterEnv() {
         File propsFile;
         try {
@@ -51,7 +51,7 @@ public class TestMailReaderSampler {
         MailReaderSampler sampler = new MailReaderSampler();
         Properties properties = new Properties();
         sampler.addCustomProperties(properties);
-        assertEquals(1, properties.size());
-        assertEquals("mail.prop2.value", properties.getProperty("mail.prop2.name"));
+        Assertions.assertEquals(1, properties.size());
+        Assertions.assertEquals("mail.prop2.value", properties.getProperty("mail.prop2.name"));
     }
 }


[jmeter] 09/16: Use ArrayList instead of LinkedList

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit cf4ae3281651eabf5d01a55dcd4822793afc74a4
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 16:54:18 2022 +0200

    Use ArrayList instead of LinkedList
    
    it is considered to be faster in almost all cases.
    
    While we are here
     * Suppress a warning about catching and printing an exception
     * Add override annotations to anonymous classes methods
     * convert to junit5 methods
     * shorten lines to less than 120 chars
     * introduce a private helper to make params (a real builder/DSL would
       be even better)
     * introduce a helper method to assert a range check
---
 .../jmeter/engine/DistributedRunnerTest.java       |   5 +-
 .../gui/logging/TestGuiLogEventAppender.java       |   7 +-
 .../jmeter/util/LogRecordingDelegatingLogger.java  |   4 +-
 .../java/org/apache/jmeter/junit/JMeterTest.java   |   4 +-
 .../apache/jmeter/functions/SplitFunctionTest.java |   4 +-
 .../apache/jmeter/functions/SumFunctionTest.java   |  20 +-
 .../apache/jmeter/functions/TestChangeCase.java    |   4 +-
 .../functions/TestDateTimeConvertFunction.java     |  36 +--
 .../jmeter/functions/TestDigestFunction.java       |  34 +--
 .../jmeter/functions/TestEscapeOroRegexpChars.java |  33 ++-
 .../apache/jmeter/functions/TestFileToString.java  |   4 +-
 .../jmeter/functions/TestGroovyFunction.java       |   4 +-
 .../apache/jmeter/functions/TestIsPropDefined.java |   4 +-
 .../apache/jmeter/functions/TestIsVarDefined.java  |  14 +-
 .../jmeter/functions/TestJavascriptFunction.java   |  32 +--
 .../apache/jmeter/functions/TestJexl2Function.java |  35 ++-
 .../apache/jmeter/functions/TestMachineIPName.java |  19 +-
 .../functions/TestRandomFromMultipleVars.java      |  24 +-
 .../apache/jmeter/functions/TestRegexFunction.java | 288 +++++++++++----------
 .../jmeter/functions/TestSamplerNameFunction.java  |  19 +-
 .../apache/jmeter/functions/TestSetProperty.java   |   4 +-
 .../jmeter/functions/TestSimpleFunctions.java      |  25 +-
 .../apache/jmeter/functions/TestTimeFunction.java  |  80 +++---
 .../jmeter/functions/TestUrlEncodeDecode.java      |  19 +-
 .../protocol/http/util/TestHTTPFileArgs.java       |   4 +-
 25 files changed, 365 insertions(+), 361 deletions(-)

diff --git a/src/core/src/test/java/org/apache/jmeter/engine/DistributedRunnerTest.java b/src/core/src/test/java/org/apache/jmeter/engine/DistributedRunnerTest.java
index 172b94d169..bca3154142 100644
--- a/src/core/src/test/java/org/apache/jmeter/engine/DistributedRunnerTest.java
+++ b/src/core/src/test/java/org/apache/jmeter/engine/DistributedRunnerTest.java
@@ -23,8 +23,8 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Properties;
@@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory;
 @Execution(ExecutionMode.SAME_THREAD) // System.setOut must not be run concurrently with other tests
 public class DistributedRunnerTest {
 
+    @SuppressWarnings("CatchAndPrintStackTrace")
     public static void createJmeterEnv() {
         File propsFile;
         try {
@@ -127,7 +128,7 @@ public class DistributedRunnerTest {
     }
 
     private static class DistributedRunnerEmul extends DistributedRunner {
-        public List<EmulatorEngine> engines = new LinkedList<>();
+        public List<EmulatorEngine> engines = new ArrayList<>();
 
         @Override
         protected JMeterEngine createEngine(String address) {
diff --git a/src/core/src/test/java/org/apache/jmeter/gui/logging/TestGuiLogEventAppender.java b/src/core/src/test/java/org/apache/jmeter/gui/logging/TestGuiLogEventAppender.java
index 0182366ed7..e59184d17c 100644
--- a/src/core/src/test/java/org/apache/jmeter/gui/logging/TestGuiLogEventAppender.java
+++ b/src/core/src/test/java/org/apache/jmeter/gui/logging/TestGuiLogEventAppender.java
@@ -19,8 +19,8 @@ package org.apache.jmeter.gui.logging;
 
 import static org.junit.Assert.assertTrue;
 
+import java.util.ArrayList;
 import java.util.Collections;
-import java.util.LinkedList;
 import java.util.List;
 
 import org.apache.logging.log4j.Level;
@@ -43,7 +43,7 @@ import org.slf4j.LoggerFactory;
 
 public class TestGuiLogEventAppender {
 
-    private static List<String> log4j2LevelErrorMessages = Collections.synchronizedList(new LinkedList<>());
+    private static List<String> log4j2LevelErrorMessages = Collections.synchronizedList(new ArrayList<>());
 
     /*
      * Configure logging with GuiLogEventAppender for root logger, and override the handler of GuiLogEventAppender
@@ -74,14 +74,17 @@ public class TestGuiLogEventAppender {
 
         guiLogEventAppender.stop();
         guiLogEventAppender.setHandler(new ErrorHandler() {
+            @Override
             public void error(String msg) {
                 log4j2LevelErrorMessages.add(msg);
             }
 
+            @Override
             public void error(String msg, Throwable t) {
                 log4j2LevelErrorMessages.add(msg + " " + t);
             }
 
+            @Override
             public void error(String msg, LogEvent event, Throwable t) {
                 log4j2LevelErrorMessages.add(msg + " " + t);
             }
diff --git a/src/core/src/test/java/org/apache/jmeter/util/LogRecordingDelegatingLogger.java b/src/core/src/test/java/org/apache/jmeter/util/LogRecordingDelegatingLogger.java
index 8938b83257..4eeda13311 100644
--- a/src/core/src/test/java/org/apache/jmeter/util/LogRecordingDelegatingLogger.java
+++ b/src/core/src/test/java/org/apache/jmeter/util/LogRecordingDelegatingLogger.java
@@ -17,9 +17,9 @@
 
 package org.apache.jmeter.util;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.LinkedList;
 import java.util.List;
 
 import org.slf4j.Logger;
@@ -30,7 +30,7 @@ import org.slf4j.Marker;
  */
 public class LogRecordingDelegatingLogger implements Logger {
 
-    private List<LogRecord> logRecords = Collections.synchronizedList(new LinkedList<>());
+    private List<LogRecord> logRecords = Collections.synchronizedList(new ArrayList<>());
 
     private Logger delegate;
 
diff --git a/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java b/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java
index 87a03ae61a..9297edc514 100644
--- a/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java
+++ b/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java
@@ -30,10 +30,10 @@ import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
 import java.rmi.RemoteException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -456,7 +456,7 @@ public class JMeterTest extends JMeterTestCaseJUnit implements Describable {
         Object myThis = "";
         Iterator<String> classes = ClassFinder
                 .findClassesThatExtend(JMeterUtils.getSearchPaths(), new Class[] { extendsClass }).iterator();
-        List<Object> objects = new LinkedList<>();
+        List<Object> objects = new ArrayList<>();
         String n = "";
         boolean caughtError = true;
         Throwable caught = null;
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/SplitFunctionTest.java b/src/functions/src/test/java/org/apache/jmeter/functions/SplitFunctionTest.java
index 69169bb8d8..1fe81f2a31 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/SplitFunctionTest.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/SplitFunctionTest.java
@@ -21,8 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -159,7 +159,7 @@ public class SplitFunctionTest extends JMeterTestCase {
     // Create the SplitFile function and set its parameters.
     private static SplitFunction splitParams(String p1, String p2, String p3) throws Exception {
         SplitFunction split = new SplitFunction();
-        Collection<CompoundVariable> parms = new LinkedList<>();
+        Collection<CompoundVariable> parms = new ArrayList<>();
         parms.add(new CompoundVariable(p1));
         if (p2 != null) {
             parms.add(new CompoundVariable(p2));
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/SumFunctionTest.java b/src/functions/src/test/java/org/apache/jmeter/functions/SumFunctionTest.java
index dc49c38447..fc5a2ee162 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/SumFunctionTest.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/SumFunctionTest.java
@@ -17,11 +17,10 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.LinkedList;
 import java.util.stream.Collectors;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
@@ -29,22 +28,23 @@ import org.apache.jmeter.junit.JMeterTestCase;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-public class SumFunctionTest extends JMeterTestCase {
+class SumFunctionTest extends JMeterTestCase {
 
     private JMeterVariables vars = null;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         JMeterContext jmctx = JMeterContextService.getContext();
         jmctx.setVariables(new JMeterVariables());
         vars = jmctx.getVariables();
     }
 
     @Test
-    public void sumTest() throws Exception {
+    void sumTest() throws Exception {
         String maxIntVal = Integer.toString(Integer.MAX_VALUE);
         String minIntVal = Integer.toString(Integer.MIN_VALUE);
 
@@ -78,19 +78,19 @@ public class SumFunctionTest extends JMeterTestCase {
     private void checkSum(AbstractFunction func, String value, String[] addends)  throws Exception {
         Collection<CompoundVariable> parms = Arrays.stream(addends)
                 .map(CompoundVariable::new)
-                .collect(Collectors.toCollection(LinkedList::new));
+                .collect(Collectors.toCollection(ArrayList::new));
         parms.add(new CompoundVariable("Result"));
         func.setParameters(parms);
-        assertEquals(value, func.execute(null,null));
-        assertEquals(value, vars.getObject("Result"));
+        Assertions.assertEquals(value, func.execute(null,null));
+        Assertions.assertEquals(value, vars.getObject("Result"));
     }
 
     // Perform a sum and check the results
     private void checkSumNoVar(AbstractFunction func, String value, String[] addends)  throws Exception {
         Collection<CompoundVariable> parms = Arrays.stream(addends)
                 .map(CompoundVariable::new)
-                .collect(Collectors.toCollection(LinkedList::new));
+                .collect(Collectors.toCollection(ArrayList::new));
         func.setParameters(parms);
-        assertEquals(value,func.execute(null,null));
+        Assertions.assertEquals(value, func.execute(null,null));
     }
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestChangeCase.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestChangeCase.java
index a1b2237a0f..f3c5a4f234 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestChangeCase.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestChangeCase.java
@@ -20,8 +20,8 @@ package org.apache.jmeter.functions;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -93,7 +93,7 @@ public class TestChangeCase extends JMeterTestCase {
     public void testChangeCaseError() throws Exception {
         assertThrows(
                 InvalidVariableException.class,
-                () -> changeCase.setParameters(new LinkedList<>()));
+                () -> changeCase.setParameters(new ArrayList<>()));
     }
 
     @Test
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestDateTimeConvertFunction.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestDateTimeConvertFunction.java
index f219d777fc..825eff164b 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestDateTimeConvertFunction.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestDateTimeConvertFunction.java
@@ -17,11 +17,10 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 import java.util.TimeZone;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
@@ -31,6 +30,7 @@ import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
 import org.apache.jorphan.test.JMeterSerialTest;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -38,7 +38,7 @@ import org.junit.jupiter.api.Test;
  * Test {@link DateTimeConvertFunction}
  * We implement JMeterSerialTest as we change TimeZone
  */
-public class TestDateTimeConvertFunction extends JMeterTestCase implements JMeterSerialTest {
+class TestDateTimeConvertFunction extends JMeterTestCase implements JMeterSerialTest {
 
     private AbstractFunction dateConvert;
     private SampleResult result;
@@ -47,7 +47,7 @@ public class TestDateTimeConvertFunction extends JMeterTestCase implements JMete
     private JMeterContext jmctx;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         dateConvert = new DateTimeConvertFunction();
         result = new SampleResult();
         jmctx = JMeterContextService.getContext();
@@ -56,7 +56,7 @@ public class TestDateTimeConvertFunction extends JMeterTestCase implements JMete
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
@@ -65,17 +65,17 @@ public class TestDateTimeConvertFunction extends JMeterTestCase implements JMete
     }
 
     @Test
-    public void testDateTimeConvert() throws Exception {
+    void testDateTimeConvert() throws Exception {
         params.add(new CompoundVariable("2017-01-02 21:00:21"));
         params.add(new CompoundVariable("yyyy-MM-dd HH:mm:ss"));
         params.add(new CompoundVariable("dd-MM-yyyy hh:mm"));
         dateConvert.setParameters(params);
         String returnValue = dateConvert.execute(result, null);
-        assertEquals("02-01-2017 09:00", returnValue);
+        Assertions.assertEquals("02-01-2017 09:00", returnValue);
     }
 
     @Test
-    public void testDateTimeConvertEpochTime() throws Exception {
+    void testDateTimeConvertEpochTime() throws Exception {
         TimeZone initialTZ = TimeZone.getDefault();
         TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
         params.add(new CompoundVariable("1526574881000"));
@@ -83,33 +83,33 @@ public class TestDateTimeConvertFunction extends JMeterTestCase implements JMete
         params.add(new CompoundVariable("dd/MM/yyyy HH:mm"));
         dateConvert.setParameters(params);
         String returnValue = dateConvert.execute(result, null);
-        assertEquals("17/05/2018 16:34", returnValue);
+        Assertions.assertEquals("17/05/2018 16:34", returnValue);
         TimeZone.setDefault(initialTZ);
     }
 
     @Test
-    public void testDateConvert() throws Exception {
+    void testDateConvert() throws Exception {
         params.add(new CompoundVariable("2017-01-02"));
         params.add(new CompoundVariable("yyyy-MM-dd"));
         params.add(new CompoundVariable("dd-MM-yyyy"));
         dateConvert.setParameters(params);
         String returnValue = dateConvert.execute(result, null);
-        assertEquals("02-01-2017", returnValue);
+        Assertions.assertEquals("02-01-2017", returnValue);
     }
 
     @Test
-    public void testDateConvertWithVariable() throws Exception {
+    void testDateConvertWithVariable() throws Exception {
         params.add(new CompoundVariable("2017-01-02"));
         params.add(new CompoundVariable("yyyy-MM-dd"));
         params.add(new CompoundVariable("dd-MM-yyyy"));
         params.add(new CompoundVariable("varName"));
         dateConvert.setParameters(params);
         dateConvert.execute(result, null);
-        assertEquals("02-01-2017", vars.get("varName"));
+        Assertions.assertEquals("02-01-2017", vars.get("varName"));
     }
 
     @Test
-    public void testDateConvertError() throws Exception {
+    void testDateConvertError() throws Exception {
         params.add(new CompoundVariable("2017-01-02"));
         params.add(new CompoundVariable("yyyy-MM-dd"));
         assertThrows(
@@ -118,20 +118,20 @@ public class TestDateTimeConvertFunction extends JMeterTestCase implements JMete
     }
 
     @Test
-    public void testDateConvertErrorFormat() throws Exception {
+    void testDateConvertErrorFormat() throws Exception {
         params.add(new CompoundVariable("2017-01-02"));
         params.add(new CompoundVariable("yyyy-MM-dd"));
         params.add(new CompoundVariable("abcd"));
         dateConvert.setParameters(params);
-        assertEquals(dateConvert.execute(result, null), "");
+        Assertions.assertEquals(dateConvert.execute(result, null), "");
     }
 
     @Test
-    public void testDateConvertDateError() throws Exception {
+    void testDateConvertDateError() throws Exception {
         params.add(new CompoundVariable("a2017-01-02"));
         params.add(new CompoundVariable("yyyy-MM-dd"));
         params.add(new CompoundVariable("dd-MM-yyyy HH:mm:ss"));
         dateConvert.setParameters(params);
-        assertEquals(dateConvert.execute(result, null), "");
+        Assertions.assertEquals(dateConvert.execute(result, null), "");
     }
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestDigestFunction.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestDigestFunction.java
index 77459f5bf4..17ea4796cc 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestDigestFunction.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestDigestFunction.java
@@ -17,11 +17,10 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -29,6 +28,7 @@ import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -47,7 +47,7 @@ public class TestDigestFunction extends JMeterTestCase {
         JMeterVariables vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
@@ -62,9 +62,9 @@ public class TestDigestFunction extends JMeterTestCase {
         params.add(new CompoundVariable("salt"));
         digest.setParameters(params);
         String returnValue = digest.execute(result, null);
-        assertEquals(
-                "abc8c7a1c814c74d5882e527d21fabfccf480716df9d17bae73e5e767992d8a2a47033459a9ea91aca3186f75bfbe559419109bc44c1e6dfd618101fdc0beb1b",
-                returnValue);
+        Assertions.assertEquals(
+                "abc8c7a1c814c74d5882e527d21fabfccf480716df9d17bae73e5e767992d8a2a4703345" +
+                        "9a9ea91aca3186f75bfbe559419109bc44c1e6dfd618101fdc0beb1b", returnValue);
     }
 
     @Test
@@ -74,9 +74,9 @@ public class TestDigestFunction extends JMeterTestCase {
         params.add(new CompoundVariable("salt "));
         digest.setParameters(params);
         String returnValue = digest.execute(result, null);
-        assertEquals(
-                "961451eb5870ded3fa484ad49fd1481ae3c6decdcc560200e70624a1d62ad0d1793edf3c8eccd0786bffab0b3e4421f54c7fd11a9e7461580352346d039b8e16",
-                returnValue);
+        Assertions.assertEquals(
+                "961451eb5870ded3fa484ad49fd1481ae3c6decdcc560200e70624a1d62ad0d1793edf3c8eccd0" +
+                        "786bffab0b3e4421f54c7fd11a9e7461580352346d039b8e16", returnValue);
     }
 
     @Test
@@ -86,9 +86,9 @@ public class TestDigestFunction extends JMeterTestCase {
         params.add(new CompoundVariable("salt "));
         digest.setParameters(params);
         String returnValue = digest.execute(result, null);
-        assertEquals(
-                "3968fd028934466fa095f6323c527148e87d7b74601d1db5f474748dd7c643b4f508e46beb29a405ec658a64c0f581461e99eca063414099af0b63dc890b5739",
-                returnValue);
+        Assertions.assertEquals(
+                "3968fd028934466fa095f6323c527148e87d7b74601d1db5f474748dd7c643b4f508e46beb29a" +
+                        "405ec658a64c0f581461e99eca063414099af0b63dc890b5739", returnValue);
     }
 
     @Test
@@ -97,7 +97,7 @@ public class TestDigestFunction extends JMeterTestCase {
         params.add(new CompoundVariable("nofile"));
         digest.setParameters(params);
         String returnValue = digest.execute(result, null);
-        assertEquals("4ea2ced10057872be25371cfe638d3b096c58f2f", returnValue);
+        Assertions.assertEquals("4ea2ced10057872be25371cfe638d3b096c58f2f", returnValue);
     }
 
     @Test
@@ -109,7 +109,7 @@ public class TestDigestFunction extends JMeterTestCase {
         params.add(new CompoundVariable("newVar"));
         digest.setParameters(params);
         String returnValue = digest.execute(result, null);
-        assertEquals("4EA2CED10057872BE25371CFE638D3B096C58F2F", returnValue);
+        Assertions.assertEquals("4EA2CED10057872BE25371CFE638D3B096C58F2F", returnValue);
     }
 
     @Test
@@ -121,9 +121,9 @@ public class TestDigestFunction extends JMeterTestCase {
         params.add(new CompoundVariable("newVar"));
         digest.setParameters(params);
         String returnValue = digest.execute(result, null);
-        assertEquals(
-                "58DA94D45A97B35B31D7F76D2EBAC184BC4BDA512B966CDBE43FDE1CAE1CFAF89617082CA89928FB5DC1C75D60B93ADB5631F518F970CA6DCC196E1AFC678B8C",
-                returnValue);
+        Assertions.assertEquals(
+                "58DA94D45A97B35B31D7F76D2EBAC184BC4BDA512B966CDBE43FDE1CAE1CFAF89617082" +
+                        "CA89928FB5DC1C75D60B93ADB5631F518F970CA6DCC196E1AFC678B8C", returnValue);
     }
 
     @Test
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestEscapeOroRegexpChars.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestEscapeOroRegexpChars.java
index 8091d1bcf6..1722c309e9 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestEscapeOroRegexpChars.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestEscapeOroRegexpChars.java
@@ -17,10 +17,8 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
-
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -28,6 +26,7 @@ import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -40,7 +39,7 @@ public class TestEscapeOroRegexpChars extends JMeterTestCase {
     private JMeterContext jmctx;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         function = new EscapeOroRegexpChars();
         result = new SampleResult();
         jmctx = JMeterContextService.getContext();
@@ -49,53 +48,53 @@ public class TestEscapeOroRegexpChars extends JMeterTestCase {
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
-    public void testParameterCount() throws Exception {
+    void testParameterCount() throws Exception {
         checkInvalidParameterCounts(function, 1, 2);
     }
 
     @Test
-    public void testNOEscape() throws Exception {
+    void testNOEscape() throws Exception {
         params.add(new CompoundVariable("toto1titi"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("toto1titi", ret);
+        Assertions.assertEquals("toto1titi", ret);
     }
 
     @Test
-    public void testEscapeSpace() throws Exception {
+    void testEscapeSpace() throws Exception {
         params.add(new CompoundVariable("toto1 titi"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("toto1\\ titi", ret);
+        Assertions.assertEquals("toto1\\ titi", ret);
     }
 
     @Test
-    public void testEscape() throws Exception {
+    void testEscape() throws Exception {
         params.add(new CompoundVariable("toto(.+?)titi"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("toto\\(\\.\\+\\?\\)titi", ret);
+        Assertions.assertEquals("toto\\(\\.\\+\\?\\)titi", ret);
     }
 
     @Test
-    public void testEscapeWithVars() throws Exception {
+    void testEscapeWithVars() throws Exception {
         params.add(new CompoundVariable("toto(.+?)titi"));
         params.add(new CompoundVariable("exportedVar"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("toto\\(\\.\\+\\?\\)titi", ret);
-        assertEquals("toto\\(\\.\\+\\?\\)titi", vars.get("exportedVar"));
+        Assertions.assertEquals("toto\\(\\.\\+\\?\\)titi", ret);
+        Assertions.assertEquals("toto\\(\\.\\+\\?\\)titi", vars.get("exportedVar"));
     }
 
     @Test
-    public void testEscape2() throws Exception {
+    void testEscape2() throws Exception {
         params.add(new CompoundVariable("[^\"].+?"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("\\[\\^\\\"\\]\\.\\+\\?", ret);
+        Assertions.assertEquals("\\[\\^\\\"\\]\\.\\+\\?", ret);
     }
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestFileToString.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestFileToString.java
index f6e501848c..634482ce1a 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestFileToString.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestFileToString.java
@@ -20,8 +20,8 @@ package org.apache.jmeter.functions;
 import static org.junit.Assert.assertEquals;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -52,7 +52,7 @@ public class TestFileToString extends JMeterTestCase {
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestGroovyFunction.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestGroovyFunction.java
index 513a6153bb..a8e5a28ec7 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestGroovyFunction.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestGroovyFunction.java
@@ -19,8 +19,8 @@ package org.apache.jmeter.functions;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -58,7 +58,7 @@ public class TestGroovyFunction extends JMeterTestCase implements JMeterSerialTe
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestIsPropDefined.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestIsPropDefined.java
index 113eebd139..297fc90295 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestIsPropDefined.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestIsPropDefined.java
@@ -19,8 +19,8 @@ package org.apache.jmeter.functions;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -50,7 +50,7 @@ public class TestIsPropDefined extends JMeterTestCase {
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestIsVarDefined.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestIsVarDefined.java
index eabc18a554..59f3240f59 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestIsVarDefined.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestIsVarDefined.java
@@ -17,10 +17,8 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
-
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -50,7 +48,7 @@ public class TestIsVarDefined extends JMeterTestCase {
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
@@ -63,7 +61,7 @@ public class TestIsVarDefined extends JMeterTestCase {
         params.add(new CompoundVariable("file.encoding"));
         isVarDefined.setParameters(params);
         String returnValue = isVarDefined.execute(result, null);
-        assertEquals("false", returnValue);
+        Assertions.assertEquals("false", returnValue);
     }
 
     @Test
@@ -72,7 +70,7 @@ public class TestIsVarDefined extends JMeterTestCase {
         params.add(new CompoundVariable("varName"));
         isVarDefined.setParameters(params);
         String returnValue = isVarDefined.execute(result, null);
-        assertEquals("true", returnValue);
+        Assertions.assertEquals("true", returnValue);
     }
 
     @Test
@@ -80,7 +78,7 @@ public class TestIsVarDefined extends JMeterTestCase {
         params.add(new CompoundVariable("emptyProperty"));
         isVarDefined.setParameters(params);
         String returnValue = isVarDefined.execute(result, null);
-        assertEquals("false", returnValue);
+        Assertions.assertEquals("false", returnValue);
     }
 
     @Test
@@ -96,7 +94,7 @@ public class TestIsVarDefined extends JMeterTestCase {
         params.add(new CompoundVariable("emptyProperty"));
         isVarDefined.setParameters(params);
         String returnValue = isVarDefined.execute(result, null);
-        assertEquals("false", returnValue);
+        Assertions.assertEquals("false", returnValue);
     }
 
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestJavascriptFunction.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestJavascriptFunction.java
index 6835741da4..fa7840d648 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestJavascriptFunction.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestJavascriptFunction.java
@@ -17,10 +17,9 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -30,6 +29,7 @@ import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
 import org.apache.jmeter.util.JMeterUtils;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -42,12 +42,12 @@ public class TestJavascriptFunction extends JMeterTestCase {
     private JMeterContext jmctx;
 
     @AfterEach
-    public void tearDown() {
+    void tearDown() {
         JMeterUtils.getJMeterProperties().remove("javascript.use_rhino");
     }
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         function = new JavaScript();
         result = new SampleResult();
         jmctx = JMeterContextService.getContext();
@@ -56,49 +56,49 @@ public class TestJavascriptFunction extends JMeterTestCase {
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
-    public void testParameterCount() throws Exception {
+    void testParameterCount() throws Exception {
         checkInvalidParameterCounts(function, 1, 2);
     }
 
     @Test
-    public void testSum() throws Exception {
+    void testSum() throws Exception {
         params.add(new CompoundVariable("1+2+3"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("6", ret);
+        Assertions.assertEquals("6", ret);
     }
 
     @Test
-    public void testSumVar() throws Exception {
+    void testSumVar() throws Exception {
         params.add(new CompoundVariable("1+2+3"));
         params.add(new CompoundVariable("TOTAL"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("6", ret);
-        assertEquals("6", vars.get("TOTAL"));
+        Assertions.assertEquals("6", ret);
+        Assertions.assertEquals("6", vars.get("TOTAL"));
     }
 
     @Test
-    public void testReplace1() throws Exception {
+    void testReplace1() throws Exception {
         params.add(new CompoundVariable(
                 "sampleResult.getResponseDataAsString().replaceAll('T','t')"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("the quick brown fox", ret);
+        Assertions.assertEquals("the quick brown fox", ret);
     }
 
     @Test
-    public void testReplace2() throws Exception {
+    void testReplace2() throws Exception {
         vars.put("URL", "/query.cgi?s1=1&amp;s2=2&amp;s3=3");
         params.add(new CompoundVariable("vars.get('URL').replaceAll('&amp;','&')"));
         params.add(new CompoundVariable("URL"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("/query.cgi?s1=1&s2=2&s3=3", ret);
-        assertEquals(ret,vars.getObject("URL"));
+        Assertions.assertEquals("/query.cgi?s1=1&s2=2&s3=3", ret);
+        Assertions.assertEquals(ret, vars.getObject("URL"));
     }
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestJexl2Function.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestJexl2Function.java
index af647d0e93..ef172b2667 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestJexl2Function.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestJexl2Function.java
@@ -17,10 +17,8 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
-
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -28,6 +26,7 @@ import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -40,7 +39,7 @@ public class TestJexl2Function extends JMeterTestCase {
     private JMeterContext jmctx;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         function = new Jexl2Function();
         result = new SampleResult();
         jmctx = JMeterContextService.getContext();
@@ -49,57 +48,57 @@ public class TestJexl2Function extends JMeterTestCase {
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
-    public void testParameterCount() throws Exception {
+    void testParameterCount() throws Exception {
         checkInvalidParameterCounts(function, 1, 2);
     }
 
     @Test
-    public void testSum() throws Exception {
+    void testSum() throws Exception {
         params.add(new CompoundVariable("1+2+3"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("6", ret);
+        Assertions.assertEquals("6", ret);
     }
 
     @Test
-    public void testSumVar() throws Exception {
+    void testSumVar() throws Exception {
         params.add(new CompoundVariable("1+2+3"));
         params.add(new CompoundVariable("TOTAL"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("6", ret);
-        assertEquals("6", vars.get("TOTAL"));
+        Assertions.assertEquals("6", ret);
+        Assertions.assertEquals("6", vars.get("TOTAL"));
     }
 
     @Test
-    public void testReplace1() throws Exception {
+    void testReplace1() throws Exception {
         params.add(new CompoundVariable(
                 "sampleResult.getResponseDataAsString().replaceAll('T','t')"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("the quick brown fox", ret);
+        Assertions.assertEquals("the quick brown fox", ret);
     }
 
     @Test
-    public void testReplace2() throws Exception {
+    void testReplace2() throws Exception {
         vars.put("URL", "/query.cgi?s1=1&amp;s2=2&amp;s3=3");
         params.add(new CompoundVariable("vars.get('URL').replaceAll('&amp;','&')"));
         params.add(new CompoundVariable("URL"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("/query.cgi?s1=1&s2=2&s3=3", ret);
-        assertEquals(ret,vars.getObject("URL"));
+        Assertions.assertEquals("/query.cgi?s1=1&s2=2&s3=3", ret);
+        Assertions.assertEquals(ret, vars.getObject("URL"));
     }
 
     @Test
-    public void testSumWithVar() throws Exception {
+    void testSumWithVar() throws Exception {
         params.add(new CompoundVariable("var a = 1+2+3"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("6", ret);
+        Assertions.assertEquals("6", ret);
     }
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestMachineIPName.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestMachineIPName.java
index e56e8047f2..347bb80fb4 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestMachineIPName.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestMachineIPName.java
@@ -17,10 +17,8 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
-
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -29,6 +27,7 @@ import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
 import org.apache.jmeter.util.JMeterUtils;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -49,7 +48,7 @@ public class TestMachineIPName extends JMeterTestCase {
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
@@ -66,7 +65,7 @@ public class TestMachineIPName extends JMeterTestCase {
         function = new MachineName();
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals(JMeterUtils.getLocalHostName(), ret);
+        Assertions.assertEquals(JMeterUtils.getLocalHostName(), ret);
     }
 
     @Test
@@ -75,8 +74,8 @@ public class TestMachineIPName extends JMeterTestCase {
         params.add(new CompoundVariable("HOST_NAME"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals(JMeterUtils.getLocalHostName(), ret);
-        assertEquals(JMeterUtils.getLocalHostName(), vars.get("HOST_NAME"));
+        Assertions.assertEquals(JMeterUtils.getLocalHostName(), ret);
+        Assertions.assertEquals(JMeterUtils.getLocalHostName(), vars.get("HOST_NAME"));
     }
 
     @Test
@@ -84,7 +83,7 @@ public class TestMachineIPName extends JMeterTestCase {
         function = new MachineIP();
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals(JMeterUtils.getLocalHostIP(), ret);
+        Assertions.assertEquals(JMeterUtils.getLocalHostIP(), ret);
     }
 
     @Test
@@ -93,7 +92,7 @@ public class TestMachineIPName extends JMeterTestCase {
         params.add(new CompoundVariable("HOST_IP"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals(JMeterUtils.getLocalHostIP(), ret);
-        assertEquals(JMeterUtils.getLocalHostIP(), vars.get("HOST_IP"));
+        Assertions.assertEquals(JMeterUtils.getLocalHostIP(), ret);
+        Assertions.assertEquals(JMeterUtils.getLocalHostIP(), vars.get("HOST_IP"));
     }
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestRandomFromMultipleVars.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestRandomFromMultipleVars.java
index 19b23d5522..486097fbb9 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestRandomFromMultipleVars.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestRandomFromMultipleVars.java
@@ -17,10 +17,8 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
-
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -30,7 +28,7 @@ import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
 import org.hamcrest.CoreMatchers;
 import org.hamcrest.MatcherAssert;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -43,7 +41,7 @@ public class TestRandomFromMultipleVars extends JMeterTestCase {
     private JMeterContext jmctx;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         result = new SampleResult();
         jmctx = JMeterContextService.getContext();
         String data = "The quick brown fox";
@@ -52,16 +50,16 @@ public class TestRandomFromMultipleVars extends JMeterTestCase {
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
-    public void testParameterCount() throws Exception {
+    void testParameterCount() throws Exception {
         checkInvalidParameterCounts(function, 1, 2);
     }
 
     @Test
-    public void testExtractionFromMultipleVars() throws Exception {
+    void testExtractionFromMultipleVars() throws Exception {
         String existingVarName1 = "var1";
         String existingVarName2 = "var2";
         vars.put(existingVarName1+"_matchNr", "1");
@@ -78,7 +76,7 @@ public class TestRandomFromMultipleVars extends JMeterTestCase {
                 CoreMatchers.anyOf(CoreMatchers.is("var1_value"),
                         CoreMatchers.is("var2_value1"),
                         CoreMatchers.is("var2_value2")));
-        Assert.assertNull(vars.get("outputVar"));
+        Assertions.assertNull(vars.get("outputVar"));
     }
 
     @Test
@@ -89,8 +87,8 @@ public class TestRandomFromMultipleVars extends JMeterTestCase {
         params.add(new CompoundVariable("var1"));
         function.setParameters(params);
         String returnValue = function.execute(result, null);
-        assertEquals("value1", returnValue);
-        Assert.assertNull(vars.get("outputVar"));
+        Assertions.assertEquals("value1", returnValue);
+        Assertions.assertNull(vars.get("outputVar"));
     }
 
     @Test
@@ -102,7 +100,7 @@ public class TestRandomFromMultipleVars extends JMeterTestCase {
         params.add(new CompoundVariable("outputVar"));
         function.setParameters(params);
         String returnValue = function.execute(result, null);
-        assertEquals("value1", returnValue);
-        assertEquals("value1", vars.get("outputVar"));
+        Assertions.assertEquals("value1", returnValue);
+        Assertions.assertEquals("value1", vars.get("outputVar"));
     }
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestRegexFunction.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestRegexFunction.java
index 7682beb6b0..4fd7f19bee 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestRegexFunction.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestRegexFunction.java
@@ -21,7 +21,8 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
 import java.util.Collection;
-import java.util.LinkedList;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -65,10 +66,10 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtraction() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("$2$"));
-        params.add(new CompoundVariable("2"));
+        params = makeParams(
+                "<value field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "$2$",
+                "2");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("5", match);
@@ -77,13 +78,13 @@ public class TestRegexFunction extends JMeterTestCase {
     // Test with output variable name
     @Test
     public void testVariableExtraction1a() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("$2$")); // template
-        params.add(new CompoundVariable("2")); // match number
-        params.add(new CompoundVariable("-")); // ALL separator
-        params.add(new CompoundVariable("default"));
-        params.add(new CompoundVariable("OUTVAR"));
+        params = makeParams(
+                "<value field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "$2$", // template
+                "2", // match number
+                "-", // ALL separator
+                "default",
+                "OUTVAR");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("3", vars.getObject("OUTVAR_matchNr"));
@@ -97,13 +98,12 @@ public class TestRegexFunction extends JMeterTestCase {
     // Test with empty output variable name
     @Test
     public void testVariableExtraction1b() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("$2$")); // template
-        params.add(new CompoundVariable("2")); // match number
-        params.add(new CompoundVariable("-")); // ALL separator
-        params.add(new CompoundVariable("default"));
-        params.add(new CompoundVariable(""));
+        params = makeParams(
+                "<value field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "$2$", // template
+                "2", // match number
+                "-", // ALL separator
+                "default","");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("5", match);
@@ -112,14 +112,14 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtractionFromVariable() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
-        params.add(new CompoundVariable("$2$")); // template
-        params.add(new CompoundVariable("1")); // match number
-        params.add(new CompoundVariable("-")); // ALL separator
-        params.add(new CompoundVariable("default"));
-        params.add(new CompoundVariable("OUTVAR"));
-        params.add(new CompoundVariable(INPUT_VARIABLE_NAME));
+        params = makeParams(
+                "(\\d+)\\s+(\\w+)",
+                "$2$", // template
+                "1", // match number
+                "-", // ALL separator
+                "default",
+                "OUTVAR",
+                INPUT_VARIABLE_NAME);
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("1", vars.getObject("OUTVAR_matchNr"));
@@ -132,14 +132,14 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtractionFromVariable2() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
-        params.add(new CompoundVariable("$1$$2$")); // template
-        params.add(new CompoundVariable("1")); // match number
-        params.add(new CompoundVariable("-")); // ALL separator
-        params.add(new CompoundVariable("default"));
-        params.add(new CompoundVariable("OUTVAR"));
-        params.add(new CompoundVariable(INPUT_VARIABLE_NAME));
+        params = makeParams(
+                "(\\d+)\\s+(\\w+)",
+                "$1$$2$", // template
+                "1", // match number
+                "-", // ALL separator
+                "default",
+                "OUTVAR",
+                INPUT_VARIABLE_NAME);
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("1", vars.getObject("OUTVAR_matchNr"));
@@ -152,14 +152,14 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtractionFromVariable3() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
-        params.add(new CompoundVariable("pre$2$post")); // template
-        params.add(new CompoundVariable("1")); // match number
-        params.add(new CompoundVariable("-")); // ALL separator
-        params.add(new CompoundVariable("default"));
-        params.add(new CompoundVariable("OUTVAR"));
-        params.add(new CompoundVariable(INPUT_VARIABLE_NAME));
+        params = makeParams(
+                "(\\d+)\\s+(\\w+)",
+                "pre$2$post", // template
+                "1", // match number
+                "-", // ALL separator
+                "default",
+                "OUTVAR",
+                INPUT_VARIABLE_NAME);
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("1", vars.getObject("OUTVAR_matchNr"));
@@ -172,14 +172,14 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtractionFromVariable4() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
-        params.add(new CompoundVariable("pre$2$")); // template
-        params.add(new CompoundVariable("1")); // match number
-        params.add(new CompoundVariable("-")); // ALL separator
-        params.add(new CompoundVariable("default"));
-        params.add(new CompoundVariable("OUTVAR"));
-        params.add(new CompoundVariable(INPUT_VARIABLE_NAME));
+        params = makeParams(
+                "(\\d+)\\s+(\\w+)",
+                "pre$2$", // template
+                "1", // match number
+                "-", // ALL separator
+                "default",
+                "OUTVAR",
+                INPUT_VARIABLE_NAME);
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("1", vars.getObject("OUTVAR_matchNr"));
@@ -192,14 +192,14 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtractionFromVariable5() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
-        params.add(new CompoundVariable("$2$post")); // template
-        params.add(new CompoundVariable("1")); // match number
-        params.add(new CompoundVariable("-")); // ALL separator
-        params.add(new CompoundVariable("default"));
-        params.add(new CompoundVariable("OUTVAR"));
-        params.add(new CompoundVariable(INPUT_VARIABLE_NAME));
+        params = makeParams(
+                "(\\d+)\\s+(\\w+)",
+                "$2$post", // template
+                "1", // match number
+                "-", // ALL separator
+                "default",
+                "OUTVAR",
+                INPUT_VARIABLE_NAME);
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("1", vars.getObject("OUTVAR_matchNr"));
@@ -212,14 +212,14 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtractionFromVariable6() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
-        params.add(new CompoundVariable("$2$$2$")); // template
-        params.add(new CompoundVariable("1")); // match number
-        params.add(new CompoundVariable("-")); // ALL separator
-        params.add(new CompoundVariable("default"));
-        params.add(new CompoundVariable("OUTVAR"));
-        params.add(new CompoundVariable(INPUT_VARIABLE_NAME));
+        params = makeParams(
+                "(\\d+)\\s+(\\w+)",
+                "$2$$2$", // template
+                "1", // match number
+                "-", // ALL separator
+                "default",
+                "OUTVAR",
+                INPUT_VARIABLE_NAME);
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("1", vars.getObject("OUTVAR_matchNr"));
@@ -232,13 +232,13 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtractionFromVariable7() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
-        params.add(new CompoundVariable("pre$1$mid$2$post")); // template
-        params.add(new CompoundVariable("1")); // match number
-        params.add(new CompoundVariable("-")); // ALL separator
-        params.add(new CompoundVariable("default"));
-        params.add(new CompoundVariable("OUTVAR"));
+        params = makeParams(
+                "(\\d+)\\s+(\\w+)",
+                "pre$1$mid$2$post", // template
+                "1", // match number
+                "-", // ALL separator
+                "default",
+                "OUTVAR");
         params.add(new CompoundVariable(INPUT_VARIABLE_NAME));
         variable.setParameters(params);
         String match = variable.execute(result, null);
@@ -252,14 +252,14 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtractionFromVariable8() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
-        params.add(new CompoundVariable("pre$1$mid$2$")); // template
-        params.add(new CompoundVariable("1")); // match number
-        params.add(new CompoundVariable("-")); // ALL separator
-        params.add(new CompoundVariable("default"));
-        params.add(new CompoundVariable("OUTVAR"));
-        params.add(new CompoundVariable(INPUT_VARIABLE_NAME));
+        params = makeParams(
+                "(\\d+)\\s+(\\w+)",
+                "pre$1$mid$2$", // template
+                "1", // match number
+                "-", // ALL separator
+                "default",
+                "OUTVAR",
+                INPUT_VARIABLE_NAME);
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("1", vars.getObject("OUTVAR_matchNr"));
@@ -272,14 +272,14 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtractionFromVariable9() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
-        params.add(new CompoundVariable("$1$mid$2$post")); // template
-        params.add(new CompoundVariable("1")); // match number
-        params.add(new CompoundVariable("-")); // ALL separator
-        params.add(new CompoundVariable("default"));
-        params.add(new CompoundVariable("OUTVAR"));
-        params.add(new CompoundVariable(INPUT_VARIABLE_NAME));
+        params = makeParams(
+                "(\\d+)\\s+(\\w+)",
+                "$1$mid$2$post",
+                "1", // match number
+                "-", // ALL separator
+                "default",
+                "OUTVAR",
+                INPUT_VARIABLE_NAME);
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("1", vars.getObject("OUTVAR_matchNr"));
@@ -292,10 +292,10 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtraction2() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("$1$"));
-        params.add(new CompoundVariable("3"));
+        params = makeParams(
+                "<value field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "$1$",
+                "3");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("pinposition3", match);
@@ -303,11 +303,11 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtraction5() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("$1$"));
-        params.add(new CompoundVariable("ALL"));
-        params.add(new CompoundVariable("_"));
+        params = makeParams(
+                "<value field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "$1$",
+                "ALL",
+                "_");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("pinposition1_pinposition2_pinposition3", match);
@@ -315,12 +315,12 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtraction6() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("$2$"));
-        params.add(new CompoundVariable("4"));
-        params.add(new CompoundVariable(""));
-        params.add(new CompoundVariable("default"));
+        params = makeParams(
+                "<value field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "$2$",
+                "4",
+                "",
+                "default");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("default", match);
@@ -328,10 +328,10 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testComma() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value,? field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("$1$"));
-        params.add(new CompoundVariable("3"));
+        params = makeParams(
+                "<value,? field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "$1$",
+                "3");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("pinposition3", match);
@@ -339,10 +339,10 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtraction3() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("_$1$"));
-        params.add(new CompoundVariable("2"));
+        params = makeParams(
+                "<value field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "_$1$",
+                "2");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("_pinposition2", match);
@@ -350,12 +350,12 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testExtractionIndexTooHigh() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("_$1$"));
-        params.add(new CompoundVariable("10"));
-        params.add(new CompoundVariable(""));
-        params.add(new CompoundVariable("No Value Found"));
+        params = makeParams(
+                "<value field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "_$1$",
+                "10",
+                "",
+                "No Value Found");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("No Value Found", match);
@@ -363,12 +363,12 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testRandomExtraction() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<company-xmlext-query-ret>(.+?)</company-xmlext-query-ret>"));
-        params.add(new CompoundVariable("$1$"));
-        params.add(new CompoundVariable("RAND"));
-        params.add(new CompoundVariable(""));
-        params.add(new CompoundVariable("No Value Found"));
+        params = makeParams(
+                "<company-xmlext-query-ret>(.+?)</company-xmlext-query-ret>",
+                "$1$",
+                "RAND",
+                "",
+                "No Value Found");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("<row>" + "<value field=\"RetCode\">" + "LIS_OK</value><value"
@@ -382,12 +382,12 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testExtractionIndexNotNumeric() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("_$1$"));
-        params.add(new CompoundVariable("0.333a"));
-        params.add(new CompoundVariable(""));
-        params.add(new CompoundVariable("No Value Found"));
+        params = makeParams(
+                "<value field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "_$1$",
+                "0.333a",
+                "",
+                "No Value Found");
         variable.setParameters(params);
         Assertions.assertThrows(
                 Exception.class,
@@ -396,10 +396,10 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testVariableExtraction4() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("$2$, "));
-        params.add(new CompoundVariable(".333"));
+        params = makeParams(
+                "<value field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "$2$, ",
+                ".333");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("1, ", match);
@@ -407,14 +407,20 @@ public class TestRegexFunction extends JMeterTestCase {
 
     @Test
     public void testDefaultValue() throws Exception {
-        params = new LinkedList<>();
-        params.add(new CompoundVariable("<value,, field=\"(pinposition\\d+)\">(\\d+)</value>"));
-        params.add(new CompoundVariable("$2$, "));
-        params.add(new CompoundVariable(".333"));
-        params.add(new CompoundVariable(""));
-        params.add(new CompoundVariable("No Value Found"));
+        params = makeParams(
+                "<value,, field=\"(pinposition\\d+)\">(\\d+)</value>",
+                "$2$, ",
+                ".333",
+                "",
+                "No Value Found");
         variable.setParameters(params);
         String match = variable.execute(result, null);
         assertEquals("No Value Found", match);
     }
+
+    private static Collection<CompoundVariable> makeParams(String... params) {
+        return Stream.of(params)
+                .map(CompoundVariable::new)
+                .collect(Collectors.toList());
+    }
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestSamplerNameFunction.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestSamplerNameFunction.java
index 225c534d14..83680e3c27 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestSamplerNameFunction.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestSamplerNameFunction.java
@@ -17,10 +17,8 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
-
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -29,6 +27,7 @@ import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -42,32 +41,32 @@ public class TestSamplerNameFunction extends JMeterTestCase {
     private String value;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         jmctx = JMeterContextService.getContext();
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
         result = new SampleResult();
         variable = new SamplerName();
     }
 
     @Test
-    public void testSamplerName() throws Exception {
+    void testSamplerName() throws Exception {
         variable.setParameters(params);
         TestSampler sampler = new TestSampler("UnitTestSampler");
         value = variable.execute(result, sampler);
-        assertEquals("UnitTestSampler", value);
+        Assertions.assertEquals("UnitTestSampler", value);
     }
 
     @Test
-    public void testSamplerNameWithVar() throws Exception {
+    void testSamplerNameWithVar() throws Exception {
         variable.setParameters(params);
         TestSampler sampler = new TestSampler("UnitTestSampler");
         variable.setParameters(FunctionTestHelper.makeParams("var1"));
         value = variable.execute(result, sampler);
 
-        assertEquals("UnitTestSampler", value);
-        assertEquals("UnitTestSampler", vars.get("var1"));
+        Assertions.assertEquals("UnitTestSampler", value);
+        Assertions.assertEquals("UnitTestSampler", vars.get("var1"));
     }
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestSetProperty.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestSetProperty.java
index c3c80c5c15..7a1e714d81 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestSetProperty.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestSetProperty.java
@@ -19,8 +19,8 @@ package org.apache.jmeter.functions;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -52,7 +52,7 @@ public class TestSetProperty extends JMeterTestCase implements JMeterSerialTest
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestSimpleFunctions.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestSimpleFunctions.java
index 148745d2f4..579139b449 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestSimpleFunctions.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestSimpleFunctions.java
@@ -17,10 +17,8 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
-
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 import java.util.UUID;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
@@ -33,6 +31,7 @@ import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
 import org.apache.jmeter.threads.ThreadGroup;
 import org.apache.jorphan.test.JMeterSerialTest;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -52,7 +51,7 @@ public class TestSimpleFunctions extends JMeterTestCase implements JMeterSerialT
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
         Thread.currentThread().setName("ThreadGroup-1");
     }
 
@@ -103,7 +102,7 @@ public class TestSimpleFunctions extends JMeterTestCase implements JMeterSerialT
         AbstractFunction function = new ThreadNumber();
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("1", ret);
+        Assertions.assertEquals("1", ret);
     }
 
     @Test
@@ -120,7 +119,7 @@ public class TestSimpleFunctions extends JMeterTestCase implements JMeterSerialT
         params.add(new CompoundVariable("\"bread\" & \"butter\""));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("&quot;bread&quot; &amp; &quot;butter&quot;", ret);
+        Assertions.assertEquals("&quot;bread&quot; &amp; &quot;butter&quot;", ret);
     }
 
     @Test
@@ -129,7 +128,7 @@ public class TestSimpleFunctions extends JMeterTestCase implements JMeterSerialT
         params.add(new CompoundVariable("&quot;bread&quot; &amp; &quot;butter&quot;"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("\"bread\" & \"butter\"", ret);
+        Assertions.assertEquals("\"bread\" & \"butter\"", ret);
     }
 
     @Test
@@ -138,7 +137,7 @@ public class TestSimpleFunctions extends JMeterTestCase implements JMeterSerialT
         params.add(new CompoundVariable("&lt;Fran&ccedil;ais&gt;"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("<Français>", ret);
+        Assertions.assertEquals("<Français>", ret);
     }
 
     @Test
@@ -147,7 +146,7 @@ public class TestSimpleFunctions extends JMeterTestCase implements JMeterSerialT
         params.add(new CompoundVariable("&gt;&zzzz;x"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals(">&zzzz;x", ret);
+        Assertions.assertEquals(">&zzzz;x", ret);
     }
 
     @Test
@@ -156,7 +155,7 @@ public class TestSimpleFunctions extends JMeterTestCase implements JMeterSerialT
         params.add(new CompoundVariable("\"bread\" & <'butter'>"));
         function.setParameters(params);
         String ret = function.execute(result, null);
-        assertEquals("&quot;bread&quot; &amp; &lt;&apos;butter&apos;&gt;", ret);
+        Assertions.assertEquals("&quot;bread&quot; &amp; &lt;&apos;butter&apos;&gt;", ret);
     }
 
     @Test
@@ -166,7 +165,7 @@ public class TestSimpleFunctions extends JMeterTestCase implements JMeterSerialT
             FileServer.getFileServer().setScriptName("Test");
             function.setParameters(params);
             String ret = function.execute(result, null);
-            assertEquals("Test", ret);
+            Assertions.assertEquals("Test", ret);
         } finally {
             FileServer.getFileServer().setScriptName(null);
         }
@@ -183,7 +182,7 @@ public class TestSimpleFunctions extends JMeterTestCase implements JMeterSerialT
             context.setCurrentSampler(httpRequest);
             context.setThreadGroup(threadGroup);
             String ret = function.execute(result, httpRequest);
-            assertEquals("ThreadGroup-1", ret);
+            Assertions.assertEquals("ThreadGroup-1", ret);
         } finally {
             FileServer.getFileServer().setScriptName(null);
         }
@@ -199,7 +198,7 @@ public class TestSimpleFunctions extends JMeterTestCase implements JMeterSerialT
             context.setThreadGroup(null);
             context.setCurrentSampler(httpRequest);
             String ret = function.execute(result, httpRequest);
-            assertEquals("", ret);
+            Assertions.assertEquals("", ret);
         } finally {
             FileServer.getFileServer().setScriptName(null);
         }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeFunction.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeFunction.java
index 397ac72708..25ad599c2b 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeFunction.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestTimeFunction.java
@@ -17,13 +17,10 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 import java.util.Locale;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
@@ -32,10 +29,11 @@ import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-public class TestTimeFunction extends JMeterTestCase {
+class TestTimeFunction extends JMeterTestCase {
 
     private Function variable;
     private SampleResult result;
@@ -45,39 +43,45 @@ public class TestTimeFunction extends JMeterTestCase {
     private String value;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         jmctx = JMeterContextService.getContext();
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
         result = new SampleResult();
         variable = new TimeFunction();
     }
 
     @Test
-    public void testDefault() throws Exception {
+    void testDefault() throws Exception {
         variable.setParameters(params);
         long before = System.currentTimeMillis();
         value = variable.execute(result, null);
         long now = Long.parseLong(value);
         long after = System.currentTimeMillis();
-        assertTrue(now >= before && now <= after);
+        assertBetween(before, after, now);
+    }
+
+    private static void assertBetween(long expectedLow, long expectedHigh, long actual) {
+        if (actual < expectedLow || actual > expectedHigh) {
+            Assertions.fail(() -> actual + " not within " + expectedLow + " and " + expectedHigh);
+        }
     }
 
     @Test
-    public void testDefault1() throws Exception {
+    void testDefault1() throws Exception {
         params.add(new CompoundVariable());
         variable.setParameters(params);
         long before = System.currentTimeMillis();
         value = variable.execute(result, null);
         long now = Long.parseLong(value);
         long after = System.currentTimeMillis();
-        assertTrue(now >= before && now <= after);
+        assertBetween(before, after, now);
     }
 
     @Test
-    public void testDefault2() throws Exception {
+    void testDefault2() throws Exception {
         params.add(new CompoundVariable());
         params.add(new CompoundVariable());
         variable.setParameters(params);
@@ -85,20 +89,20 @@ public class TestTimeFunction extends JMeterTestCase {
         value = variable.execute(result, null);
         long now = Long.parseLong(value);
         long after = System.currentTimeMillis();
-        assertTrue(now >= before && now <= after);
+        assertBetween(before, after, now);
     }
 
     @Test
-    public void testDefaultNone() throws Exception {
+    void testDefaultNone() throws Exception {
         long before = System.currentTimeMillis();
         value = variable.execute(result, null);
         long now = Long.parseLong(value);
         long after = System.currentTimeMillis();
-        assertTrue(now >= before && now <= after);
+        assertBetween(before, after, now);
     }
 
     @Test
-    public void testTooMany() throws Exception {
+    void testTooMany() throws Exception {
         params.add(new CompoundVariable("YMD"));
         params.add(new CompoundVariable("NAME"));
         params.add(new CompoundVariable("YMD"));
@@ -106,92 +110,92 @@ public class TestTimeFunction extends JMeterTestCase {
     }
 
     @Test
-    public void testYMD() throws Exception {
+    void testYMD() throws Exception {
         params.add(new CompoundVariable("YMD"));
         params.add(new CompoundVariable("NAME"));
         variable.setParameters(params);
         value = variable.execute(result, null);
-        assertEquals(8, value.length());
-        assertEquals(value, vars.get("NAME"));
+        Assertions.assertEquals(8, value.length());
+        Assertions.assertEquals(value, vars.get("NAME"));
     }
 
     @Test
-    public void testYMDnoV() throws Exception {
+    void testYMDnoV() throws Exception {
         params.add(new CompoundVariable("YMD"));
         variable.setParameters(params);
         value = variable.execute(result, null);
-        assertEquals(8, value.length());
-        assertNull(vars.get("NAME"));
+        Assertions.assertEquals(8, value.length());
+        Assertions.assertNull(vars.get("NAME"));
     }
 
     @Test
-    public void testHMS() throws Exception {
+    void testHMS() throws Exception {
         params.add(new CompoundVariable("HMS"));
         variable.setParameters(params);
         value = variable.execute(result, null);
-        assertEquals(6, value.length());
+        Assertions.assertEquals(6, value.length());
     }
 
     @Test
-    public void testYMDHMS() throws Exception {
+    void testYMDHMS() throws Exception {
         params.add(new CompoundVariable("YMDHMS"));
         variable.setParameters(params);
         value = variable.execute(result, null);
-        assertEquals(15, value.length());
+        Assertions.assertEquals(15, value.length());
     }
 
     @Test
-    public void testUSER1() throws Exception {
+    void testUSER1() throws Exception {
         params.add(new CompoundVariable("USER1"));
         variable.setParameters(params);
         value = variable.execute(result, null);
-        assertEquals(0, value.length());
+        Assertions.assertEquals(0, value.length());
     }
 
     @Test
-    public void testUSER2() throws Exception {
+    void testUSER2() throws Exception {
         params.add(new CompoundVariable("USER2"));
         variable.setParameters(params);
         value = variable.execute(result, null);
-        assertEquals(0, value.length());
+        Assertions.assertEquals(0, value.length());
     }
 
     @Test
-    public void testFixed() throws Exception {
+    void testFixed() throws Exception {
         params.add(new CompoundVariable("'Fixed text'"));
         variable.setParameters(params);
         value = variable.execute(result, null);
-        assertEquals("Fixed text", value);
+        Assertions.assertEquals("Fixed text", value);
     }
 
     @Test
-    public void testMixed() throws Exception {
+    void testMixed() throws Exception {
         params.add(new CompoundVariable("G"));
         variable.setParameters(params);
         Locale locale = Locale.getDefault();
         Locale.setDefault(Locale.ENGLISH);
         value = variable.execute(result, null);
         Locale.setDefault(locale);
-        assertEquals("AD", value);
+        Assertions.assertEquals("AD", value);
     }
 
     @Test
-    public void testDivisor() throws Exception {
+    void testDivisor() throws Exception {
         params.add(new CompoundVariable("/1000"));
         variable.setParameters(params);
         long before = System.currentTimeMillis() / 1000;
         value = variable.execute(result, null);
         long now = Long.parseLong(value);
         long after = System.currentTimeMillis() / 1000;
-        assertTrue(now >= before && now <= after);
+        assertBetween(before, after, now);
     }
 
     @Test
-    public void testDivisorNoMatch() throws Exception {
+    void testDivisorNoMatch() throws Exception {
         params.add(new CompoundVariable("/1000 ")); // trailing space
         variable.setParameters(params);
         value = variable.execute(result, null);
-        assertEquals("/1000 ", value);
+        Assertions.assertEquals("/1000 ", value);
     }
 
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestUrlEncodeDecode.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestUrlEncodeDecode.java
index 54f6b32526..6c53f51fd2 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestUrlEncodeDecode.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestUrlEncodeDecode.java
@@ -17,10 +17,8 @@
 
 package org.apache.jmeter.functions;
 
-import static org.junit.Assert.assertEquals;
-
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -28,6 +26,7 @@ import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -39,7 +38,7 @@ public class TestUrlEncodeDecode extends JMeterTestCase {
     private JMeterContext jmctx;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         result = new SampleResult();
         jmctx = JMeterContextService.getContext();
         String data = "The quick brown fox";
@@ -47,11 +46,11 @@ public class TestUrlEncodeDecode extends JMeterTestCase {
         vars = new JMeterVariables();
         jmctx.setVariables(vars);
         jmctx.setPreviousResult(result);
-        params = new LinkedList<>();
+        params = new ArrayList<>();
     }
 
     @Test
-    public void testParameterCount() throws Exception {
+    void testParameterCount() throws Exception {
         AbstractFunction function = new UrlEncode();
         checkInvalidParameterCounts(function, 1, 1);
 
@@ -60,20 +59,20 @@ public class TestUrlEncodeDecode extends JMeterTestCase {
     }
 
     @Test
-    public void testUrlEncode() throws Exception {
+    void testUrlEncode() throws Exception {
         AbstractFunction function = new UrlEncode();
         params.add(new CompoundVariable("Veni, vidi, vici ?"));
         function.setParameters(params);
         String returnValue = function.execute(result, null);
-        assertEquals("Veni%2C+vidi%2C+vici+%3F", returnValue);
+        Assertions.assertEquals("Veni%2C+vidi%2C+vici+%3F", returnValue);
     }
 
     @Test
-    public void testUrlDecode() throws Exception {
+    void testUrlDecode() throws Exception {
         AbstractFunction function = new UrlDecode();
         params.add(new CompoundVariable("Veni%2C+vidi%2C+vici+%3F"));
         function.setParameters(params);
         String returnValue = function.execute(result, null);
-        assertEquals("Veni, vidi, vici ?", returnValue);
+        Assertions.assertEquals("Veni, vidi, vici ?", returnValue);
     }
 }
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/util/TestHTTPFileArgs.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/util/TestHTTPFileArgs.java
index 9d6e30c427..fb8c4ec254 100644
--- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/util/TestHTTPFileArgs.java
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/util/TestHTTPFileArgs.java
@@ -19,7 +19,7 @@ package org.apache.jmeter.protocol.http.util;
 
 import static org.junit.Assert.assertEquals;
 
-import java.util.LinkedList;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.jmeter.testelement.property.PropertyIterator;
@@ -56,7 +56,7 @@ public class TestHTTPFileArgs {
 
     @Test
     public void testSetHTTPFileArgs() throws Exception {
-        List<HTTPFileArg> newHTTPFileArgs = new LinkedList<>();
+        List<HTTPFileArg> newHTTPFileArgs = new ArrayList<>();
         newHTTPFileArgs.add(new HTTPFileArg("hede"));
         HTTPFileArgs files = new HTTPFileArgs();
         files.setHTTPFileArgs(newHTTPFileArgs);


[jmeter] 13/16: Suppress warnings about old date API

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 522b86aa89399b52ff9b2e89ba4be64a016ca638
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 17:22:52 2022 +0200

    Suppress warnings about old date API
    
    we have to use it here.
---
 src/jorphan/src/test/java/org/apache/jorphan/util/TestConverter.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/jorphan/src/test/java/org/apache/jorphan/util/TestConverter.java b/src/jorphan/src/test/java/org/apache/jorphan/util/TestConverter.java
index 2165b50992..adeef4002d 100644
--- a/src/jorphan/src/test/java/org/apache/jorphan/util/TestConverter.java
+++ b/src/jorphan/src/test/java/org/apache/jorphan/util/TestConverter.java
@@ -65,14 +65,14 @@ public class TestConverter {
     }
 
     @Test
-    @SuppressWarnings({ "UndefinedEquals", "JdkObsolete" })
+    @SuppressWarnings({ "UndefinedEquals", "JavaUtilDate" })
     public void testGetDateObjectDateWithTimeAndNullDefault() {
         Date time = new Date();
         assertEquals(time, Converter.getDate(time, null));
     }
 
     @Test
-    @SuppressWarnings({ "UndefinedEquals", "JdkObsolete" })
+    @SuppressWarnings({ "UndefinedEquals", "JavaUtilDate" })
     public void testGetDateObjectDateWithNullAndDateAsDefault() {
         Date date = new Date();
         assertEquals(date, Converter.getDate(null, date));


[jmeter] 07/16: Remove unused variable

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 32b03e9334a480fb2ef571bcbdf31168a339ac51
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 16:49:13 2022 +0200

    Remove unused variable
    
    Specify charset, when none is given and use isEmpty.
---
 .../PreciseThroughputTimerTest.java                |  3 ---
 .../org/apache/jmeter/resources/PackageTest.java   | 26 +++++++---------------
 2 files changed, 8 insertions(+), 21 deletions(-)

diff --git a/src/components/src/test/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimerTest.java b/src/components/src/test/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimerTest.java
index ed5e973413..d6358fc40b 100644
--- a/src/components/src/test/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimerTest.java
+++ b/src/components/src/test/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimerTest.java
@@ -25,11 +25,8 @@ import java.util.Arrays;
 import java.util.Random;
 
 import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class PreciseThroughputTimerTest {
-    private static final Logger LOG = LoggerFactory.getLogger(PreciseThroughputTimerTest.class);
 
     @Test
     public void testTimer1() throws Exception {
diff --git a/src/core/src/test/java/org/apache/jmeter/resources/PackageTest.java b/src/core/src/test/java/org/apache/jmeter/resources/PackageTest.java
index 116a27acd6..744cb69c8f 100644
--- a/src/core/src/test/java/org/apache/jmeter/resources/PackageTest.java
+++ b/src/core/src/test/java/org/apache/jmeter/resources/PackageTest.java
@@ -23,8 +23,7 @@ import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -67,20 +66,12 @@ import junit.framework.TestSuite;
 
 public class PackageTest extends TestCase implements Describable {
     // We assume the test starts in "src/core" directory (which is true for Gradle and IDEs)
-    private static final File srcFiledir = new File("src/main/java");
     private static final File resourceFiledir = new File("src/main/resources");
 
     private static final String MESSAGES = "messages";
 
     private static PropertyResourceBundle defaultPRB; // current default language properties file
 
-    private static final CharsetEncoder ASCII_ENCODER =
-        Charset.forName("US-ASCII").newEncoder(); // Ensure properties files don't use special characters
-
-    private static boolean isPureAscii(String v) {
-      return ASCII_ENCODER.canEncode(v);
-    }
-
     // Read resource into ResourceBundle and store in List
     private PropertyResourceBundle getRAS(String res) throws Exception {
         InputStream ras = this.getClass().getResourceAsStream(res);
@@ -97,16 +88,16 @@ public class PackageTest extends TestCase implements Describable {
     private void readRF(String res, List<String> l) throws Exception {
         InputStream ras = this.getClass().getResourceAsStream(res);
         if (ras == null){
-            if (MESSAGES.equals(resourcePrefix)|| lang.length() == 0 ) {
+            if (MESSAGES.equals(resourcePrefix)|| lang.isEmpty()) {
                 throw new IOException("Cannot open resource file "+res);
             } else {
                 return;
             }
         }
-        try (BufferedReader fileReader = new BufferedReader(new InputStreamReader(ras));) {
+        try (BufferedReader fileReader = new BufferedReader(new InputStreamReader(ras, StandardCharsets.UTF_8))) {
             String s;
             while ((s = fileReader.readLine()) != null) {
-                if (s.length() > 0 && !s.startsWith("#") && !s.startsWith("!")) {
+                if (!s.isEmpty() && !s.startsWith("#") && !s.startsWith("!")) {
                     int equ = s.indexOf('=');
                     String key = s.substring(0, equ);
                     if (resourcePrefix.equals(MESSAGES)){// Only relevant for messages
@@ -147,7 +138,7 @@ public class PackageTest extends TestCase implements Describable {
 
     // Helper method to construct resource name
     private String getResName(String lang) {
-        if (lang.length() == 0) {
+        if (lang.isEmpty()) {
             return resourcePrefix+".properties";
         } else {
             return resourcePrefix+"_" + lang + ".properties";
@@ -177,7 +168,7 @@ public class PackageTest extends TestCase implements Describable {
             last = curr;
         }
 
-        if (resname.length() == 0) // Must be the default resource file
+        if (resname.isEmpty()) // Must be the default resource file
         {
             defaultPRB = getRAS(res);
             if (defaultPRB == null){
@@ -325,15 +316,14 @@ public class PackageTest extends TestCase implements Describable {
         for (String prefix : prefixList) {
             Properties messages = new Properties();
             messages.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(prefix.substring(1)+".properties"));
-            checkMessagesForLanguage( missingLabelsPerBundle , missingLabelsPerBundle, messages,prefix.substring(1), lang);
+            checkMessagesForLanguage( missingLabelsPerBundle , messages,prefix.substring(1), lang);
         }
 
         assertEquals(missingLabelsPerBundle.size()+" missing labels, labels missing:"+printLabels(missingLabelsPerBundle), 0, missingLabelsPerBundle.size());
     }
 
     private void checkMessagesForLanguage(Map<String, Map<String, String>> missingLabelsPerBundle,
-            Map<String, Map<String, String>> missingLabelsPerBundle2,
-            Properties messages, String bundlePath, String language)
+                                          Properties messages, String bundlePath, String language)
             throws IOException {
         Properties messagesFr = new Properties();
         String languageBundle = bundlePath+"_"+language+ ".properties";


[jmeter] 02/16: Get rid of error prone warnings because of missing explicit default character encoding

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 1e93c67a59673fe4d71a3a710c80bb485965b355
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 15:46:26 2022 +0200

    Get rid of error prone warnings because of missing explicit default character encoding
    
    While we are in the sources, use try-with, isEmpty and other minor clean-ups.
    Don't encode ASCII printable characters as unicode sequences, as they are
    decoded by Java anyway and are obfuscating the code unnecessarily.
    Remove unused method variables and parameters, when possible.
    Use ArrayList instead of LinkedList, when possible (more will follow).
---
 .../jmeter/assertions/TestJSONPathAssertion.java   | 40 ++++++++++++----------
 .../jmeter/assertions/XMLSchemaAssertionTest.java  | 31 ++++++++++-------
 .../test/java/org/apache/jmeter/JMeterTest.java    | 11 ++++--
 .../apache/jmeter/junit/JMeterTestCaseJUnit.java   |  4 +--
 .../jmeter/resources/ResourceKeyUsageTest.java     |  6 ++--
 .../org/apache/jmeter/save/TestSaveService.java    | 10 +++---
 .../protocol/http/control/TestAuthManager.java     | 12 +++++--
 .../protocol/http/proxy/TestHttpRequestHdr.java    | 23 ++++++-------
 .../protocol/http/sampler/PostWriterTest.java      | 22 +++++++-----
 .../TestHTTPSamplersAgainstHttpMirrorServer.java   |  7 ++--
 10 files changed, 97 insertions(+), 69 deletions(-)

diff --git a/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java b/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java
index 125662f790..e9349efb1e 100644
--- a/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java
+++ b/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java
@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import java.nio.charset.Charset;
 import java.util.Locale;
 
 import org.apache.jmeter.samplers.SampleResult;
@@ -86,7 +87,7 @@ class TestJSONPathAssertion {
     }, delimiterString=";")
     void testGetResult_pathsWithOneResult(String data, String jsonPath, String expectedResult) {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData(data.getBytes());
+        samplerResult.setResponseData(data.getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath(jsonPath);
@@ -101,7 +102,7 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_positive_regexp() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": 123}".getBytes());
+        samplerResult.setResponseData("{\"myval\": 123}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval");
@@ -112,7 +113,7 @@ class TestJSONPathAssertion {
         assertEquals(expResult.getName(), result.getName());
         assertFalse(result.isFailure());
 
-        samplerResult.setResponseData("{\"myval\": 456}".getBytes());
+        samplerResult.setResponseData("{\"myval\": 456}".getBytes(Charset.defaultCharset()));
         AssertionResult result2 = instance.getResult(samplerResult);
         assertFalse(result2.isFailure());
     }
@@ -120,7 +121,7 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_positive_invert() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": 123}".getBytes());
+        samplerResult.setResponseData("{\"myval\": 123}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval");
@@ -136,7 +137,7 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_not_regexp() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": \"some complicated value\"}".getBytes());
+        samplerResult.setResponseData("{\"myval\": \"some complicated value\"}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval");
@@ -153,7 +154,8 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_complex_map() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": { \"a\": 23, \"b\": 42, \"c\": \"something\" } }".getBytes());
+        samplerResult.setResponseData(
+                "{\"myval\": { \"a\": 23, \"b\": 42, \"c\": \"something\" } }".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval");
@@ -167,7 +169,7 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_negative() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": 123}".getBytes());
+        samplerResult.setResponseData("{\"myval\": 123}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval");
@@ -182,7 +184,7 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_negative_invert() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": 123}".getBytes());
+        samplerResult.setResponseData("{\"myval\": 123}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval");
@@ -198,7 +200,7 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_null() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": null}".getBytes());
+        samplerResult.setResponseData("{\"myval\": null}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval");
@@ -213,7 +215,7 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_null_not_found() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": 123}".getBytes());
+        samplerResult.setResponseData("{\"myval\": 123}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval");
@@ -228,7 +230,7 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_null_novalidate() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": null}".getBytes());
+        samplerResult.setResponseData("{\"myval\": null}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval");
@@ -242,7 +244,7 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_no_such_path() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": null}".getBytes());
+        samplerResult.setResponseData("{\"myval\": null}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.notexist");
@@ -256,7 +258,8 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_list_negative() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": [{\"test\":1},{\"test\":2},{\"test\":3}]}".getBytes());
+        samplerResult.setResponseData(
+                "{\"myval\": [{\"test\":1},{\"test\":2},{\"test\":3}]}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval[*].test");
@@ -274,7 +277,7 @@ class TestJSONPathAssertion {
         // we now consider an indefinite path with no assertion value
         // an error and set the AssertionResult to failure
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": []}".getBytes());
+        samplerResult.setResponseData("{\"myval\": []}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval[*]");
@@ -288,7 +291,7 @@ class TestJSONPathAssertion {
     @Test
     void testGetResult_inverted_null() {
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": [{\"key\": null}]}".getBytes());
+        samplerResult.setResponseData("{\"myval\": [{\"key\": null}]}".getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.myval[*].key");
@@ -305,7 +308,7 @@ class TestJSONPathAssertion {
     void testGetResult_match_msg_problem() {
         SampleResult samplerResult = new SampleResult();
         String str = "{\"execution\":[{\"scenario\":{\"requests\":[{\"headers\":{\"headerkey\":\"header value\"}}]}}]}";
-        samplerResult.setResponseData(str.getBytes());
+        samplerResult.setResponseData(str.getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.execution[0].scenario.requests[0].headers");
@@ -338,7 +341,7 @@ class TestJSONPathAssertion {
                 "   }\n" +
                 " }\n" +
                 "}";
-        samplerResult.setResponseData(str.getBytes());
+        samplerResult.setResponseData(str.getBytes(Charset.defaultCharset()));
 
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath("$.contact.info.ngn_number");
@@ -361,7 +364,8 @@ class TestJSONPathAssertion {
             Locale.setDefault(Locale.US);
             SampleResult samplerResult = new SampleResult();
 
-            samplerResult.setResponseData("{\"myval\": [{\"test\":0.0000123456789}]}".getBytes());
+            samplerResult.setResponseData(
+                    "{\"myval\": [{\"test\":0.0000123456789}]}".getBytes(Charset.defaultCharset()));
 
             JSONPathAssertion instance = new JSONPathAssertion();
             instance.setJsonPath("$.myval[*].test");
diff --git a/src/components/src/test/java/org/apache/jmeter/assertions/XMLSchemaAssertionTest.java b/src/components/src/test/java/org/apache/jmeter/assertions/XMLSchemaAssertionTest.java
index ca3143734f..236625a1b5 100644
--- a/src/components/src/test/java/org/apache/jmeter/assertions/XMLSchemaAssertionTest.java
+++ b/src/components/src/test/java/org/apache/jmeter/assertions/XMLSchemaAssertionTest.java
@@ -25,6 +25,7 @@ import java.io.BufferedInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.jmeter.junit.JMeterTestCase;
 import org.apache.jmeter.samplers.SampleResult;
@@ -52,19 +53,21 @@ public class XMLSchemaAssertionTest extends JMeterTestCase {
     }
 
     private ByteArrayOutputStream readBA(String name) throws IOException {
-        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(findTestFile(name)));
         ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
-        int len = 0;
-        byte[] data = new byte[512];
-        while ((len = bis.read(data)) >= 0) {
-            baos.write(data, 0, len);
+        try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(findTestFile(name)))) {
+            int len = 0;
+            byte[] data = new byte[512];
+            while ((len = bis.read(data)) >= 0) {
+                baos.write(data, 0, len);
+            }
         }
-        bis.close();
         return baos;
     }
 
     private byte[] readFile(String name) throws IOException {
-        return readBA(name).toByteArray();
+        try (ByteArrayOutputStream baos = readBA(name)) {
+            return baos.toByteArray();
+        }
     }
 
     @Test
@@ -151,9 +154,10 @@ public class XMLSchemaAssertionTest extends JMeterTestCase {
 
     @Test
     public void testXMLTrailingContent() throws Exception {
-        ByteArrayOutputStream baos = readBA("testfiles/XMLSchematest.xml");
-        baos.write("extra".getBytes()); // TODO - charset?
-        result.setResponseData(baos.toByteArray());
+        try (ByteArrayOutputStream baos = readBA("testfiles/XMLSchematest.xml")) {
+            baos.write("extra".getBytes(StandardCharsets.UTF_8));
+            result.setResponseData(baos.toByteArray());
+        }
         assertion.setXsdFileName(findTestPath("testfiles/XMLSchema-pass.xsd"));
         AssertionResult res = assertion.getResult(jmctx.getPreviousResult());
         testLog.debug("isError() " + res.isError() + " isFailure() " + res.isFailure());
@@ -165,9 +169,10 @@ public class XMLSchemaAssertionTest extends JMeterTestCase {
 
     @Test
     public void testXMLTrailingWhitespace() throws Exception {
-        ByteArrayOutputStream baos = readBA("testfiles/XMLSchematest.xml");
-        baos.write(" \t\n".getBytes()); // TODO - charset?
-        result.setResponseData(baos.toByteArray());
+        try (ByteArrayOutputStream baos = readBA("testfiles/XMLSchematest.xml")) {
+            baos.write(" \t\n".getBytes(StandardCharsets.UTF_8));
+            result.setResponseData(baos.toByteArray());
+        }
         assertion.setXsdFileName(findTestPath("testfiles/XMLSchema-pass.xsd"));
         AssertionResult res = assertion.getResult(jmctx.getPreviousResult());
         testLog.debug("xisError() " + res.isError() + " isFailure() " + res.isFailure());
diff --git a/src/core/src/test/java/org/apache/jmeter/JMeterTest.java b/src/core/src/test/java/org/apache/jmeter/JMeterTest.java
index b70e5a29dc..77fec89f51 100644
--- a/src/core/src/test/java/org/apache/jmeter/JMeterTest.java
+++ b/src/core/src/test/java/org/apache/jmeter/JMeterTest.java
@@ -22,8 +22,11 @@ import static org.junit.Assert.fail;
 
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.jmeter.junit.JMeterTestCase;
 import org.apache.jmeter.report.config.ConfigurationException;
@@ -59,7 +62,8 @@ public class JMeterTest extends JMeterTestCase implements JMeterSerialTest {
                 + "        <collectionProp name=\"Arguments.arguments\"/>\n" + "      </elementProp>\n"
                 + "      <stringProp name=\"TestPlan.user_define_classpath\"></stringProp></TestPlan>"
                 + "    <hashTree/></hashTree></jmeterTestPlan>";
-        try (FileWriter fw = new FileWriter(temp);
+        try (FileOutputStream os = new FileOutputStream(temp);
+                Writer fw = new OutputStreamWriter(os, StandardCharsets.UTF_8);
                 BufferedWriter out = new BufferedWriter(fw)) {
             out.write(testPlan);
         }
@@ -102,7 +106,8 @@ public class JMeterTest extends JMeterTestCase implements JMeterSerialTest {
                 + "          <stringProp name=\"CONNECT\">${__Random(1,5)}</stringProp>\n"
                 + "        </kg.apc.jmeter.samplers.DummySampler></hashTree></hashTree>\n"
                 + "  </hashTree></jmeterTestPlan><hashTree/></hashTree>\n" + "</jmeterTestPlan>";
-        try (FileWriter fw = new FileWriter(temp);
+        try (FileOutputStream os = new FileOutputStream(temp);
+                Writer fw = new OutputStreamWriter(os, StandardCharsets.UTF_8);
                 BufferedWriter out = new BufferedWriter(fw)) {
             out.write(testPlan);
         }
diff --git a/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCaseJUnit.java b/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCaseJUnit.java
index 41b2f146ee..a653f95cab 100644
--- a/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCaseJUnit.java
+++ b/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCaseJUnit.java
@@ -21,8 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.File;
 import java.nio.charset.Charset;
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
 import java.util.Locale;
 import java.util.MissingResourceException;
 
@@ -110,7 +110,7 @@ public abstract class JMeterTestCaseJUnit extends TestCase {
 
     protected void checkInvalidParameterCounts(AbstractFunction func, int minimum)
             throws Exception {
-        Collection<CompoundVariable> parms = new LinkedList<>();
+        Collection<CompoundVariable> parms = new ArrayList<>();
         for (int c = 0; c < minimum; c++) {
             assertThrows(InvalidVariableException.class, () -> func.setParameters(parms));
             parms.add(new CompoundVariable());
diff --git a/src/core/src/test/java/org/apache/jmeter/resources/ResourceKeyUsageTest.java b/src/core/src/test/java/org/apache/jmeter/resources/ResourceKeyUsageTest.java
index eb9551a643..b9af52655f 100644
--- a/src/core/src/test/java/org/apache/jmeter/resources/ResourceKeyUsageTest.java
+++ b/src/core/src/test/java/org/apache/jmeter/resources/ResourceKeyUsageTest.java
@@ -26,6 +26,7 @@ import java.io.FileReader;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.MissingResourceException;
@@ -51,6 +52,7 @@ public class ResourceKeyUsageTest {
 
     // Check that calls to getResString use a valid property key name
     @Test
+    @SuppressWarnings("CatchAndPrintStackTrace")
     public void checkResourceReferences() throws Exception {
         String resourceName = "/org/apache/jmeter/resources/messages.properties";
         PropertyResourceBundle messagePRB = getRAS(resourceName);
@@ -66,7 +68,7 @@ public class ResourceKeyUsageTest {
                 if (name.endsWith(".java")) {
                   BufferedReader fileReader = null;
                   try {
-                    fileReader = new BufferedReader(new FileReader(file));
+                    fileReader = new BufferedReader(new FileReader(file, StandardCharsets.UTF_8));
                     String s;
                     while ((s = fileReader.readLine()) != null) {
                         if (s.matches("\\s*//.*")) { // leading comment
@@ -89,7 +91,7 @@ public class ResourceKeyUsageTest {
                         }
                     }
                 } catch (IOException e) {
-                    e.printStackTrace();
+                      e.printStackTrace();
                 } finally {
                     JOrphanUtils.closeQuietly(fileReader);
                 }
diff --git a/src/dist-check/src/test/java/org/apache/jmeter/save/TestSaveService.java b/src/dist-check/src/test/java/org/apache/jmeter/save/TestSaveService.java
index 8c654e9e6c..9b44acc7d7 100644
--- a/src/dist-check/src/test/java/org/apache/jmeter/save/TestSaveService.java
+++ b/src/dist-check/src/test/java/org/apache/jmeter/save/TestSaveService.java
@@ -25,12 +25,13 @@ import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.nio.charset.Charset;
 import java.util.List;
 
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -128,8 +129,8 @@ public class TestSaveService extends JMeterTestCase {
 
         final FileStats outputStats;
         try (ByteArrayInputStream ins = new ByteArrayInputStream(out.toByteArray());
-                Reader insReader = new InputStreamReader(ins);
-                BufferedReader bufferedReader = new BufferedReader(insReader)) {
+             Reader insReader = new InputStreamReader(ins, Charset.defaultCharset());
+             BufferedReader bufferedReader = new BufferedReader(insReader)) {
             outputStats = computeFileStats(bufferedReader);
         }
         // We only check the length of the result. Comparing the
@@ -167,7 +168,8 @@ public class TestSaveService extends JMeterTestCase {
         if (testFile == null || !testFile.exists()) {
             return FileStats.NO_STATS;
         }
-        try (FileReader fileReader = new FileReader(testFile);
+        try (FileInputStream fis = new FileInputStream(testFile);
+             InputStreamReader fileReader = new InputStreamReader(fis, Charset.defaultCharset());
                 BufferedReader bufferedReader = new BufferedReader(fileReader)) {
             return computeFileStats(bufferedReader);
         }
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthManager.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthManager.java
index e3b41ab9b9..eee4a21257 100644
--- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthManager.java
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthManager.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.nio.charset.Charset;
 import java.nio.file.Files;
 
 import org.apache.jmeter.junit.JMeterTestCase;
@@ -88,7 +89,8 @@ public class TestAuthManager extends JMeterTestCase {
     @Test
     public void testAddFileWithoutDomainAndRealmWithMechanism() throws IOException {
         File authFile = File.createTempFile("auth", ".txt");
-        Files.write(authFile.toPath(), "http://example.com\tuser\tpassword\t\t\tBASIC_DIGEST".getBytes());
+        Files.write(authFile.toPath(),
+                "http://example.com\tuser\tpassword\t\t\tBASIC_DIGEST".getBytes(Charset.defaultCharset()));
         AuthManager manager = new AuthManager();
         manager.addFile(authFile.getAbsolutePath());
         Authorization authForURL = manager.getAuthForURL(new URL("http://example.com"));
@@ -98,7 +100,9 @@ public class TestAuthManager extends JMeterTestCase {
     @Test
     public void testAddFileWithDomainAndRealmAndDefaultMechanism() throws IOException {
         File authFile = File.createTempFile("auth", ".txt");
-        Files.write(authFile.toPath(), "http://example.com\tuser\tpassword\tdomain\tEXAMPLE.COM\tBASIC_DIGEST".getBytes());
+        Files.write(authFile.toPath(),
+                "http://example.com\tuser\tpassword\tdomain\tEXAMPLE.COM\tBASIC_DIGEST"
+                        .getBytes(Charset.defaultCharset()));
         AuthManager manager = new AuthManager();
         manager.addFile(authFile.getAbsolutePath());
         Authorization authForURL = manager.getAuthForURL(new URL("http://example.com"));
@@ -109,7 +113,9 @@ public class TestAuthManager extends JMeterTestCase {
     @Test
     public void testAddFileWithDomainAndRealmAndMechanism() throws IOException {
         File authFile = File.createTempFile("auth", ".txt");
-        Files.write(authFile.toPath(), "http://example.com\tuser\tpassword\tdomain\tEXAMPLE.COM\tKERBEROS".getBytes());
+        Files.write(authFile.toPath(),
+                "http://example.com\tuser\tpassword\tdomain\tEXAMPLE.COM\tKERBEROS"
+                        .getBytes(Charset.defaultCharset()));
         AuthManager manager = new AuthManager();
         manager.addFile(authFile.getAbsolutePath());
         Authorization authForURL = manager.getAuthForURL(new URL("http://example.com"));
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java
index 82c5b46bcf..bbfc09e3d2 100644
--- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.net.URLEncoder;
+import java.nio.charset.Charset;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -328,7 +329,7 @@ public class TestHttpRequestHdr extends JMeterTestCase {
         // A HTTP GET request, with UTF-8 encoding
         contentEncoding = "UTF-8";
         param1Value = "yes";
-        param2Value = "0+5 -\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85";
+        param2Value = "0+5 -|\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85";
         param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);
         testGetRequest =
             "GET " + url
@@ -394,7 +395,7 @@ public class TestHttpRequestHdr extends JMeterTestCase {
         // A HTTP POST request, with UTF-8 encoding
         contentEncoding = "UTF-8";
         param1Value = "yes";
-        param2Value = "0+5 -\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85";
+        param2Value = "0+5 -|\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85";
         param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);
         postBody = "param1=" + param1Value + "&param2=" + param2ValueEncoded + "\r\n";
         testPostRequest =
@@ -525,10 +526,9 @@ public class TestHttpRequestHdr extends JMeterTestCase {
     @Test
     public void testParse1() throws Exception {// no space after :
         HttpRequestHdr req = new HttpRequestHdr();
-        ByteArrayInputStream bis = null;
-        bis = new ByteArrayInputStream("GET xxx HTTP/1.0\r\nname:value \r\n".getBytes("ISO-8859-1"));
-        req.parse(bis);
-        bis.close();
+        try (ByteArrayInputStream bis = new ByteArrayInputStream("GET xxx HTTP/1.0\r\nname:value \r\n".getBytes("ISO-8859-1"))) {
+            req.parse(bis);
+        }
         HeaderManager mgr = req.getHeaderManager();
         Header header;
         mgr.getHeaders();
@@ -541,10 +541,9 @@ public class TestHttpRequestHdr extends JMeterTestCase {
     @Test
     public void testParse2() throws Exception {// spaces after :
         HttpRequestHdr req = new HttpRequestHdr();
-        ByteArrayInputStream bis = null;
-        bis = new ByteArrayInputStream("GET xxx HTTP/1.0\r\nname:           value \r\n".getBytes("ISO-8859-1"));
-        req.parse(bis);
-        bis.close();
+        try (ByteArrayInputStream bis = new ByteArrayInputStream("GET xxx HTTP/1.0\r\nname:           value \r\n".getBytes("ISO-8859-1"))) {
+            req.parse(bis);
+        }
         HeaderManager mgr = req.getHeaderManager();
         Header header;
         mgr.getHeaders();
@@ -679,12 +678,12 @@ public class TestHttpRequestHdr extends JMeterTestCase {
     }
 
     private int getBodyLength(String postBody, String contentEncoding) throws IOException {
-        if(contentEncoding != null && contentEncoding.length() > 0) {
+        if(contentEncoding != null && !contentEncoding.isEmpty()) {
             return postBody.getBytes(contentEncoding).length;
         }
         else {
             // Most browsers use ISO-8859-1 as default encoding, even if spec says UTF-8
-            return postBody.getBytes().length; // TODO - charset?
+            return postBody.getBytes(Charset.defaultCharset()).length; // TODO - charset?
         }
     }
 }
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/PostWriterTest.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/PostWriterTest.java
index e771aefb55..8de0d14c69 100644
--- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/PostWriterTest.java
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/PostWriterTest.java
@@ -32,6 +32,8 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -68,7 +70,8 @@ public class PostWriterTest {
         postWriter=new PostWriter();
 
         // Create the test file content
-        TEST_FILE_CONTENT = "foo content &?=01234+56789-\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052".getBytes(UTF_8);
+        TEST_FILE_CONTENT = "foo content &?=01234+56789-|\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052"
+                .getBytes(UTF_8);
 
         // create a temporary file to make sure we always have a file to give to the PostWriter
         // Whereever we are or Whatever the current path is.
@@ -176,7 +179,7 @@ public class PostWriterTest {
         postWriter.sendPostData(connection, sampler);
 
         checkNoContentType(connection);
-        byte[] expectedUrl = "title=mytitle&description=mydescription".getBytes(); // TODO - charset?
+        byte[] expectedUrl = "title=mytitle&description=mydescription".getBytes(StandardCharsets.UTF_8);
         checkContentLength(connection, expectedUrl.length);
         checkArraysHaveSameContent(expectedUrl, connection.getOutputStreamContent());
         expectedUrl = "title=mytitle&description=mydescription".getBytes(UTF_8);
@@ -238,7 +241,7 @@ public class PostWriterTest {
         checkContentLength(connection, TEST_FILE_CONTENT.length);
         checkArraysHaveSameContent(TEST_FILE_CONTENT, connection.getOutputStreamContent());
         // Check that other encoding is not the current encoding
-        checkArraysHaveDifferentContent(new String(TEST_FILE_CONTENT) // TODO - charset?
+        checkArraysHaveDifferentContent(new String(TEST_FILE_CONTENT, Charset.defaultCharset()) // TODO - charset?
             .getBytes(otherEncoding), connection.getOutputStreamContent());
 
         // If we have both file as body, and form data, then only form data will be sent
@@ -249,7 +252,8 @@ public class PostWriterTest {
         postWriter.sendPostData(connection, sampler);
 
         checkNoContentType(connection);
-        byte[] expectedUrl = "title=mytitle&description=mydescription".getBytes(); // TODO - charset?
+        byte[] expectedUrl = "title=mytitle&description=mydescription"
+                .getBytes(Charset.defaultCharset()); // TODO - charset?
         checkContentLength(connection, expectedUrl.length);
         checkArraysHaveSameContent(expectedUrl, connection.getOutputStreamContent());
     }
@@ -619,11 +623,11 @@ public class PostWriterTest {
 
     /** setup commons parts of HTTPSampler with a no filename. */
     private void setupNoFilename(HTTPSampler httpSampler) {
-        setupFilepart(sampler, "upload", null, "application/octet-stream");
+        setupFilepart(httpSampler, "upload", null, "application/octet-stream");
     }
 
     private void setupFilepart(HTTPSampler httpSampler) {
-        setupFilepart(sampler, "upload", temporaryFile, "text/plain");
+        setupFilepart(httpSampler, "upload", temporaryFile, "text/plain");
     }
 
     private void setupFilepart(HTTPSampler httpSampler, String fileField, File file, String mimeType) {
@@ -636,7 +640,7 @@ public class PostWriterTest {
     }
 
     private void setupFormData(HTTPSampler httpSampler, String titleValue, String descriptionValue) {
-        setupFormData(sampler, false, titleValue, descriptionValue);
+        setupFormData(httpSampler, false, titleValue, descriptionValue);
     }
 
     private void setupFormData(HTTPSampler httpSampler, boolean isEncoded, String titleValue, String descriptionValue) {
@@ -740,7 +744,7 @@ public class PostWriterTest {
             output.write(titleValue.getBytes(contentEncoding));
         }
         else {
-            output.write(titleValue.getBytes()); // TODO - charset?
+            output.write(titleValue.getBytes(Charset.defaultCharset())); // TODO - charset?
         }
         output.write(CRLF);
         output.write(DASH_DASH);
@@ -762,7 +766,7 @@ public class PostWriterTest {
             output.write(descriptionValue.getBytes(contentEncoding));
         }
         else {
-            output.write(descriptionValue.getBytes()); // TODO - charset?
+            output.write(descriptionValue.getBytes(Charset.defaultCharset())); // TODO - charset?
         }
         output.write(CRLF);
         output.write(DASH_DASH);
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
index 9b4e0a3801..1ca676f0c6 100644
--- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
@@ -25,6 +25,7 @@ import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLEncoder;
+import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.Locale;
 import java.util.regex.Matcher;
@@ -117,7 +118,7 @@ public class TestHTTPSamplersAgainstHttpMirrorServer extends JMeterTestCaseJUnit
             protected void setUp() throws Exception {
                 httpServer = TestHTTPMirrorThread.startHttpMirror(MIRROR_PORT);
                 // Create the test file content
-                TEST_FILE_CONTENT = "some foo content &?=01234+56789-\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85"
+                TEST_FILE_CONTENT = "some foo content &?=01234+56789-|\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85"
                         .getBytes(StandardCharsets.UTF_8);
 
                 // create a temporary file to make sure we always have a file to give to the PostWriter
@@ -1457,7 +1458,7 @@ public class TestHTTPSamplersAgainstHttpMirrorServer extends JMeterTestCaseJUnit
         if (contentEncoding != null) {
             output.write(titleValue.getBytes(contentEncoding));
         } else {
-            output.write(titleValue.getBytes()); // TODO - charset?
+            output.write(titleValue.getBytes(Charset.defaultCharset())); // TODO - charset?
         }
         output.write(CRLF);
         output.write(DASH_DASH);
@@ -1479,7 +1480,7 @@ public class TestHTTPSamplersAgainstHttpMirrorServer extends JMeterTestCaseJUnit
         if (contentEncoding != null) {
             output.write(descriptionValue.getBytes(contentEncoding));
         } else {
-            output.write(descriptionValue.getBytes()); // TODO - charset?
+            output.write(descriptionValue.getBytes(Charset.defaultCharset())); // TODO - charset?
         }
         output.write(CRLF);
         output.write(DASH_DASH);


[jmeter] 06/16: Get rid of warning about converting long to float

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 1527a8fcb1c96b2270d215775687443dfadc480d
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 16:42:41 2022 +0200

    Get rid of warning about converting long to float
    
    by introducing a new private assertion method.
    While we are here, convert to junit5 and add another assertion method
    to check vor valid range.
---
 .../jmeter/timers/ConstantThroughputTimerTest.java |  91 ++++++------
 .../apache/jmeter/samplers/TestSampleResult.java   | 160 +++++++++++----------
 2 files changed, 130 insertions(+), 121 deletions(-)

diff --git a/src/components/src/test/java/org/apache/jmeter/timers/ConstantThroughputTimerTest.java b/src/components/src/test/java/org/apache/jmeter/timers/ConstantThroughputTimerTest.java
index f8c8df1391..a55b4bae4a 100644
--- a/src/components/src/test/java/org/apache/jmeter/timers/ConstantThroughputTimerTest.java
+++ b/src/components/src/test/java/org/apache/jmeter/timers/ConstantThroughputTimerTest.java
@@ -17,32 +17,26 @@
 
 package org.apache.jmeter.timers;
 
-import static org.junit.Assert.assertEquals;
-
 import java.util.UUID;
 
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.TestJMeterContextService;
 import org.apache.jmeter.util.BeanShellInterpreter;
 import org.apache.jmeter.util.ScriptingTestElement;
-import org.junit.Assert;
-import org.junit.Assume;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Assumptions;
 import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ConstantThroughputTimerTest {
 
-    private static final Logger log = LoggerFactory.getLogger(ConstantThroughputTimerTest.class);
+class ConstantThroughputTimerTest {
 
     @Test
-    public void testTimer1() throws Exception {
+    void testTimer1() throws Exception {
         ConstantThroughputTimer timer = new ConstantThroughputTimer();
-        assertEquals(0,timer.getCalcMode());// Assume this thread only
+        Assertions.assertEquals(0, timer.getCalcMode());// Assume this thread only
         timer.setThroughput(60.0);// 1 per second
         long start = System.currentTimeMillis();
         long delay = timer.delay(); // Initialise
-        assertEquals(0,delay);
+        Assertions.assertEquals(0, delay);
         // The test tries to check if the calculated delay is correct.
         // If the build machine is busy, then the sleep(500) may take longer in
         // which case the calculated delay should be shorter.
@@ -55,107 +49,120 @@ public class ConstantThroughputTimerTest {
         if (expected < 0) {
             expected = 0;
         }
-        assertEquals("Expected delay of approx 500", expected, timer.delay(), 50);
+        assertAlmostEquals(expected, timer.delay(), 50);
     }
 
+    private static void assertAlmostEquals(long expected, long actual, long delta) {
+        long actualDelta = Math.abs(actual - expected);
+        if (actualDelta > delta) {
+            Assertions.fail(() -> "Expected " + expected + " within delta of " + delta
+                    + ", but got " + actual + " which is a delta of " + actualDelta);
+        }
+    }
     @Test
-    public void testTimer2() throws Exception {
+    void testTimer2() throws Exception {
         ConstantThroughputTimer timer = new ConstantThroughputTimer();
-        assertEquals(0,timer.getCalcMode());// Assume this thread only
+        Assertions.assertEquals(0, timer.getCalcMode());// Assume this thread only
         timer.setThroughput(60.0);// 1 per second
-        assertEquals(1000,timer.calculateCurrentTarget(0)); // Should delay for 1 second
+        Assertions.assertEquals(1000, timer.calculateCurrentTarget(0)); // Should delay for 1 second
         timer.setThroughput(60000.0);// 1 per milli-second
-        assertEquals(1,timer.calculateCurrentTarget(0)); // Should delay for 1 milli-second
+        Assertions.assertEquals(1, timer.calculateCurrentTarget(0)); // Should delay for 1 milli-second
     }
 
     @Test
-    public void testTimer3() throws Exception {
+    void testTimer3() throws Exception {
         ConstantThroughputTimer timer = new ConstantThroughputTimer();
         timer.setMode(ConstantThroughputTimer.Mode.AllActiveThreads); //$NON-NLS-1$ - all threads
-        assertEquals(1,timer.getCalcMode());// All threads
+        Assertions.assertEquals(1, timer.getCalcMode());// All threads
         for(int i=1; i<=10; i++){
             TestJMeterContextService.incrNumberOfThreads();
         }
-        assertEquals(10,JMeterContextService.getNumberOfThreads());
+        Assertions.assertEquals(10, JMeterContextService.getNumberOfThreads());
         timer.setThroughput(600.0);// 10 per second
-        assertEquals(1000,timer.calculateCurrentTarget(0)); // Should delay for 1 second
+        Assertions.assertEquals(1000, timer.calculateCurrentTarget(0)); // Should delay for 1 second
         timer.setThroughput(600000.0);// 10 per milli-second
-        assertEquals(1,timer.calculateCurrentTarget(0)); // Should delay for 1 milli-second
+        Assertions.assertEquals(1, timer.calculateCurrentTarget(0)); // Should delay for 1 milli-second
         for(int i=1; i<=990; i++){
             TestJMeterContextService.incrNumberOfThreads();
         }
-        assertEquals(1000,JMeterContextService.getNumberOfThreads());
+        Assertions.assertEquals(1000, JMeterContextService.getNumberOfThreads());
         timer.setThroughput(60000000.0);// 1000 per milli-second
-        assertEquals(1,timer.calculateCurrentTarget(0)); // Should delay for 1 milli-second
+        Assertions.assertEquals(1, timer.calculateCurrentTarget(0)); // Should delay for 1 milli-second
     }
 
     @Test
-    public void testTimerBSH() throws Exception {
-        Assume.assumeTrue("BeanShell jar should be on the classpath, otherwise the test makes no sense",
-                BeanShellInterpreter.isInterpreterPresent());
+    void testTimerBSH() throws Exception {
+        Assumptions.assumeTrue(BeanShellInterpreter.isInterpreterPresent(),
+                "BeanShell jar should be on the classpath, otherwise the test makes no sense");
         BeanShellTimer timer = new BeanShellTimer();
 
         timer.setScript("\"60\"");
-        assertEquals(60, timer.delay());
+        Assertions.assertEquals(60, timer.delay());
 
         timer.setScript("60");
-        assertEquals(60, timer.delay());
+        Assertions.assertEquals(60, timer.delay());
 
         timer.setScript("5*3*4");
-        assertEquals(60,timer.delay());
+        Assertions.assertEquals(60, timer.delay());
     }
 
     @Test
-    public void testTimerJSR223Timer() throws Exception {
+    void testTimerJSR223Timer() throws Exception {
         JSR223Timer timer = new JSR223Timer();
         timer.setScriptLanguage(ScriptingTestElement.DEFAULT_SCRIPT_LANGUAGE);
         timer.setCacheKey(UUID.randomUUID().toString());
 
         timer.setScript("\"60\"");
-        assertEquals(60, timer.delay());
+        Assertions.assertEquals(60, timer.delay());
 
         timer.setScript("60");
-        assertEquals(60, timer.delay());
+        Assertions.assertEquals(60, timer.delay());
 
         timer.setScript("5*3*4");
-        assertEquals(60,timer.delay());
+        Assertions.assertEquals(60, timer.delay());
     }
 
     @Test
-    public void testUniformRandomTimer() throws Exception {
+    void testUniformRandomTimer() throws Exception {
         UniformRandomTimer timer = new UniformRandomTimer();
         timer.setDelay("1000");
         timer.setRange(100d);
         timer.iterationStart(null);
         long delay = timer.delay();
-        Assert.assertTrue("delay:"+delay +" is not in expected range", delay >= 1000 && delay <=1100);
+        assertBetween(1000, 1100, delay);
     }
 
+    private static void assertBetween(long expectedLow, long expectedHigh, long actual) {
+        if (actual < expectedLow || actual > expectedHigh) {
+            Assertions.fail(() -> "delay not in expected range: expected " + actual
+                    + " to be within " + expectedLow + " and " + expectedHigh);
+        }
+    }
     @Test
-    public void testConstantTimer() throws Exception {
+    void testConstantTimer() throws Exception {
         ConstantTimer timer = new ConstantTimer();
         timer.setDelay("1000");
         timer.iterationStart(null);
-        assertEquals(1000, timer.delay());
+        Assertions.assertEquals(1000, timer.delay());
     }
 
     @Test
-    public void testPoissonRandomTimerRangeHigherThan30() throws Exception {
+    void testPoissonRandomTimerRangeHigherThan30() throws Exception {
         PoissonRandomTimer timer = new PoissonRandomTimer();
         timer.setDelay("300");
         timer.setRange(100d);
         timer.iterationStart(null);
         long delay = timer.delay();
-        Assert.assertTrue("delay:"+delay +" is not in expected range", delay >= 356 && delay <=457);
+        assertBetween(356, 457, delay);
     }
 
     @Test
-    public void testPoissonRandomTimerRangeLowerThan30() throws Exception {
+    void testPoissonRandomTimerRangeLowerThan30() throws Exception {
         PoissonRandomTimer timer = new PoissonRandomTimer();
         timer.setDelay("300");
         timer.setRange(30d);
         timer.iterationStart(null);
         long delay = timer.delay();
-        Assert.assertTrue("delay:"+delay +" is not in expected range", delay >= 305 && delay <=362);
+        assertBetween(305, 362, delay);
     }
 }
diff --git a/src/core/src/test/java/org/apache/jmeter/samplers/TestSampleResult.java b/src/core/src/test/java/org/apache/jmeter/samplers/TestSampleResult.java
index 9bdbea7469..a551a5287f 100644
--- a/src/core/src/test/java/org/apache/jmeter/samplers/TestSampleResult.java
+++ b/src/core/src/test/java/org/apache/jmeter/samplers/TestSampleResult.java
@@ -17,24 +17,18 @@
 
 package org.apache.jmeter.samplers;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 import org.apache.jmeter.junit.JMeterTestCase;
 import org.apache.jmeter.testelement.TestPlan;
 import org.apache.jmeter.util.Calculator;
 import org.apache.jmeter.util.LogRecordingDelegatingLogger;
 import org.apache.jorphan.test.JMeterSerialTest;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-public class TestSampleResult implements JMeterSerialTest {
+class TestSampleResult implements JMeterSerialTest {
 
     @Test
-    public void testElapsedTrue() throws Exception {
+    void testElapsedTrue() throws Exception {
         SampleResult res = new SampleResult(true);
 
         // Check sample increments OK
@@ -43,12 +37,12 @@ public class TestSampleResult implements JMeterSerialTest {
         res.sampleEnd();
         long time = res.getTime();
         if (time < 100) {
-            fail("Sample time should be >=100, actual " + time);
+            Assertions.fail("Sample time should be >=100, actual " + time);
         }
     }
 
     @Test
-    public void testElapsedFalse() throws Exception {
+    void testElapsedFalse() throws Exception {
         SampleResult res = new SampleResult(false);
 
         // Check sample increments OK
@@ -57,12 +51,12 @@ public class TestSampleResult implements JMeterSerialTest {
         res.sampleEnd();
         long time = res.getTime();
         if (time < 100) {
-            fail("Sample time should be >=100, actual " + time);
+            Assertions.fail("Sample time should be >=100, actual " + time);
         }
     }
 
     @Test
-    public void testPauseFalse() throws Exception {
+    void testPauseFalse() throws Exception {
         SampleResult res = new SampleResult(false);
         // Check sample increments OK
         res.sampleStart();
@@ -76,11 +70,19 @@ public class TestSampleResult implements JMeterSerialTest {
         totalSampleTime += sleep(100);
         res.sampleEnd();
         long sampleTime = res.getTime();
-        assertEquals("Accumulated sample time", totalSampleTime, sampleTime, 50);
+        assertAlmostEquals(totalSampleTime, sampleTime, 50, "Accumulated sample time");
     }
 
+    private static void assertAlmostEquals(long expected, long actual, long delta, String message) {
+        long actualDelta = Math.abs(expected - actual);
+        if (actualDelta > delta) {
+            Assertions.fail(() -> message + ", expected " + expected
+                    + " within delta of " + delta + ", but got " + actual
+                    + " which results in actual delta of " + actualDelta);
+        }
+    }
     @Test
-    public void testPauseTrue() throws Exception {
+    void testPauseTrue() throws Exception {
         SampleResult res = new SampleResult(true);
         // Check sample increments OK
         res.sampleStart();
@@ -94,7 +96,7 @@ public class TestSampleResult implements JMeterSerialTest {
         totalSampleTime += sleep(100);
         res.sampleEnd();
         long sampleTime = res.getTime();
-        assertEquals("Accumulated sample time", totalSampleTime, sampleTime, 50);
+        assertAlmostEquals(totalSampleTime, sampleTime, 50, "Accumulated sample time");
     }
 
     private LogRecordingDelegatingLogger recordLogger;
@@ -110,76 +112,76 @@ public class TestSampleResult implements JMeterSerialTest {
     }
 
     @Test
-    public void testPause2True() throws Exception {
+    void testPause2True() throws Exception {
         divertLog();
         SampleResult res = new SampleResult(true);
         res.sampleStart();
         res.samplePause();
-        assertEquals(0, recordLogger.getLogRecordCount());
+        Assertions.assertEquals(0, recordLogger.getLogRecordCount());
         res.samplePause();
-        assertNotEquals(0, recordLogger.getLogRecordCount());
+        Assertions.assertNotEquals(0, recordLogger.getLogRecordCount());
     }
 
     @Test
-    public void testPause2False() throws Exception {
+    void testPause2False() throws Exception {
         divertLog();
         SampleResult res = new SampleResult(false);
         res.sampleStart();
         res.samplePause();
-        assertEquals(0, recordLogger.getLogRecordCount());
+        Assertions.assertEquals(0, recordLogger.getLogRecordCount());
         res.samplePause();
-        assertNotEquals(0, recordLogger.getLogRecordCount());
+        Assertions.assertNotEquals(0, recordLogger.getLogRecordCount());
     }
 
     @Test
-    public void testByteCount() throws Exception {
+    void testByteCount() throws Exception {
         SampleResult res = new SampleResult();
 
         res.sampleStart();
         res.setBytes(100L);
         res.setSampleLabel("sample of size 100 bytes");
         res.sampleEnd();
-        assertEquals(100, res.getBytesAsLong());
-        assertEquals("sample of size 100 bytes", res.getSampleLabel());
+        Assertions.assertEquals(100, res.getBytesAsLong());
+        Assertions.assertEquals("sample of size 100 bytes", res.getSampleLabel());
     }
 
     @Test
-    public void testSubResultsTrue() throws Exception {
+    void testSubResultsTrue() throws Exception {
         testSubResults(true, 0);
     }
 
     @Test
-    public void testSubResultsTrueThread() throws Exception {
+    void testSubResultsTrueThread() throws Exception {
         testSubResults(true, 500L, 0);
     }
 
     @Test
-    public void testSubResultsFalse() throws Exception {
+    void testSubResultsFalse() throws Exception {
         testSubResults(false, 0);
     }
 
     @Test
-    public void testSubResultsFalseThread() throws Exception {
+    void testSubResultsFalseThread() throws Exception {
         testSubResults(false, 500L, 0);
     }
 
     @Test
-    public void testSubResultsTruePause() throws Exception {
+    void testSubResultsTruePause() throws Exception {
         testSubResults(true, 100);
     }
 
     @Test
-    public void testSubResultsTruePauseThread() throws Exception {
+    void testSubResultsTruePauseThread() throws Exception {
         testSubResults(true, 500L, 100);
     }
 
     @Test
-    public void testSubResultsFalsePause() throws Exception {
+    void testSubResultsFalsePause() throws Exception {
         testSubResults(false, 100);
     }
 
     @Test
-    public void testSubResultsFalsePauseThread() throws Exception {
+    void testSubResultsFalsePauseThread() throws Exception {
         testSubResults(false, 500L, 100);
     }
 
@@ -204,7 +206,7 @@ public class TestSampleResult implements JMeterSerialTest {
         SampleResult parent = new SampleResult(nanoTime, nanoThreadSleep);
 
         JMeterTestCase.assertPrimitiveEquals(nanoTime, parent.useNanoTime);
-        assertEquals(nanoThreadSleep, parent.nanoThreadSleep);
+        Assertions.assertEquals(nanoThreadSleep, parent.nanoThreadSleep);
 
         long beginTest = parent.currentTimeInMillis();
 
@@ -226,11 +228,11 @@ public class TestSampleResult implements JMeterSerialTest {
         child1.sampleEnd();
         long child1Elapsed = child1.getTime();
 
-        assertTrue(child1.isSuccessful());
-        assertEquals(100, child1.getBytesAsLong());
-        assertEquals("Child1 Sample", child1.getSampleLabel());
-        assertEquals(1, child1.getSampleCount());
-        assertEquals(0, child1.getSubResults().length);
+        Assertions.assertTrue(child1.isSuccessful());
+        Assertions.assertEquals(100, child1.getBytesAsLong());
+        Assertions.assertEquals("Child1 Sample", child1.getSampleLabel());
+        Assertions.assertEquals(1, child1.getSampleCount());
+        Assertions.assertEquals(0, child1.getSubResults().length);
 
         long actualPause = 0;
         if (pause > 0) {
@@ -249,20 +251,20 @@ public class TestSampleResult implements JMeterSerialTest {
         child2.sampleEnd();
         long child2Elapsed = child2.getTime();
 
-        assertTrue(child2.isSuccessful());
-        assertEquals(200, child2.getBytesAsLong());
-        assertEquals("Child2 Sample", child2.getSampleLabel());
-        assertEquals(1, child2.getSampleCount());
-        assertEquals(0, child2.getSubResults().length);
+        Assertions.assertTrue(child2.isSuccessful());
+        Assertions.assertEquals(200, child2.getBytesAsLong());
+        Assertions.assertEquals("Child2 Sample", child2.getSampleLabel());
+        Assertions.assertEquals(1, child2.getSampleCount());
+        Assertions.assertEquals(0, child2.getSubResults().length);
 
         // Now add the subsamples to the sample
         parent.addSubResult(child1);
         parent.addSubResult(child2);
-        assertTrue(parent.isSuccessful());
-        assertEquals(600, parent.getBytesAsLong());
-        assertEquals("Parent Sample", parent.getSampleLabel());
-        assertEquals(1, parent.getSampleCount());
-        assertEquals(2, parent.getSubResults().length);
+        Assertions.assertTrue(parent.isSuccessful());
+        Assertions.assertEquals(600, parent.getBytesAsLong());
+        Assertions.assertEquals("Parent Sample", parent.getSampleLabel());
+        Assertions.assertEquals(1, parent.getSampleCount());
+        Assertions.assertEquals(2, parent.getSubResults().length);
         long parentElapsedTotal = parent.getTime();
 
         long overallTime = parent.currentTimeInMillis() - beginTest;
@@ -277,7 +279,7 @@ public class TestSampleResult implements JMeterSerialTest {
         long diff = parentElapsedTotal - sumSamplesTimes;
         long maxDiff = nanoTime ? 10 : 16; // TimeMillis has granularity of 10-20
         if (diff < 0 || diff > maxDiff) {
-            fail("ParentElapsed: " + parentElapsedTotal + " - " + " sum(samples): " + sumSamplesTimes
+            Assertions.fail("ParentElapsed: " + parentElapsedTotal + " - " + " sum(samples): " + sumSamplesTimes
                     + " => " + diff + " not in [0," + maxDiff + "]; nanotime=" + nanoTime);
         }
 
@@ -286,53 +288,53 @@ public class TestSampleResult implements JMeterSerialTest {
 
         diff = overallTime - parentElapsedTotal;
         if (diff < 0 || diff > maxDiff) {
-            fail("TestElapsed: " + overallTime + " - " + " ParentElapsed: " + parentElapsedTotal
+            Assertions.fail("TestElapsed: " + overallTime + " - " + " ParentElapsed: " + parentElapsedTotal
                     + " => " + diff + " not in [0," + maxDiff + "]; nanotime=" + nanoTime);
         }
 
         // Check that calculator gets the correct statistics from the sample
         Calculator calculator = new Calculator();
         calculator.addSample(parent);
-        assertEquals(600, calculator.getTotalBytes());
-        assertEquals(1, calculator.getCount());
-        assertEquals(1d / (parentElapsedTotal / 1000d), calculator.getRate(), 0.0001d); // Allow for some margin of error
+        Assertions.assertEquals(600, calculator.getTotalBytes());
+        Assertions.assertEquals(1, calculator.getCount());
+        Assertions.assertEquals(1d / (parentElapsedTotal / 1000d), calculator.getRate(), 0.0001d); // Allow for some margin of error
         // Check that the throughput uses the time elapsed for the sub results
-        assertFalse(1d / (parentElapsed / 1000d) <= calculator.getRate());
+        Assertions.assertFalse(1d / (parentElapsed / 1000d) <= calculator.getRate());
     }
 
     // TODO some more invalid sequence tests needed
 
     @Test
-    public void testEncodingAndType() throws Exception {
+    void testEncodingAndType() throws Exception {
         // check default
         SampleResult res = new SampleResult();
-        assertEquals(SampleResult.DEFAULT_ENCODING, res.getDataEncodingWithDefault());
-        assertEquals("DataType should be blank", "", res.getDataType());
-        assertNull(res.getDataEncodingNoDefault());
+        Assertions.assertEquals(SampleResult.DEFAULT_ENCODING, res.getDataEncodingWithDefault());
+        Assertions.assertEquals("", res.getDataType(), "DataType should be blank");
+        Assertions.assertNull(res.getDataEncodingNoDefault());
 
         // check null changes nothing
         res.setEncodingAndType(null);
-        assertEquals(SampleResult.DEFAULT_ENCODING, res.getDataEncodingWithDefault());
-        assertEquals("DataType should be blank", "", res.getDataType());
-        assertNull(res.getDataEncodingNoDefault());
+        Assertions.assertEquals(SampleResult.DEFAULT_ENCODING, res.getDataEncodingWithDefault());
+        Assertions.assertEquals("", res.getDataType(), "DataType should be blank");
+        Assertions.assertNull(res.getDataEncodingNoDefault());
 
         // check no charset
         res.setEncodingAndType("text/html");
-        assertEquals(SampleResult.DEFAULT_ENCODING, res.getDataEncodingWithDefault());
-        assertEquals("text", res.getDataType());
-        assertNull(res.getDataEncodingNoDefault());
+        Assertions.assertEquals(SampleResult.DEFAULT_ENCODING, res.getDataEncodingWithDefault());
+        Assertions.assertEquals("text", res.getDataType());
+        Assertions.assertNull(res.getDataEncodingNoDefault());
 
         // Check unquoted charset
         res.setEncodingAndType("text/html; charset=aBcd");
-        assertEquals("aBcd", res.getDataEncodingWithDefault());
-        assertEquals("aBcd", res.getDataEncodingNoDefault());
-        assertEquals("text", res.getDataType());
+        Assertions.assertEquals("aBcd", res.getDataEncodingWithDefault());
+        Assertions.assertEquals("aBcd", res.getDataEncodingNoDefault());
+        Assertions.assertEquals("text", res.getDataType());
 
         // Check quoted charset
         res.setEncodingAndType("text/html; charset=\"aBCd\"");
-        assertEquals("aBCd", res.getDataEncodingWithDefault());
-        assertEquals("aBCd", res.getDataEncodingNoDefault());
-        assertEquals("text", res.getDataType());
+        Assertions.assertEquals("aBCd", res.getDataEncodingWithDefault());
+        Assertions.assertEquals("aBCd", res.getDataEncodingNoDefault());
+        Assertions.assertEquals("text", res.getDataType());
     }
 
     // sleep and return how long we actually slept
@@ -344,7 +346,7 @@ public class TestSampleResult implements JMeterSerialTest {
     }
 
     @Test
-    public void testCompareSampleLabels() {
+    void testCompareSampleLabels() {
         final boolean prevValue = TestPlan.getFunctionalMode();
         TestPlan plan = new TestPlan();
         plan.setFunctionalMode(true);
@@ -358,25 +360,25 @@ public class TestSampleResult implements JMeterSerialTest {
             subResult.setSampleLabel("subResult label");
 
             result.addSubResult(subResult);
-            assertEquals("subResult label", subResult.getSampleLabel());
+            Assertions.assertEquals("subResult label", subResult.getSampleLabel());
 
             plan.setFunctionalMode(false);
             subResult.setSampleLabel("parent label");
             result.addRawSubResult(subResult);
-            assertEquals("parent label-0", subResult.getSampleLabel());
+            Assertions.assertEquals("parent label-0", subResult.getSampleLabel());
         } finally {
             plan.setFunctionalMode(prevValue);
         }
     }
 
     @Test
-    public void testBug63433() {
+    void testBug63433() {
         SampleResult firstResult = new SampleResult();
-        assertFalse("Expected false on first call of markFile", firstResult.markFile("result.csv"));
-        assertTrue("Expected true on second call of markFile", firstResult.markFile("result.csv"));
+        Assertions.assertFalse(firstResult.markFile("result.csv"), "Expected false on first call of markFile");
+        Assertions.assertTrue(firstResult.markFile("result.csv"), "Expected true on second call of markFile");
 
         SampleResult secondResult = new SampleResult();
-        assertFalse("Expected false on first call of markFile with null", secondResult.markFile(null));
-        assertTrue("Expected true on second call of markFile with null", secondResult.markFile(null));
+        Assertions.assertFalse(secondResult.markFile(null), "Expected false on first call of markFile with null");
+        Assertions.assertTrue(secondResult.markFile(null), "Expected true on second call of markFile with null");
     }
 }


[jmeter] 03/16: Make error prone happy by re-throwing catched exception

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit fb6322030f9bc1ea97160810c3f83f066544c47c
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 15:58:44 2022 +0200

    Make error prone happy by re-throwing catched exception
    
    and while we are here, update to junit5
    and get rid of unused code
---
 .../apache/jmeter/control/TestIfController.java    | 51 ++++++++++------------
 .../org/apache/jmeter/functions/PackageTest.java   | 25 ++---------
 2 files changed, 27 insertions(+), 49 deletions(-)

diff --git a/src/components/src/test/java/org/apache/jmeter/control/TestIfController.java b/src/components/src/test/java/org/apache/jmeter/control/TestIfController.java
index 1585eb8fa5..03805d42b0 100644
--- a/src/components/src/test/java/org/apache/jmeter/control/TestIfController.java
+++ b/src/components/src/test/java/org/apache/jmeter/control/TestIfController.java
@@ -17,10 +17,6 @@
 
 package org.apache.jmeter.control;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
 import org.apache.jmeter.config.Arguments;
 import org.apache.jmeter.junit.JMeterTestCase;
 import org.apache.jmeter.junit.stubs.TestSampler;
@@ -31,14 +27,15 @@ import org.apache.jmeter.testkit.BugId;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
-public class TestIfController extends JMeterTestCase {
+class TestIfController extends JMeterTestCase {
 
     @BugId("56160")
     @Test
-    public void testStackOverflow() throws Exception {
+    void testStackOverflow() throws Exception {
         LoopController controller = new LoopController();
         controller.setLoops(1);
         controller.setContinueForever(false);
@@ -65,15 +62,15 @@ public class TestIfController extends JMeterTestCase {
                 sampler.sample(null);
                 counter++;
             }
-            assertEquals(0, counter);
+            Assertions.assertEquals(0, counter);
         } catch (StackOverflowError e) {
-            fail("Stackoverflow occurred in testStackOverflow");
+            throw new AssertionError("Stackoverflow occurred in testStackOverflow", e);
         }
     }
 
     @BugId("53768")
     @Test
-    public void testBug53768() throws Exception {
+    void testBug53768() throws Exception {
         LoopController controller = new LoopController();
         controller.setLoops(1);
         controller.setContinueForever(false);
@@ -125,19 +122,19 @@ public class TestIfController extends JMeterTestCase {
 
             Sampler sampler = controller.next();
             sampler.sample(null);
-            assertEquals("0", vars.get("VAR1"));
+            Assertions.assertEquals("0", vars.get("VAR1"));
             sampler = controller.next();
             sampler.sample(null);
-            assertEquals("0", vars.get("VAR1"));
+            Assertions.assertEquals("0", vars.get("VAR1"));
 
         } catch (StackOverflowError e) {
-            fail("Stackoverflow occurred in testStackOverflow");
+            throw new AssertionError("Stackoverflow occurred in testStackOverflow", e);
         }
     }
 
     @Test
     @Disabled
-    public void testProcessing() throws Exception {
+    void testProcessing() throws Exception {
 
         GenericController controller = new GenericController();
 
@@ -150,7 +147,7 @@ public class TestIfController extends JMeterTestCase {
     }
 
     @Test
-    public void testProcessingTrue() throws Exception {
+    void testProcessingTrue() throws Exception {
         LoopController controller = new LoopController();
         controller.setLoops(2);
         controller.addTestElement(new TestSampler("Sample1"));
@@ -170,14 +167,14 @@ public class TestIfController extends JMeterTestCase {
         Sampler sampler = null;
         while ((sampler = controller.next()) != null) {
             sampler.sample(null);
-            assertEquals(order[counter], sampler.getName());
+            Assertions.assertEquals(order[counter], sampler.getName());
             counter++;
         }
-        assertEquals(counter, 6);
+        Assertions.assertEquals(counter, 6);
     }
 
     @Test
-    public void testProcessingTrueWithExpression() throws Exception {
+    void testProcessingTrueWithExpression() throws Exception {
         LoopController controller = new LoopController();
         controller.setLoops(2);
         controller.addTestElement(new TestSampler("Sample1"));
@@ -198,10 +195,10 @@ public class TestIfController extends JMeterTestCase {
         Sampler sampler = null;
         while ((sampler = controller.next()) != null) {
             sampler.sample(null);
-            assertEquals(order[counter], sampler.getName());
+            Assertions.assertEquals(order[counter], sampler.getName());
             counter++;
         }
-        assertEquals(counter, 6);
+        Assertions.assertEquals(counter, 6);
     }
 
 
@@ -209,7 +206,7 @@ public class TestIfController extends JMeterTestCase {
      * Test false return on sample3 (sample4 doesn't execute)
      */
     @Test
-    public void testEvaluateAllChildrenWithoutSubController() throws Exception {
+    void testEvaluateAllChildrenWithoutSubController() throws Exception {
         LoopController controller = new LoopController();
         controller.setLoops(2);
         controller.addTestElement(new TestSampler("Sample1"));
@@ -235,17 +232,17 @@ public class TestIfController extends JMeterTestCase {
             if (sampler.getName().equals("Sample3")) {
                 ifCont.setCondition("true==false");
             }
-            assertEquals(order[counter], sampler.getName());
+            Assertions.assertEquals(order[counter], sampler.getName());
             counter++;
         }
-        assertEquals(counter, 6);
+        Assertions.assertEquals(counter, 6);
     }
 
     /**
      * test 2 loops with a sub generic controller (sample4 doesn't execute)
      */
     @Test
-    public void testEvaluateAllChildrenWithSubController() throws Exception {
+    void testEvaluateAllChildrenWithSubController() throws Exception {
         LoopController controller = new LoopController();
         controller.setLoops(2);
         controller.addTestElement(new TestSampler("Sample1"));
@@ -274,14 +271,14 @@ public class TestIfController extends JMeterTestCase {
             if (sampler.getName().equals("Sample3")) {
                 ifCont.setCondition("true==false");
             }
-            assertEquals(order[counter], sampler.getName());
+            Assertions.assertEquals(order[counter], sampler.getName());
             counter++;
         }
-        assertEquals(counter, 6);
+        Assertions.assertEquals(counter, 6);
     }
 
     @Test
-    public void shouldIgnoreEmptyLastLine() {
+    void shouldIgnoreEmptyLastLine() {
         GenericController controller = new GenericController();
 
         IfController ifCont = new IfController("true\n");
@@ -296,6 +293,6 @@ public class TestIfController extends JMeterTestCase {
         ifCont.setRunningVersion(true);
 
         Sampler sampler = controller.next();
-        assertFalse(sampler == null);
+        Assertions.assertNotNull(sampler);
     }
 }
diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/PackageTest.java b/src/functions/src/test/java/org/apache/jmeter/functions/PackageTest.java
index ae392c9a4b..3b6b25d975 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/PackageTest.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/PackageTest.java
@@ -105,7 +105,7 @@ public class PackageTest extends JMeterTestCaseJUnit {
             bsh = BSHFParams("", "", null);
             assertEquals("", bsh.execute());
         } catch (InvalidVariableException e) {
-            fail("BeanShell not present");
+            throw new AssertionError("BeanShell not present", e);
         }
 
         bsh = BSHFParams("1", null, null);
@@ -158,25 +158,6 @@ public class PackageTest extends JMeterTestCaseJUnit {
 
     }
 
-    // Helper class used to implement co-routine between two threads
-    private static class Baton {
-        void pass() {
-            done();
-            try {
-                wait(1000);
-            } catch (InterruptedException e) {
-                System.out.println(e);
-            }
-        }
-
-        void done() {
-            notifyAll();
-        }
-
-    }
-
-    private static final Baton BATON = new Baton();
-
     // XPathFileContainer tests
 
     public void XPathtestNull() throws Exception {
@@ -207,7 +188,7 @@ public class PackageTest extends JMeterTestCaseJUnit {
         int last = 0;
         for (int i = 0; i < f.size(); i++) {
             last = f.nextRow();
-            log.debug("found [" + i + "]" + f.getXPathString(last));
+            log.debug("found [{}]{}", i, f.getXPathString(last));
         }
         assertEquals(last + 1, f.size());
 
@@ -275,7 +256,7 @@ public class PackageTest extends JMeterTestCaseJUnit {
 
     private XPath setupXPath(String file, String expr) throws Exception{
         XPath xp = new XPath();
-        xp.setParameters(makeParams(new Object[]{getResourceFilePath(file), expr}));
+        xp.setParameters(makeParams(getResourceFilePath(file), expr));
         return xp;
     }
 


[jmeter] 12/16: Suppress warning about calling wait without a loop

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 16340ba1b8a0d441cb52c58423ebc0d3bf343fb9
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 17:21:19 2022 +0200

    Suppress warning about calling wait without a loop
    
    While it is certainly not good to wait ouside a loop,
    it is not that problematic here, as the test should fail
    in such a case.
---
 .../src/test/java/org/apache/jmeter/functions/Synchronizer.java          | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/Synchronizer.java b/src/functions/src/test/java/org/apache/jmeter/functions/Synchronizer.java
index ebcd95648d..93a061444d 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/Synchronizer.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/Synchronizer.java
@@ -25,6 +25,7 @@ class Synchronizer {
         notifyAll();
     }
 
+    @SuppressWarnings("WaitNotInLoop")
     void pass() {
         done();
         try {


[jmeter] 16/16: Updated a few dependencies

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 89f4a76c61004cf68598b92883e2d1456e6c8ba1
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 17:36:27 2022 +0200

    Updated a few dependencies
---
 checksum.xml                                |  3 +++
 gradle.properties                           | 26 +++++++++++-----------
 src/dist/src/dist/expected_release_jars.csv | 34 ++++++++++++++---------------
 xdocs/changes.xml                           | 17 ++++++++-------
 4 files changed, 42 insertions(+), 38 deletions(-)

diff --git a/checksum.xml b/checksum.xml
index 3d43a4475c..d40d479ca2 100644
--- a/checksum.xml
+++ b/checksum.xml
@@ -16,6 +16,7 @@
     <trusted-key id='07d3516820bcf6b1' group='com.github.ben-manes.caffeine' />
     <trusted-key id='3c0a8f4744f37328' group='com.github.ben-manes.caffeine' />
     <trusted-key id='62c82e50836eb3ee' group='com.github.gundy' />
+    <trusted-key id='249dee8e2c07a0a2' group='com.github.javaparser' />
     <trusted-key id='379ce192d401ab61' group='com.github.javaparser' />
     <trusted-key id='431b8f80403a7dc1' group='com.github.javaparser' />
     <trusted-key id='8ea48d105232855d' group='com.github.jknack' />
@@ -143,6 +144,7 @@
     <trusted-key id='e91287822fdb81b1' group='org.apache.xbean' />
     <trusted-key id='5b93f1df7cdb6dea' group='org.apache.xmlgraphics' />
     <trusted-key id='85911f425ec61b51' group='org.apiguardian' />
+    <trusted-key id='0cc0b712fee75827' group='org.assertj' />
     <trusted-key id='e2b3d84202b812d9' group='org.assertj' />
     <trusted-key id='b341ddb020fcb6ab' group='org.bouncycastle' />
     <trusted-key id='be84d764623a3644' group='org.brotli' />
@@ -189,6 +191,7 @@
     <trusted-key id='85911f425ec61b51' group='org.junit.platform' />
     <trusted-key id='85911f425ec61b51' group='org.junit.vintage' />
     <trusted-key id='82216a03caa86c78' group='org.mongodb' />
+    <trusted-key id='2f45f85cdf082e68' group='org.mozilla' />
     <trusted-key id='3f36885c24df4b75' group='org.mozilla' />
     <trusted-key id='7ad289796be2ffe2' group='org.neo4j.driver' />
     <trusted-key id='f8052e4e1bd0db31' group='org.neo4j.driver' />
diff --git a/gradle.properties b/gradle.properties
index 6caea8bcf3..56428b4043 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -61,7 +61,7 @@ activemq.version=5.16.4
 apache-rat.version=0.13
 apiguardian-api.version=1.1.0
 asm.version=9.2
-bouncycastle.version=1.69
+bouncycastle.version=1.70
 bsf.version=2.4.0
 bsh.version=2.0b6
 caffeine.version=2.9.3
@@ -84,12 +84,12 @@ darklaf.version=2.7.3
 darklaf.extensions.version=0.3.4
 dec.version=0.1.2
 dnsjava.version=2.1.9
-equalsverifier.version=3.9
+equalsverifier.version=3.10
 freemarker.version=2.3.31
-ftplet-api.version=1.1.3
-ftpserver-core.version=1.1.3
+ftplet-api.version=1.2.0
+ftpserver-core.version=1.2.0
 geronimo-jms_1.1_spec.version=1.1.1
-groovy.version=3.0.9
+groovy.version=3.0.10
 hamcrest.version=2.2
 hamcrest-date.version=2.0.8
 hsqldb.version=2.5.2
@@ -98,8 +98,8 @@ httpclient.version=4.5.13
 httpcore-nio.version=4.4.15
 httpcore.version=4.4.15
 httpmime.version=4.5.13
-jackson.version=2.13.1
-jackson-databind.version=2.13.1
+jackson.version=2.13.2
+jackson-databind.version=2.13.2.2
 javax.activation.version=1.2.0
 jcharts.version=0.7.5
 jdom.version=1.1.3
@@ -107,7 +107,7 @@ jetbrains-annotations.version=23.0.0
 jmespath-core.version=0.5.1
 jmespath-jackson.version=0.5.1
 jodd.version=5.0.13
-json-path.version=2.6.0
+json-path.version=2.7.0
 json-smart.version=2.4.8
 jsoup.version=1.14.3
 jtidy.version=r938
@@ -120,16 +120,16 @@ mail.version=1.5.0-b01
 miglayout.version=5.3
 mina-core.version=2.1.6
 mongo-java-driver.version=2.11.3
-neo4j-java-driver.version=4.4.3
+neo4j-java-driver.version=4.4.5
 objenesis.version=3.2
 oro.version=2.0.8
 ph-commons.version=10.1.6
 ph-css.version=6.5.0
-rhino.version=1.7.13
-rsyntaxtextarea.version=3.1.6
-Saxon-HE.version=11.2
+rhino.version=1.7.14
+rsyntaxtextarea.version=3.2.0
+Saxon-HE.version=11.3
 slf4j.version=1.7.36
-spock-core.version=2.0-M2-groovy-3.0
+spock-core.version=2.1-groovy-3.0
 springframework.version=4.3.17.RELEASE
 svgSalamander.version=1.1.2.4
 tika.version=1.28.1
diff --git a/src/dist/src/dist/expected_release_jars.csv b/src/dist/src/dist/expected_release_jars.csv
index d627e3d964..f518fb736e 100644
--- a/src/dist/src/dist/expected_release_jars.csv
+++ b/src/dist/src/dist/expected_release_jars.csv
@@ -52,15 +52,15 @@
 15992,error_prone_annotations-2.10.0.jar
 1715750,freemarker-2.3.31.jar
 32359,geronimo-jms_1.1_spec-1.1.1.jar
-8004986,groovy-3.0.9.jar
-19457,groovy-datetime-3.0.9.jar
-11684,groovy-dateutil-3.0.9.jar
-137553,groovy-jmx-3.0.9.jar
-133032,groovy-json-3.0.9.jar
-21294,groovy-jsr223-3.0.9.jar
-82930,groovy-sql-3.0.9.jar
-97097,groovy-templates-3.0.9.jar
-296025,groovy-xml-3.0.9.jar
+8014657,groovy-3.0.10.jar
+19460,groovy-datetime-3.0.10.jar
+11688,groovy-dateutil-3.0.10.jar
+137554,groovy-jmx-3.0.10.jar
+133032,groovy-json-3.0.10.jar
+21298,groovy-jsr223-3.0.10.jar
+83198,groovy-sql-3.0.10.jar
+97128,groovy-templates-3.0.10.jar
+296091,groovy-xml-3.0.10.jar
 123360,hamcrest-2.2.jar
 1499,hamcrest-core-2.2.jar
 109741,hamcrest-date-2.0.8.jar
@@ -69,9 +69,9 @@
 328324,httpcore-4.4.15.jar
 369486,httpcore-nio-4.4.15.jar
 41790,httpmime-4.5.13.jar
-75717,jackson-annotations-2.13.1.jar
-374588,jackson-core-2.13.1.jar
-1534017,jackson-databind-2.13.1.jar
+75717,jackson-annotations-2.13.2.jar
+374739,jackson-core-2.13.2.jar
+1535087,jackson-databind-2.13.2.2.jar
 78030,javax.activation-1.2.0.jar
 142391,jcharts-0.7.5.jar
 16555,jcl-over-slf4j-1.7.36.jar
@@ -81,7 +81,7 @@
 220475,jodd-lagarto-5.0.13.jar
 19858,jodd-log-5.0.13.jar
 26047,jodd-props-5.0.13.jar
-238605,json-path-2.6.0.jar
+271159,json-path-2.7.0.jar
 119545,json-smart-2.4.8.jar
 423395,jsoup-1.14.3.jar
 249924,jtidy-r938.jar
@@ -103,7 +103,7 @@
 22576,miglayout-swing-5.3.jar
 419054,mongo-java-driver-2.11.3.jar
 29680,mxparser-1.2.2.jar
-4890898,neo4j-java-driver-4.4.3.jar
+4878084,neo4j-java-driver-4.4.5.jar
 65261,oro-2.0.8.jar
 1308773,ph-commons-10.1.6.jar
 530791,ph-css-6.5.0.jar
@@ -113,9 +113,9 @@
 116030,plot-common-portable-jvm-2.2.1.jar
 749095,plot-config-portable-jvm-2.2.1.jar
 11369,reactive-streams-1.0.3.jar
-1315838,rhino-1.7.13.jar
-1245900,rsyntaxtextarea-3.1.6.jar
-5104409,Saxon-HE-11.2.jar
+1383644,rhino-1.7.14.jar
+1248250,rsyntaxtextarea-3.2.0.jar
+5111311,Saxon-HE-11.3.jar
 276420,serializer-2.7.2.jar
 41125,slf4j-api-1.7.36.jar
 301279,svgSalamander-1.1.2.4.jar
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 39650534bd..805216f8e2 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -169,39 +169,39 @@ however, the profile can't be updated while the test is running.
   <li><pr>656</pr><pr>668</pr>Updated json-smart to 2.4.8 (from 2.3), accessors-smart to 2.4.8 (from 1.2) and asm 9.1 (from 9.0). Contributed by Stefan Seide (stefan at trilobyte-se.de)</li>
   <li><bug>64831</bug>Log truststore entries in debug level for logger <code>org.apache.jmeter.util.keystore.JmeterKeyStore</code></li>
   <li><bug>65232</bug>Hide splash screen when an error is displayed because the test plan could not be parsed.</li>
-  <li>Updated Groovy to 3.0.9 (from 3.0.7).</li>
+  <li>Updated Groovy to 3.0.10 (from 3.0.7).</li>
   <li>Updated Darklaf to 2.7.3 (from 2.5.4).</li>
   <li>Updated Apache ActiveMQ to 15.6.4 (from 15.6.0).</li>
   <li>Updated Asm to 9.2 (from 9.1).</li>
-  <li>Updated Bouncycastle to 1.69 (from 1.67).</li>
+  <li>Updated Bouncycastle to 1.70 (from 1.67).</li>
   <li>Updated Caffeine to 2.9.3 (from 2.8.8).</li>
   <li>Updated Apache commons-dbcp2 to 2.9.0 (from 2.8.0).</li>
   <li>Updated Apache commons-io to 2.11.0 (from 2.8.0).</li>
   <li>Updated Apache commons-lang3 to 3.12.0 (from 3.11).</li>
   <li>Updated Apache commons-net to 3.8.0 (from 3.7.2).</li>
   <li>Updated Apache commons-pool2 to 2.11.1 (from 2.9.0).</li>
-  <li>Updated equalsverifier to 3.9 (from 3.4.2).</li>
+  <li>Updated equalsverifier to 3.10 (from 3.4.2).</li>
   <li>Updated Apache Freemarker to 2.3.31 (from 2.3.30).</li>
   <li>Updated hsqldb to 2.5.2 (from 2.5.0).</li>
   <li>Updated Apache HttpClient to 4.5.13 (from 4.5.12).</li>
   <li>Updated Apache HttpCore to 4.4.15 (from 4.4.13).</li>
   <li>Updated jacoco to 0.8.7 (from 0.8.5).</li>
-  <li>Updated json-path to 2.6.0 (from 2.4.0).</li>
+  <li>Updated json-path to 2.7.0 (from 2.4.0).</li>
   <li>Updated jsoup to 1.14.3 (from 1.13.1).</li>
   <li>Updated JUnit to 4.13.2 and 5.8.2 (from 4.13.1 and 5.7.0).</li>
   <li>Updated Apache log4j2 to 2.17.2 (from 2.13.3).</li>
   <li>Updated Miglayout to 5.3 (from 5.2).</li>
-  <li>Updated Neo4j Java driver to 4.4.4 (from 4.2.0).</li>
+  <li>Updated Neo4j Java driver to 4.4.5 (from 4.2.0).</li>
   <li>Updated Objenesis to 3.2 (from 2.6).</li>
   <li>Updated ktlint to 0.40.0</li>
   <li>Updated PH CSS and PH commons to 6.5.4 and 10.1.6 (from 6.2.3 and 9.5.1).</li>
-  <li>Updated RSyntaxTextArea to 3.1.6 (from 3.1.1).</li>
+  <li>Updated RSyntaxTextArea to 3.2.0 (from 3.1.1).</li>
   <li>Updated SLF4J to 1.7.36 (from 1.7.30).</li>
   <li>Updated SvgSalamander to 1.1.2.4 (from 1.1.2.1).</li>
   <li><pr>698</pr>Updated Apache Tika to 1.28.1 (from 1.26).</li>
   <li>Updated WireMock-JRE8 to 2.30.0 (from 2.24.1).</li>
   <li>Updated com.github.vlsi.vlsi-release-plugins 1.76 (from 1.74).</li>
-  <li>Updated jackson to 2.13.1 (from 2.10.5)</li>
+  <li>Updated jackson to 2.13.2 (from 2.10.5)</li>
   <li>Updated jmespath to 0.5.1</li>
   <li>Updated Saxon-HE to 11.2 (from 9.9.1-8)</li>
   <li>Updated Apache xmlgraphics commons to 2.7 (from 2.6)</li>
@@ -218,6 +218,7 @@ however, the profile can't be updated while the test is running.
   <li><pr>697></pr>Junit 5 tests to use asserts from Junit 5 API. Contributed by Sampath Kumar Krishnasamy (sampathkumar.krishnasamykuppusamy at aexp.com)</li>
   <li><bug>65983</bug><pr>707</pr>Use current screenshot for save-to-file listener in documentation. Based on patch by NaveenKumar Namachivayam (catch.nkn at gmail.com)</li>
   <li><pr>708</pr>Make errorprone happier. Based on patch by Wilson Kurniawan (wilson at visenze.com)></li>
+  <li>Updated Rhino JavaScript to 1.7.14 (from 1.7.13)</li>
 </ul>
 
  <!-- =================== Bug fixes =================== -->
@@ -407,7 +408,7 @@ export JVM_ARGS="-Dnashorn.args=--no-deprecation-warning"
 With Java 15 the JavaScript implementation <a href="https://openjdk.java.net/jeps/372">Nashorn has been removed</a>. To add back a JSR-223 compatible JavaScript engine you have two options:
   <dl>
     <dt>Use Mozilla Rhino</dt>
-    <dd>Copy <a href="https://github.com/mozilla/rhino/releases/download/Rhino1_7_13_Release/rhino-engine-1.7.13.jar">rhino-engine-1.7.13.jar</a> into <code>$JMETER_HOME/lib/ext</code>.</dd>
+    <dd>Copy <a href="https://github.com/mozilla/rhino/releases/download/Rhino1_7_14_Release/rhino-engine-1.7.14.jar">rhino-engine-1.7.14.jar</a> into <code>$JMETER_HOME/lib/ext</code>.</dd>
     <dt>Use OpenJDK Nashorn</dt>
     <dd>
       The OpenJDK Nashorn implementation comes as a module. To use it, you will have to download it and add it to the module path. A hacky way to download the version 15.0 (or later) and its dependencies and set the module path is outlined below:


[jmeter] 11/16: Add override annotations to make error prone happy

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit ee2353ed1cf75ff87c17ce87fab66326d561821c
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Mon Apr 18 17:15:32 2022 +0200

    Add override annotations to make error prone happy
---
 .../org/apache/jmeter/functions/TestJavascriptFunctionWithRhino.java    | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/functions/src/test/java/org/apache/jmeter/functions/TestJavascriptFunctionWithRhino.java b/src/functions/src/test/java/org/apache/jmeter/functions/TestJavascriptFunctionWithRhino.java
index e302ac3a68..7b4f32b1db 100644
--- a/src/functions/src/test/java/org/apache/jmeter/functions/TestJavascriptFunctionWithRhino.java
+++ b/src/functions/src/test/java/org/apache/jmeter/functions/TestJavascriptFunctionWithRhino.java
@@ -25,12 +25,14 @@ import org.junit.jupiter.api.BeforeEach;
 public class TestJavascriptFunctionWithRhino extends TestJavascriptFunction {
 
     @BeforeEach
+    @Override
     public void setUp() {
         JMeterUtils.getJMeterProperties().put("javascript.use_rhino", "true");
         super.setUp();
     }
 
     @AfterEach
+    @Override
     public void tearDown() {
         JMeterUtils.getJMeterProperties().remove("javascript.use_rhino");
     }