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 <[email protected]> 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&s2=2&s3=3"); params.add(new CompoundVariable("vars.get('URL').replaceAll('&','&')")); 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&s2=2&s3=3"); params.add(new CompoundVariable("vars.get('URL').replaceAll('&','&')")); 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(""bread" & "butter"", ret); + Assertions.assertEquals(""bread" & "butter"", ret); } @Test @@ -129,7 +128,7 @@ public class TestSimpleFunctions extends JMeterTestCase implements JMeterSerialT params.add(new CompoundVariable(""bread" & "butter"")); 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("<Français>")); 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(">&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(""bread" & <'butter'>", ret); + Assertions.assertEquals(""bread" & <'butter'>", 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);
