This is an automated email from the ASF dual-hosted git repository.
vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push:
new 01d5985e03 test: replace the usage of org.hamcrest with junit's
assertions
01d5985e03 is described below
commit 01d5985e037a695b6d6e40001a5cf1e66e8acb80
Author: Vladimir Sitnikov <[email protected]>
AuthorDate: Thu Oct 30 10:04:08 2025 +0300
test: replace the usage of org.hamcrest with junit's assertions
---
.../main/kotlin/build-logic.test-junit5.gradle.kts | 1 -
lib/aareadme.txt | 5 --
src/bom-thirdparty/build.gradle.kts | 1 -
.../jmeter/extractor/TestBoundaryExtractor.java | 29 +++---
.../jmeter/extractor/TestHtmlExtractorJSoup.java | 22 +++--
.../jmeter/extractor/TestJSONPostProcessor.java | 78 ++++++++--------
.../jmeter/extractor/TestRegexExtractor.java | 16 ++--
.../jmeter/extractor/TestXPath2Extractor.java | 2 +-
.../jmeter/extractor/TestXPathExtractor.java | 28 +++---
.../json/jmespath/TestJMESPathExtractor.java | 73 +++++++--------
.../org/apache/jmeter/timers/TimerServiceTest.java | 46 ++++------
.../jmeter/visualizers/TestSampleCompareTo.java | 6 +-
.../jmeter/report/core/CsvSampleReaderTest.java | 11 +--
.../graph/impl/CustomGraphConsumerTest.java | 52 +++++------
.../samplers/TestDataStrippingSampleSender.java | 7 +-
.../testelement/property/AbstractPropertyTest.java | 25 +++---
.../testelement/property/MapPropertyTest.java | 7 +-
.../threads/TestUnmodifiableJMeterVariables.java | 28 +++---
.../apache/jmeter/util/JSR223TestElementTest.java | 12 +--
.../java/org/apache/jmeter/util/XPathUtilTest.java | 24 ++---
.../jmeter/gui/AbstractJMeterGuiComponentTest.kt | 6 +-
.../apache/jorphan/reflect/TestClassFinder.java | 10 ++-
src/dist/src/dist/expected_release_jars.csv | 1 -
src/functions/build.gradle.kts | 2 -
.../functions/TestRandomFromMultipleVars.java | 25 ++++--
.../functions/TestTimeRandomDateFunction.java | 28 +++---
.../jmeter/functions/TestTimeShiftFunction.java | 48 +++++-----
.../apache/jorphan/gui/MinMaxLongRendererTest.java | 6 +-
.../apache/jorphan/gui/ObjectTableSorterTest.java | 25 +++---
.../org/apache/jorphan/util/TestJorphanUtils.java | 100 ++++++++++-----------
src/licenses/licenses/hamcrest-date/LICENSE | 24 -----
.../protocol/http/control/TestAuthorization.java | 5 +-
.../http/parser/TestBug60842HtmlParser.java | 10 +--
.../jmeter/protocol/http/parser/TestCssParser.java | 15 ++--
.../protocol/http/sampler/TestDecompression.java | 24 +++--
.../protocol/http/sampler/TestRedirects.java | 2 +-
.../http/sampler/TestSerializedHTTPSampler.java | 7 +-
.../http/visualizers/RequestViewHTTPTest.java | 14 +--
.../sampler/render/BinaryMessageRendererTest.java | 98 +++++---------------
src/protocol/junit/build.gradle.kts | 3 -
40 files changed, 414 insertions(+), 512 deletions(-)
diff --git a/build-logic/jvm/src/main/kotlin/build-logic.test-junit5.gradle.kts
b/build-logic/jvm/src/main/kotlin/build-logic.test-junit5.gradle.kts
index 2434b0123a..a82326e5b4 100644
--- a/build-logic/jvm/src/main/kotlin/build-logic.test-junit5.gradle.kts
+++ b/build-logic/jvm/src/main/kotlin/build-logic.test-junit5.gradle.kts
@@ -24,7 +24,6 @@ plugins {
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter")
- testImplementation("org.hamcrest:hamcrest")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
diff --git a/lib/aareadme.txt b/lib/aareadme.txt
index ee01ff8812..b2f886e2d0 100644
--- a/lib/aareadme.txt
+++ b/lib/aareadme.txt
@@ -106,11 +106,6 @@ groovy-3.0.3
----------------------
Advised scripting language for JSR223 Test Elements
-hamcrest-core-1.3
-----------------------
-- unit tests, JUnit sampler
-https://github.com/hamcrest/JavaHamcrest
-
freemarker-2.3.29.jar
----------------------
- used by Report/Dashboard feature
diff --git a/src/bom-thirdparty/build.gradle.kts
b/src/bom-thirdparty/build.gradle.kts
index c6ce5d3aa4..f55ed3e043 100644
--- a/src/bom-thirdparty/build.gradle.kts
+++ b/src/bom-thirdparty/build.gradle.kts
@@ -122,7 +122,6 @@ dependencies {
api("org.bouncycastle:bcpkix-jdk18on:1.82")
api("org.bouncycastle:bcprov-jdk18on:1.82")
api("org.brotli:dec:0.1.2")
- api("org.exparity:hamcrest-date:2.0.8")
api("org.freemarker:freemarker:2.3.32")
api("org.jdom:jdom:1.1.3")
api("org.jetbrains.lets-plot:lets-plot-batik:4.7.3")
diff --git
a/src/components/src/test/java/org/apache/jmeter/extractor/TestBoundaryExtractor.java
b/src/components/src/test/java/org/apache/jmeter/extractor/TestBoundaryExtractor.java
index 26ce6ecb8d..934078c8d6 100644
---
a/src/components/src/test/java/org/apache/jmeter/extractor/TestBoundaryExtractor.java
+++
b/src/components/src/test/java/org/apache/jmeter/extractor/TestBoundaryExtractor.java
@@ -17,14 +17,13 @@
package org.apache.jmeter.extractor;
-
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
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.hamcrest.CoreMatchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -63,9 +62,9 @@ public class TestBoundaryExtractor {
extractor.setScopeVariable("content");
extractor.setThreadContext(jmctx);
extractor.process();
- assertThat(vars.get("varname"), CoreMatchers.is("one"));
- assertThat("Indexed variable name should be null",
vars.get("varname_1"), CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat("MatchNumber is incorrect", vars.get("varname_matchNr"),
CoreMatchers.is(CoreMatchers.nullValue()));
+ assertEquals("one", vars.get("varname"));
+ assertNull(vars.get("varname_1"), "Indexed variable name should be
null");
+ assertNull(vars.get("varname_matchNr"), "MatchNumber is incorrect");
}
@Test
@@ -76,9 +75,9 @@ public class TestBoundaryExtractor {
extractor.setScopeVariable("content");
extractor.setThreadContext(jmctx);
extractor.process();
- assertThat("Non indexed variable name should be null",
vars.get("varname"), CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat("First match is incorrect", vars.get("varname_1"),
CoreMatchers.is("one"));
- assertThat("MatchNumber is incorrect", vars.get("varname_matchNr"),
CoreMatchers.is("1"));
+ assertNull(vars.get("varname"), "Non indexed variable name should be
null");
+ assertEquals("one", vars.get("varname_1"), "First match is incorrect");
+ assertEquals("1", vars.get("varname_matchNr"), "MatchNumber is
incorrect");
}
@Test
@@ -91,9 +90,9 @@ public class TestBoundaryExtractor {
extractor.setThreadContext(jmctx);
extractor.process();
- assertThat("Non indexed variable name should be null",
vars.get("varname"), CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat("First match is incorrect", vars.get("varname_1"),
CoreMatchers.is("ne"));
- assertThat("MatchNumber is incorrect", vars.get("varname_matchNr"),
CoreMatchers.is("1"));
+ assertNull(vars.get("varname"), "Non indexed variable name should be
null");
+ assertEquals("ne", vars.get("varname_1"), "First match is incorrect");
+ assertEquals("1", vars.get("varname_matchNr"), "MatchNumber is
incorrect");
}
@Test
@@ -105,8 +104,8 @@ public class TestBoundaryExtractor {
extractor.setScopeVariable("content");
extractor.setThreadContext(jmctx);
extractor.process();
- assertThat("Non indexed variable name should be null",
vars.get("varname"), CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat("First match is incorrect", vars.get("varname_1"),
CoreMatchers.is("on"));
- assertThat("MatchNumber is incorrect", vars.get("varname_matchNr"),
CoreMatchers.is("1"));
+ assertNull(vars.get("varname"), "Non indexed variable name should be
null");
+ assertEquals("on", vars.get("varname_1"), "First match is incorrect");
+ assertEquals("1", vars.get("varname_matchNr"), "MatchNumber is
incorrect");
}
}
diff --git
a/src/components/src/test/java/org/apache/jmeter/extractor/TestHtmlExtractorJSoup.java
b/src/components/src/test/java/org/apache/jmeter/extractor/TestHtmlExtractorJSoup.java
index 0d45695662..0fa76e7142 100644
---
a/src/components/src/test/java/org/apache/jmeter/extractor/TestHtmlExtractorJSoup.java
+++
b/src/components/src/test/java/org/apache/jmeter/extractor/TestHtmlExtractorJSoup.java
@@ -17,7 +17,6 @@
package org.apache.jmeter.extractor;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -25,7 +24,6 @@ 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.hamcrest.CoreMatchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -65,9 +63,9 @@ public class TestHtmlExtractorJSoup {
extractor.setScopeVariable("content");
extractor.setThreadContext(jmctx);
extractor.process();
- assertThat(vars.get("varname"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get("varname_1"),
CoreMatchers.is("http://jmeter.apache.org/"));
- assertThat(vars.get("varname_matchNr"), CoreMatchers.is("1"));
+ assertNull(vars.get("varname"));
+ assertEquals("http://jmeter.apache.org/", vars.get("varname_1"));
+ assertEquals("1", vars.get("varname_matchNr"));
}
@Test
@@ -82,10 +80,10 @@ public class TestHtmlExtractorJSoup {
extractor.setScopeVariable("content");
extractor.setThreadContext(jmctx);
extractor.process();
- assertThat(vars.get("varname"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get("varname_1"),
CoreMatchers.is("http://www.apache.org/"));
- assertThat(vars.get("varname_2"),
CoreMatchers.is("http://jmeter.apache.org/"));
- assertThat(vars.get("varname_matchNr"), CoreMatchers.is("2"));
+ assertNull(vars.get("varname"));
+ assertEquals("http://www.apache.org/", vars.get("varname_1"));
+ assertEquals("http://jmeter.apache.org/", vars.get("varname_2"));
+ assertEquals("2", vars.get("varname_matchNr"));
}
@Test
@@ -147,7 +145,7 @@ public class TestHtmlExtractorJSoup {
extractor.setAttribute("href");
extractor.setMatchNumber(-1);
extractor.process();
- assertThat(vars.get("regVal_matchNr"), CoreMatchers.is("2"));
+ assertEquals("2", vars.get("regVal_matchNr"));
assertEquals("http://example.com/", vars.get("regVal_1"));
assertEquals("http://example2.com/", vars.get("regVal_2"));
}
@@ -157,7 +155,7 @@ public class TestHtmlExtractorJSoup {
extractor.setExpression("b");
extractor.setMatchNumber(-1);
extractor.process();
- assertThat(vars.get("regVal_matchNr"), CoreMatchers.is("2"));
+ assertEquals("2", vars.get("regVal_matchNr"));
assertEquals("example1", vars.get("regVal_1"));
assertEquals("example2", vars.get("regVal_2"));
}
@@ -167,7 +165,7 @@ public class TestHtmlExtractorJSoup {
extractor.setExpression("c");
extractor.setMatchNumber(-1);
extractor.process();
- assertThat(vars.get("regVal_matchNr"), CoreMatchers.is("0"));
+ assertEquals("0", vars.get("regVal_matchNr"));
assertNull(vars.get("regVal"));
assertNull(vars.get("regVal_1"));
}
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 57d131bb1f..f82bf2cab9 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
@@ -17,8 +17,9 @@
package org.apache.jmeter.extractor;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.fail;
import java.nio.charset.StandardCharsets;
import java.util.function.Consumer;
@@ -30,7 +31,6 @@ import
org.apache.jmeter.testelement.AbstractScopedTestElement;
import org.apache.jmeter.threads.JMeterContext;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -93,7 +93,7 @@ class TestJSONPostProcessor {
context.setPreviousResult(sampleResult);
context.setVariables(vars);
processor.process();
- assertThat(vars.get("result"), CoreMatchers.is(resultObject));
+ assertEquals(resultObject, vars.get("result"));
}
@Test
@@ -108,9 +108,9 @@ class TestJSONPostProcessor {
context.setVariables(vars);
vars.put("contentvar", "[\"one\"]");
processor.process();
- assertThat(vars.get("varname"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
- assertThat(vars.get("varname_matchNr"), CoreMatchers.is("1"));
+ assertNull(vars.get("varname"));
+ assertEquals("one", vars.get("varname_1"));
+ assertEquals("1", vars.get("varname_matchNr"));
}
@Test
@@ -125,9 +125,9 @@ class TestJSONPostProcessor {
context.setVariables(vars);
vars.put("contentvar", "[\"one\", \"two\"]");
processor.process();
- assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
- assertThat(vars.get("varname_2"), CoreMatchers.is("two"));
- assertThat(vars.get("varname_matchNr"), CoreMatchers.is("2"));
+ assertEquals("one", vars.get("varname_1"));
+ assertEquals("two", vars.get("varname_2"));
+ assertEquals("2", vars.get("varname_matchNr"));
}
@Test
@@ -142,10 +142,13 @@ class TestJSONPostProcessor {
context.setVariables(vars);
vars.put("contentvar", "[\"one\", \"two\"]");
processor.process();
- assertThat(vars.get("varname"),
CoreMatchers.is(CoreMatchers.anyOf(CoreMatchers.is("one"),
CoreMatchers.is("two"))));
- assertThat(vars.get("varname_1"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get("varname_2"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get("varname_matchNr"),
CoreMatchers.is(CoreMatchers.nullValue()));
+ String varname = vars.get("varname");
+ if (!"one".equals(varname) && !"two".equals(varname)) {
+ fail("vars.get(\"varname\") should be one or two, got " + varname);
+ }
+ assertNull(vars.get("varname_1"));
+ assertNull(vars.get("varname_2"));
+ assertNull(vars.get("varname_matchNr"));
}
@Test
@@ -160,14 +163,14 @@ class TestJSONPostProcessor {
context.setVariables(vars);
vars.put("contentvar", "[\"one\", \"two\"]");
processor.process();
- assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
- assertThat(vars.get("varname_2"), CoreMatchers.is("two"));
- assertThat(vars.get("varname_matchNr"), CoreMatchers.is("2"));
+ assertEquals("one", vars.get("varname_1"));
+ assertEquals("two", vars.get("varname_2"));
+ assertEquals("2", vars.get("varname_matchNr"));
vars.put("contentvar", "");
processor.process();
- assertThat(vars.get("varname_matchNr"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get("varname_1"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get("varname_2"),
CoreMatchers.is(CoreMatchers.nullValue()));
+ assertNull(vars.get("varname_matchNr"));
+ assertNull(vars.get("varname_1"));
+ assertNull(vars.get("varname_2"));
}
@Test
@@ -182,13 +185,13 @@ class TestJSONPostProcessor {
context.setVariables(vars);
vars.remove("contentvar");
processor.process();
- assertThat(vars.get("varname"), CoreMatchers.is("NONE"));
- assertThat(vars.get("varname_matchNr"),
CoreMatchers.is(CoreMatchers.nullValue()));
+ assertEquals("NONE", vars.get("varname"));
+ assertNull(vars.get("varname_matchNr"));
vars.put("contentvar", "");
processor.process();
- assertThat(vars.get("varname"), CoreMatchers.is("NONE"));
- assertThat(vars.get("varname_matchNr"),
CoreMatchers.is(CoreMatchers.nullValue()));
+ assertEquals("NONE", vars.get("varname"));
+ assertNull(vars.get("varname_matchNr"));
}
@Test
@@ -203,16 +206,19 @@ class TestJSONPostProcessor {
context.setVariables(vars);
vars.put("contentvar", "[\"one\", \"two\"]");
processor.process();
- assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
- assertThat(vars.get("varname_2"), CoreMatchers.is("two"));
- assertThat(vars.get("varname_matchNr"), CoreMatchers.is("2"));
+ assertEquals("one", vars.get("varname_1"));
+ assertEquals("two", vars.get("varname_2"));
+ assertEquals("2", vars.get("varname_matchNr"));
vars.put("contentvar", "[\"A\", \"B\"]");
processor.setMatchNumbers("0");
processor.process();
- assertThat(vars.get("varname"),
CoreMatchers.is(CoreMatchers.anyOf(CoreMatchers.is("A"),
CoreMatchers.is("B"))));
- assertThat(vars.get("varname_matchNr"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get("varname_1"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get("varname_2"),
CoreMatchers.is(CoreMatchers.nullValue()));
+ String varname = vars.get("varname");
+ if (!"A".equals(varname) && !"B".equals(varname)) {
+ fail("vars.get(\"varname\") should be A or B, got " + varname);
+ }
+ assertNull(vars.get("varname_matchNr"));
+ assertNull(vars.get("varname_1"));
+ assertNull(vars.get("varname_2"));
}
private static Stream<Arguments> provideEmptyOrNullResultArgs() {
@@ -243,9 +249,9 @@ class TestJSONPostProcessor {
processor.setScopeAll();
processor.process();
- assertThat(vars.get(VAR_NAME), CoreMatchers.is(expectedResult));
- assertThat(vars.get(VAR_NAME + "_matchNr"),
CoreMatchers.is(expectedMatchNumber));
- assertThat(vars.get(VAR_NAME + "_1"),
CoreMatchers.is(CoreMatchers.nullValue()));
+ assertEquals(expectedResult, vars.get(VAR_NAME));
+ assertEquals(expectedMatchNumber, vars.get(VAR_NAME + "_matchNr"));
+ assertNull(vars.get(VAR_NAME + "_1"));
}
@Test
@@ -267,9 +273,9 @@ class TestJSONPostProcessor {
JSONParser parser = new JSONParser(0);
Object expectedValue = parser.parse(innerValue);
- assertThat(parser.parse(vars.get(VAR_NAME)),
CoreMatchers.is(expectedValue));
- assertThat(vars.get(VAR_NAME + "_matchNr"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get(VAR_NAME + "_1"),
CoreMatchers.is(CoreMatchers.nullValue()));
+ assertEquals(expectedValue, parser.parse(vars.get(VAR_NAME)));
+ assertNull(vars.get(VAR_NAME + "_matchNr"));
+ assertNull(vars.get(VAR_NAME + "_1"));
}
@Test
diff --git
a/src/components/src/test/java/org/apache/jmeter/extractor/TestRegexExtractor.java
b/src/components/src/test/java/org/apache/jmeter/extractor/TestRegexExtractor.java
index c4d42b97b1..4e39a7889e 100644
---
a/src/components/src/test/java/org/apache/jmeter/extractor/TestRegexExtractor.java
+++
b/src/components/src/test/java/org/apache/jmeter/extractor/TestRegexExtractor.java
@@ -18,7 +18,6 @@
package org.apache.jmeter.extractor;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -31,7 +30,6 @@ 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.hamcrest.CoreMatchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -76,9 +74,9 @@ public class TestRegexExtractor {
extractor.setThreadContext(jmctx);
extractor.setTemplate("$1$");
extractor.process();
- assertThat(vars.get("varname"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
- assertThat(vars.get("varname_matchNr"), CoreMatchers.is("1"));
+ assertNull(vars.get("varname"));
+ assertEquals("one", vars.get("varname_1"));
+ assertEquals("1", vars.get("varname_matchNr"));
}
@Test
@@ -91,10 +89,10 @@ public class TestRegexExtractor {
extractor.setThreadContext(jmctx);
extractor.setTemplate("$1$");
extractor.process();
- assertThat(vars.get("varname"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get("varname_1"), CoreMatchers.is("one"));
- assertThat(vars.get("varname_2"), CoreMatchers.is("two"));
- assertThat(vars.get("varname_matchNr"), CoreMatchers.is("2"));
+ assertNull(vars.get("varname"));
+ assertEquals("one", vars.get("varname_1"));
+ assertEquals("two", vars.get("varname_2"));
+ assertEquals("2", vars.get("varname_matchNr"));
}
@Test
diff --git
a/src/components/src/test/java/org/apache/jmeter/extractor/TestXPath2Extractor.java
b/src/components/src/test/java/org/apache/jmeter/extractor/TestXPath2Extractor.java
index 906f93a7a3..f7830a02c4 100644
---
a/src/components/src/test/java/org/apache/jmeter/extractor/TestXPath2Extractor.java
+++
b/src/components/src/test/java/org/apache/jmeter/extractor/TestXPath2Extractor.java
@@ -282,6 +282,6 @@ public class TestXPath2Extractor {
jmc.setPreviousResult(null);
extractor.setXPathQuery("/book/preface");
extractor.process();
- assertEquals(null, vars.get(VAL_NAME));
+ assertNull(vars.get(VAL_NAME));
}
}
diff --git
a/src/components/src/test/java/org/apache/jmeter/extractor/TestXPathExtractor.java
b/src/components/src/test/java/org/apache/jmeter/extractor/TestXPathExtractor.java
index 1bb72f696c..9cf66000d5 100644
---
a/src/components/src/test/java/org/apache/jmeter/extractor/TestXPathExtractor.java
+++
b/src/components/src/test/java/org/apache/jmeter/extractor/TestXPathExtractor.java
@@ -17,8 +17,6 @@
package org.apache.jmeter.extractor;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -274,15 +272,15 @@ public class TestXPathExtractor {
assertEquals(1, result.getAssertionResults().length);
AssertionResult firstResult = result.getAssertionResults()[0];
assertEquals(extractor.getName(), firstResult.getName());
- assertThat(
- "'<' is an invalid character in xpath, so it is expected to be
present in the error message",
+ assertContains(
firstResult.getFailureMessage(),
- containsString("<")
- );
+ "<",
+ "'<' is an invalid character in xpath, so it is expected to be
present in the error message");
if
(Locale.getDefault().getLanguage().startsWith(Locale.ENGLISH.getLanguage())) {
- assertThat(
+ assertContains(
firstResult.getFailureMessage(),
- containsString("A location path was expected, but the
following token was encountered")
+ "A location path was expected, but the following token was
encountered",
+ ""
);
}
assertEquals("Default", vars.get(VAL_NAME));
@@ -296,8 +294,9 @@ public class TestXPathExtractor {
extractor.process();
assertEquals(1, result.getAssertionResults().length);
assertEquals(extractor.getName(),
result.getAssertionResults()[0].getName());
- assertThat(result.getAssertionResults()[0].getFailureMessage(),
- containsString("Content is not allowed in prolog"));
+ assertContains(result.getAssertionResults()[0].getFailureMessage(),
+ "Content is not allowed in prolog",
+ "");
assertEquals("Default", vars.get(VAL_NAME));
assertEquals("0", vars.get(VAL_NAME_NR));
}
@@ -310,10 +309,15 @@ public class TestXPathExtractor {
assertEquals(1, result.getAssertionResults().length);
assertEquals(extractor.getName(),
result.getAssertionResults()[0].getName());
- assertThat(result.getAssertionResults()[0].getFailureMessage(),
- containsString("XML document structures must start and end
within the same entity"));
+ assertContains(result.getAssertionResults()[0].getFailureMessage(),
+ "XML document structures must start and end within the same
entity",
+ "");
assertEquals("Default", vars.get(VAL_NAME));
assertEquals("0", vars.get(VAL_NAME_NR));
}
+
+ private void assertContains(String value, String substring, String
message) {
+ assertTrue(value.contains(substring), () -> message + ": " + value + "
should contain " + substring);
+ }
}
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 d2e7f77dfe..0cce79b990 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
@@ -17,7 +17,9 @@
package org.apache.jmeter.extractor.json.jmespath;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.function.Consumer;
import java.util.stream.Stream;
@@ -27,7 +29,6 @@ import
org.apache.jmeter.testelement.AbstractScopedTestElement;
import org.apache.jmeter.threads.JMeterContext;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -64,7 +65,7 @@ class TestJMESPathExtractor {
JMESPathExtractor processor = setupProcessor(vars, sampleResult,
"[1]", false, "");
processor.setJmesPathExpression("[*]");
processor.process();
- assertThat(vars.get(REFERENCE_NAME), CoreMatchers.is("1"));
+ assertEquals("1", vars.get(REFERENCE_NAME));
}
private static Stream<Arguments> dataOneMatch() {
@@ -98,13 +99,13 @@ class TestJMESPathExtractor {
JMESPathExtractor processor = setupProcessor(vars, sampleResult, data,
fromVars, "-1");
processor.setJmesPathExpression(jmesPath);
processor.process();
- assertThat(vars.get(REFERENCE_NAME),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get(REFERENCE_NAME + "_1"),
CoreMatchers.is(expectedResult));
- assertThat(vars.get(REFERENCE_NAME_MATCH_NUMBER),
CoreMatchers.is(expectedMatchNumber));
+ assertNull(vars.get(REFERENCE_NAME));
+ assertEquals(expectedResult, vars.get(REFERENCE_NAME + "_1"));
+ assertEquals(expectedMatchNumber,
vars.get(REFERENCE_NAME_MATCH_NUMBER));
processor.clearOldRefVars(vars, REFERENCE_NAME);
- assertThat(vars.get(REFERENCE_NAME + "_1"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get(REFERENCE_NAME_MATCH_NUMBER),
CoreMatchers.is(CoreMatchers.nullValue()));
+ assertNull(vars.get(REFERENCE_NAME + "_1"));
+ assertNull(vars.get(REFERENCE_NAME_MATCH_NUMBER));
}
private static Stream<Arguments> dataMultipleMatches() {
@@ -137,11 +138,11 @@ class TestJMESPathExtractor {
// test1
processor.setJmesPathExpression(jmesPath);
processor.process();
- assertThat(vars.get(REFERENCE_NAME),
CoreMatchers.is(CoreMatchers.nullValue()));
+ assertNull(vars.get(REFERENCE_NAME));
for (int i = 0; i < expectedResults.length; i++) {
- assertThat(vars.get(REFERENCE_NAME + "_"+(i+1)),
CoreMatchers.is(expectedResults[i]));
+ assertEquals(expectedResults[i], vars.get(REFERENCE_NAME +
"_"+(i+1)));
}
- assertThat(vars.get(REFERENCE_NAME_MATCH_NUMBER),
CoreMatchers.is(expectedMatchNumber));
+ assertEquals(expectedMatchNumber,
vars.get(REFERENCE_NAME_MATCH_NUMBER));
}
private static final String TEST_DATA = "{\r\n" + " \"people\": [\r\n" +
" {\"first\": \"James\", \"last\": \"d\", \"age\":10},\r\n"
@@ -182,8 +183,8 @@ class TestJMESPathExtractor {
processor.setMatchNumber(matchNumber);
processor.setJmesPathExpression(jmesPath);
processor.process();
- assertThat(vars.get(REFERENCE_NAME), CoreMatchers.is(expectedResult));
- assertThat(vars.get(REFERENCE_NAME_MATCH_NUMBER),
CoreMatchers.is(expectedMatchNumber));
+ assertEquals(expectedResult, vars.get(REFERENCE_NAME));
+ assertEquals(expectedMatchNumber,
vars.get(REFERENCE_NAME_MATCH_NUMBER));
}
enum AccessMode {
@@ -232,9 +233,9 @@ class TestJMESPathExtractor {
accessMode.configure(processor);
processor.process();
- assertThat(vars.get(REFERENCE_NAME), CoreMatchers.is(resultObject));
- assertThat(vars.get(REFERENCE_NAME + "_1"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get(REFERENCE_NAME_MATCH_NUMBER),
CoreMatchers.is(resultCount));
+ assertEquals(resultObject, vars.get(REFERENCE_NAME));
+ assertNull(vars.get(REFERENCE_NAME + "_1"));
+ assertEquals(resultCount, vars.get(REFERENCE_NAME_MATCH_NUMBER));
}
private static Stream<Arguments> dataSourceVarOrResponse() {
@@ -250,9 +251,9 @@ class TestJMESPathExtractor {
processor.setJmesPathExpression("a.b.c.d");
processor.process();
- assertThat(vars.get(REFERENCE_NAME), CoreMatchers.is("value"));
- assertThat(vars.get(REFERENCE_NAME + "_1"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get(REFERENCE_NAME_MATCH_NUMBER),
CoreMatchers.is("1"));
+ assertEquals("value", vars.get(REFERENCE_NAME));
+ assertNull(vars.get(REFERENCE_NAME + "_1"));
+ assertEquals("1", vars.get(REFERENCE_NAME_MATCH_NUMBER));
}
@ParameterizedTest
@@ -264,11 +265,13 @@ class TestJMESPathExtractor {
processor.setJmesPathExpression("[*]");
processor.process();
- assertThat(vars.get(REFERENCE_NAME),
- CoreMatchers.is(CoreMatchers.anyOf(CoreMatchers.is("one"),
CoreMatchers.is("two"))));
- assertThat(vars.get(REFERENCE_NAME + "_1"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get(REFERENCE_NAME + "_2"),
CoreMatchers.is(CoreMatchers.nullValue()));
- assertThat(vars.get(REFERENCE_NAME_MATCH_NUMBER),
CoreMatchers.is("2"));
+ String varValue = vars.get(REFERENCE_NAME);
+ if (!"one".equals(varValue) && !"two".equals(varValue)) {
+ fail("vars.get(REFERENCE_NAME) should be one or two, got " +
varValue);
+ }
+ assertNull(vars.get(REFERENCE_NAME + "_1"));
+ assertNull(vars.get(REFERENCE_NAME + "_2"));
+ assertEquals("2", vars.get(REFERENCE_NAME_MATCH_NUMBER));
}
@ParameterizedTest
@@ -280,8 +283,8 @@ class TestJMESPathExtractor {
processor.setJmesPathExpression("[*]");
processor.process();
- assertThat(vars.get(REFERENCE_NAME), CoreMatchers.is(DEFAULT_VALUE));
- assertThat(vars.get(REFERENCE_NAME_MATCH_NUMBER),
CoreMatchers.is(CoreMatchers.nullValue()));
+ assertEquals(DEFAULT_VALUE, vars.get(REFERENCE_NAME));
+ assertNull(vars.get(REFERENCE_NAME_MATCH_NUMBER));
}
@ParameterizedTest
@@ -293,9 +296,9 @@ class TestJMESPathExtractor {
processor.setJmesPathExpression("$.k");
processor.process();
- assertThat(vars.get(REFERENCE_NAME), CoreMatchers.is(DEFAULT_VALUE));
- assertThat(vars.get(REFERENCE_NAME+ "_1"), CoreMatchers.nullValue());
- assertThat(vars.get(REFERENCE_NAME_MATCH_NUMBER),
CoreMatchers.nullValue());
+ assertEquals(DEFAULT_VALUE, vars.get(REFERENCE_NAME));
+ assertNull(vars.get(REFERENCE_NAME+ "_1"));
+ assertNull(vars.get(REFERENCE_NAME_MATCH_NUMBER));
}
@ParameterizedTest
@@ -307,9 +310,9 @@ class TestJMESPathExtractor {
processor.setJmesPathExpression("a.b.c.f");
processor.process();
- assertThat(vars.get(REFERENCE_NAME), CoreMatchers.is(DEFAULT_VALUE));
- assertThat(vars.get(REFERENCE_NAME+ "_1"), CoreMatchers.nullValue());
- assertThat(vars.get(REFERENCE_NAME_MATCH_NUMBER),
CoreMatchers.is("0"));
+ assertEquals(DEFAULT_VALUE, vars.get(REFERENCE_NAME));
+ assertNull(vars.get(REFERENCE_NAME+ "_1"));
+ assertEquals("0", vars.get(REFERENCE_NAME_MATCH_NUMBER));
}
@ParameterizedTest
@@ -321,8 +324,8 @@ class TestJMESPathExtractor {
processor.setJmesPathExpression("a.b");
processor.process();
- assertThat(vars.get(REFERENCE_NAME), CoreMatchers.is(DEFAULT_VALUE));
- assertThat(vars.get(REFERENCE_NAME+ "_1"), CoreMatchers.nullValue());
- assertThat(vars.get(REFERENCE_NAME_MATCH_NUMBER),
CoreMatchers.nullValue());
+ assertEquals(DEFAULT_VALUE, vars.get(REFERENCE_NAME));
+ assertNull(vars.get(REFERENCE_NAME+ "_1"));
+ assertNull(vars.get(REFERENCE_NAME_MATCH_NUMBER));
}
}
diff --git
a/src/components/src/test/java/org/apache/jmeter/timers/TimerServiceTest.java
b/src/components/src/test/java/org/apache/jmeter/timers/TimerServiceTest.java
index fa81878479..7f3f80234d 100644
---
a/src/components/src/test/java/org/apache/jmeter/timers/TimerServiceTest.java
+++
b/src/components/src/test/java/org/apache/jmeter/timers/TimerServiceTest.java
@@ -17,10 +17,8 @@
package org.apache.jmeter.timers;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.CoreMatchers;
-import org.hamcrest.Description;
-import org.hamcrest.MatcherAssert;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import org.junit.jupiter.api.Test;
public class TimerServiceTest {
@@ -31,48 +29,34 @@ public class TimerServiceTest {
public void testBigInitialDelayAndDontWait() {
long now = System.currentTimeMillis();
long adjustedDelay = sut.adjustDelay(Long.MAX_VALUE, now + 1000L,
false);
- MatcherAssert.assertThat("TimerService should return -1 as delay would
lead to a time after end time",
- adjustedDelay, CoreMatchers.is((long) -1));
+ assertEquals(
+ -1L,
+ adjustedDelay,
+ "TimerService should return -1 as delay would lead to a time
after end time");
}
@Test
public void testBigInitialDelayAndWait() {
long now = System.currentTimeMillis();
long adjustedDelay = sut.adjustDelay(Long.MAX_VALUE, now + 1000L);
- MatcherAssert.assertThat("TimerService should return -1 as delay would
lead to a time after end time",
- adjustedDelay, isAlmost(1000L, 200L));
- }
-
- private BaseMatcher<Long> isAlmost(long value, long precision) {
- return new BaseMatcher<Long>() {
-
- @Override
- public boolean matches(Object item) {
- if (item instanceof Long) {
- Long other = (Long) item;
- return Math.abs(other - value) < precision;
- }
- return false;
- }
-
- @Override
- public void describeTo(Description description) {
- description.appendText("the number is within a precision of "
+ precision + " near " + value);
- }
- };
+ assertEquals(1000.0, adjustedDelay, 200.0, "TimerService should return
-1 as delay would lead to a time after end time");
}
@Test
public void testSmallInitialDelay() {
long now = System.currentTimeMillis();
- MatcherAssert.assertThat("TimerService should not change the delay as
the end time is far away",
- sut.adjustDelay(1000L, now + 20000L), CoreMatchers.is(1000L));
+ assertEquals(
+ 1000L,
+ sut.adjustDelay(1000L, now + 20000L),
+ "TimerService should not change the delay as the end time is
far away");
}
@Test
public void testNegativeEndTime() {
- MatcherAssert.assertThat("TimerService should not change the delay as
the indicated end time is far away",
- sut.adjustDelay(1000L, -1), CoreMatchers.is(1000L));
+ assertEquals(
+ 1000L,
+ sut.adjustDelay(1000L, -1),
+ "TimerService should not change the delay as the indicated end
time is far away");
}
}
diff --git
a/src/components/src/test/java/org/apache/jmeter/visualizers/TestSampleCompareTo.java
b/src/components/src/test/java/org/apache/jmeter/visualizers/TestSampleCompareTo.java
index 586aca92b9..9e4fb3b4b6 100644
---
a/src/components/src/test/java/org/apache/jmeter/visualizers/TestSampleCompareTo.java
+++
b/src/components/src/test/java/org/apache/jmeter/visualizers/TestSampleCompareTo.java
@@ -17,11 +17,10 @@
package org.apache.jmeter.visualizers;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.stream.Stream;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -44,8 +43,7 @@ class TestSampleCompareTo {
@ParameterizedTest
@MethodSource("data")
void testCompareTo(long thisCount, long otherCount, int compareResult) {
- assertThat(sample(thisCount).compareTo(sample(otherCount)),
- CoreMatchers.is(compareResult));
+ assertEquals(compareResult,
sample(thisCount).compareTo(sample(otherCount)));
}
private Sample sample(long count) {
diff --git
a/src/core/src/test/java/org/apache/jmeter/report/core/CsvSampleReaderTest.java
b/src/core/src/test/java/org/apache/jmeter/report/core/CsvSampleReaderTest.java
index 1df86af511..3dc15c34d8 100644
---
a/src/core/src/test/java/org/apache/jmeter/report/core/CsvSampleReaderTest.java
+++
b/src/core/src/test/java/org/apache/jmeter/report/core/CsvSampleReaderTest.java
@@ -17,7 +17,6 @@
package org.apache.jmeter.report.core;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -28,7 +27,6 @@ import java.io.File;
import java.io.IOException;
import org.apache.jmeter.junit.JMeterTestCase;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -65,8 +63,7 @@ public class CsvSampleReaderTest extends JMeterTestCase {
@Test
public void testGetMetadata() {
try (CsvSampleReader reader = new CsvSampleReader(tempCsv, metadata)) {
- assertThat(reader.getMetadata().toString(),
- CoreMatchers.is(metadata.toString()));
+ assertEquals(metadata.toString(), reader.getMetadata().toString());
}
}
@@ -76,8 +73,7 @@ public class CsvSampleReaderTest extends JMeterTestCase {
for (long i = 0; i < NR_ROWS; i++) {
Sample expected = new SampleBuilder(metadata).add(i)
.add("a" + i).build();
- assertThat(reader.readSample().toString(),
- CoreMatchers.is(expected.toString()));
+ assertEquals(expected.toString(),
reader.readSample().toString());
}
}
}
@@ -88,8 +84,7 @@ public class CsvSampleReaderTest extends JMeterTestCase {
for (long i = 0; i < NR_ROWS; i++) {
Sample expected = new SampleBuilder(metadata).add(i)
.add("a" + i).build();
- assertThat(reader.peek().toString(),
- CoreMatchers.is(expected.toString()));
+ assertEquals(expected.toString(), reader.peek().toString());
reader.readSample();
}
}
diff --git
a/src/core/src/test/java/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumerTest.java
b/src/core/src/test/java/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumerTest.java
index 3056972432..952574d395 100644
---
a/src/core/src/test/java/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumerTest.java
+++
b/src/core/src/test/java/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumerTest.java
@@ -17,8 +17,10 @@
package org.apache.jmeter.report.processor.graph.impl;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashMap;
import java.util.Map;
@@ -65,16 +67,16 @@ public class CustomGraphConsumerTest {
@Test
public void testGetters() {
- assertThat(customGraphConsumer.getTitle(), equalTo("graph title"));
- assertThat(customGraphConsumer.getXAxis(), equalTo("X axis name"));
- assertThat(customGraphConsumer.getYAxis(), equalTo("Y axis name"));
- assertThat(customGraphConsumer.getContentMessage(), equalTo("content
message"));
- assertThat(customGraphConsumer.getSampleVariableName(),
equalTo("ulp_lag_ratio"));
- assertThat(customGraphConsumer.getIsNativeSampleVariableName(),
equalTo(false));
+ assertEquals("graph title", customGraphConsumer.getTitle());
+ assertEquals("X axis name", customGraphConsumer.getXAxis());
+ assertEquals("Y axis name", customGraphConsumer.getYAxis());
+ assertEquals("content message",
customGraphConsumer.getContentMessage());
+ assertEquals("ulp_lag_ratio",
customGraphConsumer.getSampleVariableName());
+ assertFalse(customGraphConsumer.getIsNativeSampleVariableName());
// bytes is one of the native sample variables names
customGraphConsumer.setSampleVariableName(CSVSaveService.CSV_BYTES);
- assertThat(customGraphConsumer.getIsNativeSampleVariableName(),
equalTo(true));
+ assertTrue(customGraphConsumer.getIsNativeSampleVariableName());
}
@Test
@@ -87,15 +89,15 @@ public class CustomGraphConsumerTest {
String key = entrySet.getKey();
if (key.equals("granularity")) {
- assertThat(testedValue, equalTo("60000"));
+ assertEquals("60000", testedValue);
} else if (key.equals("X_Axis")) {
- assertThat(testedValue, equalTo("\"X axis name\""));
+ assertEquals("\"X axis name\"", testedValue);
} else if (key.equals("Y_Axis")) {
- assertThat(testedValue, equalTo("\"Y axis name\""));
+ assertEquals("\"Y axis name\"", testedValue);
} else if (key.equals("sample_Metric_Name")) {
- assertThat(testedValue, equalTo("\"ulp_lag_ratio\""));
+ assertEquals("\"ulp_lag_ratio\"", testedValue);
} else if (key.equals("content_Message")) {
- assertThat(testedValue, equalTo("\"content message\""));
+ assertEquals("\"content message\"", testedValue);
}
}
}
@@ -104,30 +106,30 @@ public class CustomGraphConsumerTest {
public void testCreateTimeStampKeysSelector() {
TimeStampKeysSelector keysSelector = new TimeStampKeysSelector();
keysSelector.setSelectBeginTime(false);
-
assertThat(customGraphConsumer.createTimeStampKeysSelector().getGranularity(),
equalTo(keysSelector.getGranularity()));
+ assertEquals(keysSelector.getGranularity(),
customGraphConsumer.createTimeStampKeysSelector().getGranularity());
}
@Test
public void testCreateGroupInfos() {
// Testing defaults values
- assertThat(map.containsKey("Generic group"), equalTo(true));
- assertThat(map.containsKey("foo"), equalTo(false));
- assertThat(map.get("Generic group").getAggregatorFactory().getClass(),
-
equalTo(org.apache.jmeter.report.processor.MeanAggregatorFactory.class));
+ assertTrue(map.containsKey("Generic group"));
+ assertFalse(map.containsKey("foo"));
+
assertEquals(org.apache.jmeter.report.processor.MeanAggregatorFactory.class,
+ map.get("Generic group").getAggregatorFactory().getClass());
GroupData groupData = map.get("Generic group").getGroupData();
- assertThat(groupData.getOverallSeries(), equalTo(null));
- assertThat(groupData.getSeriesInfo(), equalTo(new HashMap<String,
SeriesData>()));
+ assertNull(groupData.getOverallSeries());
+ assertEquals(new HashMap<String, SeriesData>(),
groupData.getSeriesInfo());
// Testing native sample variable
customGraphConsumer.setSampleVariableName("bytes");
Sample sample = new Sample(0, sampleMetaData, data);
Double testedValue = map.get("Generic
group").getValueSelector().select("bytes", sample);
- assertThat(testedValue, equalTo(492.0));
+ assertEquals(492.0, testedValue);
// Testing non-native sample variable
customGraphConsumer.setSampleVariableName("mm-miss");
testedValue = map.get("Generic
group").getValueSelector().select("mm-miss", sample);
- assertThat(testedValue, equalTo(null));
+ assertNull(testedValue);
// Testing empty data value, the change between data and data2
// is on the last value that switchs from "null" to ""
@@ -136,7 +138,7 @@ public class CustomGraphConsumerTest {
"null", "null", "null", "null", "null", "null", "null",
"null", "null", "null", "null", "null", "null", ""};
sample = new Sample(0, sampleMetaData, data2);
testedValue = map.get("Generic
group").getValueSelector().select("mm-miss", sample);
- assertThat(testedValue, equalTo(null));
+ assertNull(testedValue);
}
// Test the exception when the column data is not a Double
@@ -154,7 +156,7 @@ public class CustomGraphConsumerTest {
public void testSelectMetric() {
Sample sample = new Sample(0, sampleMetaData, data);
String testString = map.get("Generic
group").getSeriesSelector().select(sample).toString();
- assertThat(testString, equalTo("[ulp_lag_ratio]"));
+ assertEquals("[ulp_lag_ratio]", testString);
}
// Create a static SampleMetadataObject
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 a2168564ef..b14f85f273 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
@@ -19,7 +19,7 @@ package org.apache.jmeter.samplers;
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -30,7 +30,6 @@ import java.util.stream.Stream;
import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.test.JMeterSerialTest;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -60,11 +59,11 @@ class TestDataStrippingSampleSender extends JMeterTestCase
implements JMeterSeri
SampleResult sample = result(successfulParent,
result(result(result())));
sut.sampleOccurred(event(sample));
assertResultsHaveContent(content, sample);
- assertThat(sample, CoreMatchers.is(nextSender.getResult()));
+ assertEquals(nextSender.getResult(), sample);
}
private void assertResultsHaveContent(String content, SampleResult sample)
{
- assertThat(sample.getResponseDataAsString(), CoreMatchers.is(content));
+ assertEquals(content, sample.getResponseDataAsString());
for (SampleResult subResult : sample.getSubResults()) {
assertResultsHaveContent(content, subResult);
}
diff --git
a/src/core/src/test/java/org/apache/jmeter/testelement/property/AbstractPropertyTest.java
b/src/core/src/test/java/org/apache/jmeter/testelement/property/AbstractPropertyTest.java
index f9d3d008fc..d632bc6441 100644
---
a/src/core/src/test/java/org/apache/jmeter/testelement/property/AbstractPropertyTest.java
+++
b/src/core/src/test/java/org/apache/jmeter/testelement/property/AbstractPropertyTest.java
@@ -17,7 +17,9 @@
package org.apache.jmeter.testelement.property;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.ArrayList;
import java.util.Collection;
@@ -27,7 +29,6 @@ import java.util.List;
import java.util.Map;
import org.apache.jmeter.testelement.TestElement;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -69,15 +70,15 @@ public class AbstractPropertyTest {
public void testNormalizeListWithEmptyList() {
Collection<JMeterProperty> emptyCollection = Collections.emptyList();
Collection<JMeterProperty> newCollection =
dummyProperty.normalizeList(emptyCollection);
- assertThat(newCollection, CoreMatchers.equalTo(emptyCollection));
+ assertEquals(emptyCollection, newCollection);
}
@Test
public void testNormalizeListWithEmptyArrayList() {
Collection<JMeterProperty> emptyCollection = new ArrayList<>();
Collection<JMeterProperty> newCollection =
dummyProperty.normalizeList(emptyCollection);
- assertThat(newCollection,
CoreMatchers.not(CoreMatchers.sameInstance(emptyCollection)));
- assertThat(newCollection, CoreMatchers.equalTo(emptyCollection));
+ assertNotSame(emptyCollection, newCollection);
+ assertEquals(emptyCollection, newCollection);
}
@Test
@@ -85,23 +86,23 @@ public class AbstractPropertyTest {
List<JMeterProperty> filledCollection = new ArrayList<>();
filledCollection.add(new StringProperty("key", "value"));
Collection<JMeterProperty> newCollection =
dummyProperty.normalizeList(filledCollection);
- assertThat(newCollection,
CoreMatchers.not(CoreMatchers.sameInstance(filledCollection)));
- assertThat(newCollection, CoreMatchers.equalTo(filledCollection));
+ assertNotSame(filledCollection, newCollection);
+ assertEquals(filledCollection, newCollection);
}
@Test
public void testNormalizeListWithEmptyMap() {
Map<String, JMeterProperty> emptyCollection = Collections.emptyMap();
Map<String, JMeterProperty> newCollection =
dummyProperty.normalizeMap(emptyCollection);
- assertThat(newCollection, CoreMatchers.nullValue());
+ assertNull(newCollection);
}
@Test
public void testNormalizeMapWithEmptyHashMap() {
Map<String, JMeterProperty> emptyCollection = new HashMap<>();
Map<String, JMeterProperty> newCollection =
dummyProperty.normalizeMap(emptyCollection);
- assertThat(newCollection,
CoreMatchers.not(CoreMatchers.sameInstance(emptyCollection)));
- assertThat(newCollection, CoreMatchers.equalTo(emptyCollection));
+ assertNotSame(emptyCollection, newCollection);
+ assertEquals(emptyCollection, newCollection);
}
@Test
@@ -109,7 +110,7 @@ public class AbstractPropertyTest {
Map<String, JMeterProperty> filledCollection = new HashMap<>();
filledCollection.put("someKey", new StringProperty("key", "value"));
Map<String, JMeterProperty> newCollection =
dummyProperty.normalizeMap(filledCollection);
- assertThat(newCollection,
CoreMatchers.not(CoreMatchers.sameInstance(filledCollection)));
- assertThat(newCollection, CoreMatchers.equalTo(filledCollection));
+ assertNotSame(filledCollection, newCollection);
+ assertEquals(filledCollection, newCollection);
}
}
diff --git
a/src/core/src/test/java/org/apache/jmeter/testelement/property/MapPropertyTest.java
b/src/core/src/test/java/org/apache/jmeter/testelement/property/MapPropertyTest.java
index d229f7619c..40937d0450 100644
---
a/src/core/src/test/java/org/apache/jmeter/testelement/property/MapPropertyTest.java
+++
b/src/core/src/test/java/org/apache/jmeter/testelement/property/MapPropertyTest.java
@@ -17,12 +17,11 @@
package org.apache.jmeter.testelement.property;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import java.util.Map;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
public class MapPropertyTest {
@@ -36,13 +35,13 @@ public class MapPropertyTest {
@Test
public void testGetPropertyTypeOfEmptyMap() {
MapProperty props = new MapProperty("foo", new HashMap<>());
- assertThat(props.getPropertyType(),
CoreMatchers.equalTo(NullProperty.class));
+ assertEquals(NullProperty.class, props.getPropertyType());
}
public void testGetPropertyTypeOfStringElements() {
Map<String, Integer> numberMap = new HashMap<>();
numberMap.put("One", 1);
MapProperty props = new MapProperty("foo", numberMap);
- assertThat(props.getPropertyType(),
CoreMatchers.equalTo(IntegerProperty.class));
+ assertEquals(IntegerProperty.class, props.getPropertyType());
}
}
diff --git
a/src/core/src/test/java/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
b/src/core/src/test/java/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
index 3a6b68bbb7..4b04e6bd1a 100644
---
a/src/core/src/test/java/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
+++
b/src/core/src/test/java/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
@@ -17,15 +17,15 @@
package org.apache.jmeter.threads;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
@@ -47,12 +47,12 @@ public class TestUnmodifiableJMeterVariables {
@Test
public void testGetThreadName() {
- assertThat(unmodifiables.getThreadName(),
CoreMatchers.is(vars.getThreadName()));
+ assertEquals(vars.getThreadName(), unmodifiables.getThreadName());
}
@Test
public void testGetIteration() {
- assertThat(unmodifiables.getIteration(),
CoreMatchers.is(vars.getIteration()));
+ assertEquals(vars.getIteration(), unmodifiables.getIteration());
}
@Test
@@ -92,18 +92,18 @@ public class TestUnmodifiableJMeterVariables {
@Test
public void testGet() {
- assertThat(unmodifiables.get(MY_KEY),
CoreMatchers.is(vars.get(MY_KEY)));
+ assertEquals(vars.get(MY_KEY), unmodifiables.get(MY_KEY));
}
@Test
public void testGetObject() {
- assertThat(unmodifiables.getObject(MY_OBJECT_KEY),
CoreMatchers.is(vars.getObject(MY_OBJECT_KEY)));
+ assertEquals(vars.getObject(MY_OBJECT_KEY),
unmodifiables.getObject(MY_OBJECT_KEY));
}
@Test
public void testGetIteratorIsUnmodifable() {
Iterator<Map.Entry<String, Object>> iterator =
unmodifiables.getIterator();
- assertThat(iterator.hasNext(), CoreMatchers.is(true));
+ assertTrue(iterator.hasNext());
iterator.next();
assertThrowsUnsupportedOperation(iterator::remove);
}
@@ -117,7 +117,7 @@ public class TestUnmodifiableJMeterVariables {
@Test
public void testGetIterator() {
- assertThat(iteratorToMap(unmodifiables.getIterator()),
CoreMatchers.is(iteratorToMap(vars.getIterator())));
+ assertEquals(iteratorToMap(vars.getIterator()),
iteratorToMap(unmodifiables.getIterator()));
}
private <K, V> Map<K, V> iteratorToMap(Iterator<Map.Entry<K, V>> it) {
@@ -131,29 +131,29 @@ public class TestUnmodifiableJMeterVariables {
@Test
public void testEntrySet() {
- assertThat(unmodifiables.entrySet(), CoreMatchers.is(vars.entrySet()));
+ assertEquals(vars.entrySet(), unmodifiables.entrySet());
}
@Test
public void testEqualsObjectSymmetry() {
UnmodifiableJMeterVariables otherUnmodifiables = new
UnmodifiableJMeterVariables(vars);
- assertThat(unmodifiables, CoreMatchers.is(otherUnmodifiables));
- assertThat(otherUnmodifiables, CoreMatchers.is(unmodifiables));
+ assertEquals(otherUnmodifiables, unmodifiables);
+ assertEquals(unmodifiables, otherUnmodifiables);
}
@Test
public void testEqualsObjectReflexivity() {
- assertThat(unmodifiables, CoreMatchers.is(unmodifiables));
+ assertEquals(unmodifiables, unmodifiables);
}
@Test
public void testEqualsObjectWithJMeterVariables() {
- assertThat(unmodifiables.equals(vars),
CoreMatchers.is(vars.equals(unmodifiables)));
+ assertEquals(vars.equals(unmodifiables), unmodifiables.equals(vars));
}
@Test
public void testHashCode() {
UnmodifiableJMeterVariables otherUnmodifiables = new
UnmodifiableJMeterVariables(vars);
- assertThat(unmodifiables.hashCode(),
CoreMatchers.is(otherUnmodifiables.hashCode()));
+ assertEquals(otherUnmodifiables.hashCode(), unmodifiables.hashCode());
}
}
diff --git
a/src/core/src/test/java/org/apache/jmeter/util/JSR223TestElementTest.java
b/src/core/src/test/java/org/apache/jmeter/util/JSR223TestElementTest.java
index 1beb45840c..1a3ca4da8f 100644
--- a/src/core/src/test/java/org/apache/jmeter/util/JSR223TestElementTest.java
+++ b/src/core/src/test/java/org/apache/jmeter/util/JSR223TestElementTest.java
@@ -17,9 +17,9 @@
package org.apache.jmeter.util;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
@@ -34,15 +34,15 @@ public class JSR223TestElementTest {
@DisabledForJreRange(min = JRE.JAVA_15, max = JRE.OTHER, disabledReason =
"The default JavaScript engine has been removed in Java 15+")
public void testGetScriptEngineJS() throws Exception {
element.setScriptLanguage("JavaScript");
- assertThat(element.getScriptEngine().getFactory().getLanguageName(),
- CoreMatchers.containsString("Script"));
+ String languageName =
element.getScriptEngine().getFactory().getLanguageName();
+ assertTrue(languageName.contains("Script"),
+ () -> "getFactory().getLanguageName() should contain Script,
got " + languageName);
}
@Test
public void testGetScriptEngineDefault() throws Exception {
element.setScriptLanguage("");
- assertThat(element.getScriptEngine().getFactory().getLanguageName(),
- CoreMatchers.is("Groovy"));
+ assertEquals("Groovy",
element.getScriptEngine().getFactory().getLanguageName());
}
}
diff --git a/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java
b/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java
index 3ebf8c2cd3..3f95fc8de2 100644
--- a/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java
+++ b/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java
@@ -17,7 +17,6 @@
package org.apache.jmeter.util;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -39,7 +38,6 @@ import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;
import org.apache.jmeter.assertions.AssertionResult;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -146,22 +144,25 @@ public class XPathUtilTest {
@Test
public void testFormatXmlSimple() {
- assertThat(XPathUtil.formatXml("<one foo='bar'>Test</one>"),
- CoreMatchers.is("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<one foo=\"bar\">Test</one>" + lineSeparator));
+ assertEquals(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ + "<one foo=\"bar\">Test</one>" + lineSeparator,
+ XPathUtil.formatXml("<one foo='bar'>Test</one>"));
}
@Test
public void testFormatXmlComplex() {
- assertThat(
- XPathUtil.formatXml(
- "<one foo='bar'><two/><three><four
p=\"1\"/></three>...</one>"),
- CoreMatchers.is(String.join(lineSeparator, "<?xml
version=\"1.0\" encoding=\"UTF-8\"?><one foo=\"bar\">",
+ assertEquals(
+ String.join(
+ lineSeparator,
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><one
foo=\"bar\">",
" <two/>",
" <three>",
" <four p=\"1\"/>",
" </three>...</one>",
- "")));
+ ""),
+ XPathUtil.formatXml(
+ "<one foo='bar'><two/><three><four
p=\"1\"/></three>...</one>"));
}
@Test
@@ -175,8 +176,7 @@ public class XPathUtilTest {
// ignore output
}
}));
- assertThat("No well formed xml here", CoreMatchers
- .is(XPathUtil.formatXml("No well formed xml here")));
+ assertEquals("No well formed xml here", XPathUtil.formatXml("No
well formed xml here"));
} finally {
System.setErr(origErr);
}
diff --git
a/src/core/src/test/kotlin/org/apache/jmeter/gui/AbstractJMeterGuiComponentTest.kt
b/src/core/src/test/kotlin/org/apache/jmeter/gui/AbstractJMeterGuiComponentTest.kt
index 38c17c4bba..37e36fca39 100644
---
a/src/core/src/test/kotlin/org/apache/jmeter/gui/AbstractJMeterGuiComponentTest.kt
+++
b/src/core/src/test/kotlin/org/apache/jmeter/gui/AbstractJMeterGuiComponentTest.kt
@@ -18,7 +18,7 @@
package org.apache.jmeter.gui
import org.apache.jmeter.testelement.TestElement
-import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import javax.swing.JPopupMenu
@@ -37,9 +37,9 @@ class AbstractJMeterGuiComponentTest {
override fun getMenuCategories(): MutableCollection<String> =
TODO()
}
- assertEquals(true, element.isEnabled, "element.isEnabled after
creation of the element")
+ assertTrue(element.isEnabled, "element.isEnabled after creation of the
element")
element.clearGui()
- assertEquals(true, element.isEnabled, "element.isEnabled after
element.clearGui()")
+ assertTrue(element.isEnabled, "element.isEnabled after
element.clearGui()")
}
}
diff --git
a/src/dist-check/src/test/java/org/apache/jorphan/reflect/TestClassFinder.java
b/src/dist-check/src/test/java/org/apache/jorphan/reflect/TestClassFinder.java
index 182bfd1643..488b59da1a 100644
---
a/src/dist-check/src/test/java/org/apache/jorphan/reflect/TestClassFinder.java
+++
b/src/dist-check/src/test/java/org/apache/jorphan/reflect/TestClassFinder.java
@@ -27,8 +27,6 @@ import java.util.List;
import org.apache.jmeter.junit.JMeterTestUtils;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.logging.log4j.LoggingException;
-import org.hamcrest.CoreMatchers;
-import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -53,7 +51,9 @@ public class TestClassFinder {
List<String> findClassesThatExtend = ClassFinder.findClassesThatExtend(
libDirs,
new Class<?>[] { Exception.class });
- MatcherAssert.assertThat(findClassesThatExtend,
CoreMatchers.hasItem(LoggingException.class.getName()));
+ assertTrue(
+
findClassesThatExtend.contains(LoggingException.class.getName()),
+ () -> "findClassesThatExtend(.., Exception.class) should
contain LoggingException, got " + findClassesThatExtend);
}
@Test
@@ -74,7 +74,9 @@ public class TestClassFinder {
new Class<?>[] { Exception.class },
false);
assertTrue(findClassesThatExtend.stream().noneMatch(s ->
s.contains("$")));
- MatcherAssert.assertThat(findClassesThatExtend,
CoreMatchers.hasItem(LoggingException.class.getName()));
+ assertTrue(
+
findClassesThatExtend.contains(LoggingException.class.getName()),
+ () -> "findClassesThatExtend(.., Exception.class) should
contain LoggingException, got " + findClassesThatExtend);
}
@Test
diff --git a/src/dist/src/dist/expected_release_jars.csv
b/src/dist/src/dist/expected_release_jars.csv
index 283887ad23..63e0fc6317 100644
--- a/src/dist/src/dist/expected_release_jars.csv
+++ b/src/dist/src/dist/expected_release_jars.csv
@@ -69,7 +69,6 @@
223993,groovy-xml-5.0.2.jar
123360,hamcrest-2.2.jar
1499,hamcrest-core-2.2.jar
-109741,hamcrest-date-2.0.8.jar
181512,httpasyncclient-4.1.5.jar
785639,httpclient-4.5.14.jar
327891,httpcore-4.4.16.jar
diff --git a/src/functions/build.gradle.kts b/src/functions/build.gradle.kts
index 34bf2366dc..b948246962 100644
--- a/src/functions/build.gradle.kts
+++ b/src/functions/build.gradle.kts
@@ -35,6 +35,4 @@ dependencies {
}
implementation("com.github.ben-manes.caffeine:caffeine")
implementation("oro:oro")
- testImplementation("org.hamcrest:hamcrest-core")
- testImplementation("org.exparity:hamcrest-date")
}
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 486097fbb9..f024819350 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,8 +17,14 @@
package org.apache.jmeter.functions;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
import org.apache.jmeter.engine.util.CompoundVariable;
import org.apache.jmeter.junit.JMeterTestCase;
@@ -26,8 +32,6 @@ 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.hamcrest.CoreMatchers;
-import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -72,10 +76,13 @@ public class TestRandomFromMultipleVars extends
JMeterTestCase {
params.add(new CompoundVariable("var1|var2"));
function.setParameters(params);
String returnValue = function.execute(result, null);
- MatcherAssert.assertThat(returnValue,
- CoreMatchers.anyOf(CoreMatchers.is("var1_value"),
- CoreMatchers.is("var2_value1"),
- CoreMatchers.is("var2_value2")));
+
+ Set<String> expectedValues = new HashSet<>(
+ Arrays.asList("var1_value", "var2_value1", "var2_value2")
+ );
+ assertTrue(
+ expectedValues.contains(returnValue),
+ () -> returnValue + " should be one of " + expectedValues);
Assertions.assertNull(vars.get("outputVar"));
}
@@ -87,7 +94,7 @@ public class TestRandomFromMultipleVars extends
JMeterTestCase {
params.add(new CompoundVariable("var1"));
function.setParameters(params);
String returnValue = function.execute(result, null);
- Assertions.assertEquals("value1", returnValue);
+ assertEquals("value1", returnValue);
Assertions.assertNull(vars.get("outputVar"));
}
@@ -100,7 +107,7 @@ public class TestRandomFromMultipleVars extends
JMeterTestCase {
params.add(new CompoundVariable("outputVar"));
function.setParameters(params);
String returnValue = function.execute(result, null);
- Assertions.assertEquals("value1", returnValue);
- Assertions.assertEquals("value1", vars.get("outputVar"));
+ assertEquals("value1", returnValue);
+ assertEquals("value1", vars.get("outputVar"));
}
}
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 b0e99fd660..95de9d9384 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
@@ -18,9 +18,7 @@
package org.apache.jmeter.functions;
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.jupiter.api.Assertions.assertEquals;
import java.time.LocalDate;
import java.time.ZoneId;
@@ -80,7 +78,7 @@ public class TestTimeRandomDateFunction extends
JMeterTestCase {
Collection<CompoundVariable> params = makeParams("yyyy-dd-MM", "",
endDate, "", "");
function.setParameters(params);
value = function.execute(result, null);
- Assertions.assertEquals(10, value.length());
+ assertEquals(10, value.length());
}
@Test
@@ -104,7 +102,7 @@ public class TestTimeRandomDateFunction extends
JMeterTestCase {
Collection<CompoundVariable> params = makeParams(formatDate, "",
endDate, "", "");
function.setParameters(params);
value = function.execute(result, null);
- Assertions.assertEquals(8, value.length());
+ assertEquals(8, value.length());
}
@Test
@@ -116,7 +114,7 @@ public class TestTimeRandomDateFunction extends
JMeterTestCase {
Collection<CompoundVariable> params = makeParams(formatDate,
startDate, endDate, localeAsString, "");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("29 Aug 2111")));
+ assertEquals("29 Aug 2111", value);
}
@Test
@@ -128,7 +126,7 @@ public class TestTimeRandomDateFunction extends
JMeterTestCase {
Collection<CompoundVariable> params = makeParams(formatDate,
startDate, endDate, localeAsString, "");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("29 mars 2111")));
+ assertEquals("29 mars 2111", value);
}
@Test
@@ -140,7 +138,7 @@ public class TestTimeRandomDateFunction extends
JMeterTestCase {
Collection<CompoundVariable> params = makeParams(formatDate,
startDate, endDate, localeAsString, "");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("2111-03-29")));
+ assertEquals("2111-03-29", value);
}
@Test
@@ -152,7 +150,7 @@ public class TestTimeRandomDateFunction extends
JMeterTestCase {
Collection<CompoundVariable> params = makeParams(formatDate,
startDate, endDate, localeAsString, "");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("")));
+ assertEquals("", value);
}
@Test
@@ -164,7 +162,7 @@ public class TestTimeRandomDateFunction extends
JMeterTestCase {
Collection<CompoundVariable> params = makeParams(formatDate,
startDate, endDate, localeAsString, null);
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("2111-03-29")));
+ assertEquals("2111-03-29", value);
}
@Test
@@ -176,8 +174,8 @@ public class TestTimeRandomDateFunction extends
JMeterTestCase {
Collection<CompoundVariable> params = makeParams(formatDate,
startDate, endDate, localeAsString, "MY_VAR");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("2111-03-29")));
- assertThat(vars.get("MY_VAR"), is(equalTo("2111-03-29")));
+ assertEquals("2111-03-29", value);
+ assertEquals("2111-03-29", vars.get("MY_VAR"));
}
@Test
@@ -189,7 +187,7 @@ public class TestTimeRandomDateFunction extends
JMeterTestCase {
Collection<CompoundVariable> params = makeParams(formatDate,
startDate, endDate, localeAsString, "");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("")));
+ assertEquals("", value);
}
@Test
@@ -201,7 +199,7 @@ public class TestTimeRandomDateFunction extends
JMeterTestCase {
Collection<CompoundVariable> params = makeParams(formatDate,
startDate, endDate, localeAsString, "");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("")));
+ assertEquals("", value);
}
@Test
@@ -213,6 +211,6 @@ public class TestTimeRandomDateFunction extends
JMeterTestCase {
Collection<CompoundVariable> params = makeParams(formatDate,
startDate, endDate, localeAsString, "");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("")));
+ assertEquals("", value);
}
}
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 a307ed8334..b93829c13e 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
@@ -18,11 +18,8 @@
package org.apache.jmeter.functions;
import static org.apache.jmeter.functions.FunctionTestHelper.makeParams;
-import static org.exparity.hamcrest.date.LocalDateMatchers.sameDay;
-import static org.exparity.hamcrest.date.LocalDateTimeMatchers.within;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import java.time.Duration;
import java.time.Instant;
@@ -31,7 +28,6 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
-import java.time.temporal.ChronoUnit;
import java.time.zone.ZoneRules;
import java.util.Collection;
import java.util.Random;
@@ -66,12 +62,19 @@ class TestTimeShiftFunction extends JMeterTestCase {
function = new TimeShift();
}
+ private void assertDateEquals(LocalDateTime expected, LocalDateTime
actual, Duration delta) {
+ Duration diff = Duration.between(expected, actual);
+ if (diff.abs().compareTo(delta) > 0) {
+ fail(expected + " should be within " + delta + " of " + actual +
", actual diff is " + diff);
+ }
+ }
+
@Test
void testDatePlusOneDay() throws Exception {
Collection<CompoundVariable> params = makeParams("yyyy-dd-MM",
"2017-01-01", "P1D", "");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("2017-02-01")));
+ assertEquals("2017-02-01", value);
}
@Test
@@ -79,7 +82,7 @@ class TestTimeShiftFunction extends JMeterTestCase {
Collection<CompoundVariable> params = makeParams("yyyy-dd-MM",
"2017-01-01", "P1d", "VAR");
function.setParameters(params);
function.execute(result, null);
- assertThat(vars.get("VAR"), is(equalTo("2017-02-01")));
+ assertEquals("2017-02-01", vars.get("VAR"));
}
@Test
@@ -87,7 +90,7 @@ class TestTimeShiftFunction extends JMeterTestCase {
Collection<CompoundVariable> params = makeParams("yyyy-dd-MM HH:m",
"2017-01-01 12:00", "P+32dT-1H-5m", "VAR");
function.setParameters(params);
String value = function.execute(result, null);
- assertThat(value, is(equalTo("2017-02-02 10:55")));
+ assertEquals("2017-02-02 10:55", value);
}
@Test
@@ -98,7 +101,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(ZoneId.systemDefault())));
+ assertDateEquals(LocalDateTime.now(ZoneId.systemDefault()),
nowFromFunction, Duration.ofSeconds(5));
}
@Test
@@ -108,7 +111,7 @@ class TestTimeShiftFunction extends JMeterTestCase {
value = function.execute(result, null);
LocalDate tomorrow = LocalDate.now(ZoneId.systemDefault()).plusDays(1);
LocalDate tomorrowFromFunction = LocalDate.parse(value);
- assertThat(tomorrowFromFunction, sameDay(tomorrow));
+ assertEquals(tomorrow, tomorrowFromFunction);
}
@Test
@@ -123,7 +126,7 @@ class TestTimeShiftFunction extends JMeterTestCase {
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));
+ assertDateEquals(futureDate, futureDateFromFunction,
Duration.ofSeconds(1));
}
private static BooleanSupplier dstChangeAhead(String duration) {
@@ -150,7 +153,7 @@ class TestTimeShiftFunction extends JMeterTestCase {
DateTimeFormatter dateFormat =
DateTimeFormatter.ofPattern("yyyy-MM-dd' 'HH:mm:ss");
LocalDateTime baseDate = LocalDateTime.parse("2017-12-21 12:00:00",
dateFormat);
LocalDateTime futureDate =
baseDate.plusDays(10).plusHours(-1).plusMinutes(-5).plusSeconds(5);
- assertThat(futureDateFromFunction, within(1, ChronoUnit.SECONDS,
futureDate));
+ assertDateEquals(futureDate, futureDateFromFunction,
Duration.ofSeconds(1));
}
@Test
@@ -165,8 +168,7 @@ class TestTimeShiftFunction extends JMeterTestCase {
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(pattern);
LocalDateTime baseDate = ZonedDateTime.parse(timeString,
dateFormat).toLocalDateTime();
LocalDateTime futureDate =
baseDate.plusDays(10).plusHours(-1).plusMinutes(-5).plusSeconds(5);
- assertThat(futureDateFromFunction.toLocalDateTime(), within(1,
ChronoUnit.SECONDS, futureDate));
-
+ assertDateEquals(futureDate, futureDateFromFunction.toLocalDateTime(),
Duration.ofSeconds(1));
}
static void main(String[] args) {
@@ -182,7 +184,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(ZoneId.systemDefault())));
+ assertDateEquals(LocalDateTime.now(ZoneId.systemDefault()),
nowFromFunction, Duration.ofSeconds(5));
}
@Test
@@ -190,7 +192,7 @@ class TestTimeShiftFunction extends JMeterTestCase {
Collection<CompoundVariable> params = makeParams("hjfdjyra:fd", "",
"P1D", "");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("")));
+ assertEquals("", value);
}
@Test
@@ -203,13 +205,13 @@ class TestTimeShiftFunction extends JMeterTestCase {
value = function.execute(result, null);
LocalDateTime randomFutureDate = LocalDateTime.parse(value);
LocalDateTime checkFutureDate =
LocalDateTime.now(ZoneId.systemDefault()).plusMinutes(randomInt);
- assertThat(randomFutureDate, within(5, ChronoUnit.SECONDS,
checkFutureDate));
+ assertDateEquals(checkFutureDate, randomFutureDate,
Duration.ofSeconds(5));
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(ZoneId.systemDefault()).plusMinutes(randomInt);
- assertThat(randomFutureDate, within(5, ChronoUnit.SECONDS,
checkFutureDate));
+ assertDateEquals(checkFutureDate, randomFutureDate,
Duration.ofSeconds(5));
}
@Test
@@ -217,19 +219,19 @@ class TestTimeShiftFunction extends JMeterTestCase {
Collection<CompoundVariable> params = makeParams("yyyy-MMMM-dd",
"2017-juillet-01", "P1D", "fr_FR", "");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("2017-juillet-02")));
+ assertEquals("2017-juillet-02", value);
params = makeParams("yyyy-MMMM-dd", "2017-July-01", "P1D", "en_EN",
"");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("2017-July-02")));
+ assertEquals("2017-July-02", value);
params = makeParams("yyyy-MMMM-dd", "2017-julio-01", "P1D", "es_ES",
"");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("2017-julio-02")));
+ assertEquals("2017-julio-02", value);
params = makeParams("yyyy-MMMM-dd", "2017-Juli-01", "P1D", "de_DE",
"");
function.setParameters(params);
value = function.execute(result, null);
- assertThat(value, is(equalTo("2017-Juli-02")));
+ assertEquals("2017-Juli-02", value);
}
}
diff --git
a/src/jorphan/src/test/java/org/apache/jorphan/gui/MinMaxLongRendererTest.java
b/src/jorphan/src/test/java/org/apache/jorphan/gui/MinMaxLongRendererTest.java
index 0e92b30d10..fea48b24ee 100644
---
a/src/jorphan/src/test/java/org/apache/jorphan/gui/MinMaxLongRendererTest.java
+++
b/src/jorphan/src/test/java/org/apache/jorphan/gui/MinMaxLongRendererTest.java
@@ -17,11 +17,11 @@
package org.apache.jorphan.gui;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
-import org.hamcrest.CoreMatchers;
-import org.hamcrest.MatcherAssert;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -48,7 +48,7 @@ class MinMaxLongRendererTest {
@Override
public void setText(String text) {
if (afterInit.get()) {
- MatcherAssert.assertThat(text, CoreMatchers.is(expected));
+ assertEquals(expected, text);
}
}
};
diff --git
a/src/jorphan/src/test/java/org/apache/jorphan/gui/ObjectTableSorterTest.java
b/src/jorphan/src/test/java/org/apache/jorphan/gui/ObjectTableSorterTest.java
index f776065fcc..4f51f6f485 100644
---
a/src/jorphan/src/test/java/org/apache/jorphan/gui/ObjectTableSorterTest.java
+++
b/src/jorphan/src/test/java/org/apache/jorphan/gui/ObjectTableSorterTest.java
@@ -21,14 +21,11 @@ import static java.lang.String.format;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
-import static org.hamcrest.CoreMatchers.allOf;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -48,7 +45,6 @@ import javax.swing.RowSorter.SortKey;
import javax.swing.SortOrder;
import org.apache.jorphan.reflect.Functor;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -145,25 +141,25 @@ public class ObjectTableSorterTest {
@Test
public void getDefaultComparatorForNullClass() {
ObjectTableSorter sorter = new
ObjectTableSorter(createTableModel("null", null));
- assertThat(sorter.getValueComparator(0), is(nullValue()));
+ assertNull(sorter.getValueComparator(0));
}
@Test
public void getDefaultComparatorForStringClass() {
ObjectTableSorter sorter = new
ObjectTableSorter(createTableModel("string", String.class));
- assertThat(sorter.getValueComparator(0),
is(CoreMatchers.notNullValue()));
+ assertNotNull(sorter.getValueComparator(0));
}
@Test
public void getDefaultComparatorForIntegerClass() {
ObjectTableSorter sorter = new
ObjectTableSorter(createTableModel("integer", Integer.class));
- assertThat(sorter.getValueComparator(0),
is(CoreMatchers.notNullValue()));
+ assertNotNull(sorter.getValueComparator(0));
}
@Test
public void getDefaultComparatorForObjectClass() {
ObjectTableSorter sorter = new
ObjectTableSorter(createTableModel("object", Object.class));
- assertThat(sorter.getValueComparator(0), is(nullValue()));
+ assertNull(sorter.getValueComparator(0));
}
@Test
@@ -229,7 +225,10 @@ public class ObjectTableSorterTest {
public void setSortKeys_single() {
List<SortKey> keys = singletonList(new SortKey(0,
SortOrder.ASCENDING));
sorter.setSortKeys(keys);
- assertThat(sorter.getSortKeys(), allOf(is(not(sameInstance(keys))),
is(equalTo(keys))));
+ assertAll(
+ () -> assertNotSame(keys, sorter.getSortKeys(), "keys vs
sorter.getSortKeys()"),
+ () -> assertEquals(keys, sorter.getSortKeys(), "keys vs
sorter.getSortKeys()")
+ );
}
@Test
diff --git
a/src/jorphan/src/test/java/org/apache/jorphan/util/TestJorphanUtils.java
b/src/jorphan/src/test/java/org/apache/jorphan/util/TestJorphanUtils.java
index 30c271e186..b044302124 100644
--- a/src/jorphan/src/test/java/org/apache/jorphan/util/TestJorphanUtils.java
+++ b/src/jorphan/src/test/java/org/apache/jorphan/util/TestJorphanUtils.java
@@ -17,7 +17,6 @@
package org.apache.jorphan.util;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -26,8 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.charset.StandardCharsets;
-import org.hamcrest.CoreMatchers;
-import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -80,75 +77,83 @@ public class TestJorphanUtils {
public void testSplitStringStringTrueWithTrailingSplitChars() {
// Test ignore trailing split characters
// Ignore adjacent delimiters
- assertThat("Ignore trailing split chars", JOrphanUtils.split("a,bc,,",
",", true),
- CoreMatchers.equalTo(new String[]{"a", "bc"}));
+ assertArrayEquals(
+ new String[]{"a", "bc"},
+ JOrphanUtils.split("a,bc,,", ",", true),
+ "Ignore trailing split chars");
}
@Test
public void testSplitStringStringFalseWithTrailingSplitChars() {
// Test ignore trailing split characters
- assertThat("Include the trailing split chars",
JOrphanUtils.split("a,bc,,", ",", false),
- CoreMatchers.equalTo(new String[]{"a", "bc", "", ""}));
+ assertArrayEquals(
+ new String[]{"a", "bc", "", ""},
+ JOrphanUtils.split("a,bc,,", ",", false),
+ "Include the trailing split chars");
}
@Test
public void testSplitStringStringTrueWithLeadingSplitChars() {
// Test leading split characters
- assertThat("Ignore leading split chars", JOrphanUtils.split(",,a,bc",
",", true),
- CoreMatchers.equalTo(new String[]{"a", "bc"}));
+ assertArrayEquals(
+ new String[]{"a", "bc"},
+ JOrphanUtils.split(",,a,bc", ",", true),
+ "Ignore leading split chars");
}
@Test
public void testSplitStringStringFalseWithLeadingSplitChars() {
// Test leading split characters
- assertThat("Include leading split chars", JOrphanUtils.split(",,a,bc",
",", false),
- CoreMatchers.equalTo(new String[]{"", "", "a", "bc"}));
+ assertArrayEquals(
+ new String[]{"", "", "a", "bc"},
+ JOrphanUtils.split(",,a,bc", ",", false),
+ "Include leading split chars");
}
@Test
public void testSplit3() {
String in = "a,bc,,"; // Test ignore trailing split characters
String[] out = JOrphanUtils.split(in, ",", true);// Ignore adjacent
delimiters
- assertThat(out, CoreMatchers.equalTo(new String[]{"a", "bc"}));
+ assertArrayEquals(new String[]{"a", "bc"}, out);
out = JOrphanUtils.split(in, ",", false);
- assertThat(out, CoreMatchers.equalTo(new String[]{"a", "bc", "", ""}));
+ assertArrayEquals(new String[]{"a", "bc", "", ""}, out);
}
@Test
public void testSplitStringStringTrueWithLeadingComplexSplitCharacters() {
// Test leading split characters
- assertThat(JOrphanUtils.split(" , ,a ,bc", " ,", true),
CoreMatchers.equalTo(new String[]{"a", "bc"}));
+ assertArrayEquals(new String[]{"a", "bc"}, JOrphanUtils.split(" , ,a
,bc", " ,", true));
}
@Test
public void testSplitStringStringFalseWithLeadingComplexSplitCharacters() {
// Test leading split characters
- assertThat(JOrphanUtils.split(" , ,a ,bc", " ,", false),
- CoreMatchers.equalTo(new String[]{"", "", "a", "bc"}));
+ assertArrayEquals(new String[]{"", "", "a", "bc"},
+ JOrphanUtils.split(" , ,a ,bc", " ,", false));
}
@Test
public void testSplitStringStringTrueTruncate() throws Exception {
- assertThat(JOrphanUtils.split("a;,b;,;,;,d;,e;,;,f", ";,", true),
- CoreMatchers.equalTo(new String[]{"a", "b", "d", "e", "f"}));
+ assertArrayEquals(new String[]{"a", "b", "d", "e", "f"},
+ JOrphanUtils.split("a;,b;,;,;,d;,e;,;,f", ";,", true));
}
@Test
public void testSplitStringStringFalseTruncate() throws Exception {
- assertThat(JOrphanUtils.split("a;,b;,;,;,d;,e;,;,f", ";,", false),
- CoreMatchers.equalTo(new String[]{"a", "b", "", "", "d", "e",
"", "f"}));
+ assertArrayEquals(new String[]{"a", "b", "", "", "d", "e", "", "f"},
+ JOrphanUtils.split("a;,b;,;,;,d;,e;,;,f", ";,", false));
}
@Test
public void testSplitStringStringTrueDoubledSplitChar() throws Exception {
- assertThat(JOrphanUtils.split("a;;b;;;;;;d;;e;;;;f", ";;", true),
- CoreMatchers.equalTo(new String[]{"a", "b", "d", "e", "f"}));
+ assertArrayEquals(new String[]{"a", "b", "d", "e", "f"},
+ JOrphanUtils.split("a;;b;;;;;;d;;e;;;;f", ";;", true));
}
@Test
public void testSplitStringStringFalseDoubledSplitChar() throws Exception {
- assertThat(JOrphanUtils.split("a;;b;;;;;;d;;e;;;;f", ";;", false),
- CoreMatchers.equalTo(new String[]{"a", "b", "", "", "d", "e",
"", "f"}));
+ assertArrayEquals(new String[]{"a", "b", "", "", "d", "e", "", "f"},
+ JOrphanUtils.split("a;;b;;;;;;d;;e;;;;f", ";;", false));
}
// Empty string
@@ -162,37 +167,37 @@ public class TestJorphanUtils {
@Test
public void testSplitSSSSingleDelimiterWithDefaultValue() {
// Test non-empty parameters
- assertThat(JOrphanUtils.split("a,bc,,", ",", "?"),
CoreMatchers.equalTo(new String[]{"a", "bc", "?", "?"}));
+ assertArrayEquals(new String[]{"a", "bc", "?", "?"},
JOrphanUtils.split("a,bc,,", ",", "?"));
}
@Test
public void testSplitSSSSingleDelimiterWithEmptyValue() {
// Empty default
- assertThat(JOrphanUtils.split("a,bc,,", ",", ""),
CoreMatchers.equalTo(new String[]{"a", "bc", "", ""}));
+ assertArrayEquals(new String[]{"a", "bc", "", ""},
JOrphanUtils.split("a,bc,,", ",", ""));
}
@Test
public void testSplitSSSEmptyDelimiter() {
String in = "a,bc,,"; // Empty delimiter
- assertThat(JOrphanUtils.split(in, "", "?"), CoreMatchers.equalTo(new
String[]{in}));
+ assertArrayEquals(new String[]{in}, JOrphanUtils.split(in, "", "?"));
}
@Test
public void testSplitSSSMultipleDelimCharsWithDefaultValue() {
// Multiple delimiters
- assertThat(JOrphanUtils.split("a,b;c,,", ",;", "?"),
- CoreMatchers.equalTo(new String[]{"a", "b", "c", "?", "?"}));
+ assertArrayEquals(new String[]{"a", "b", "c", "?", "?"},
+ JOrphanUtils.split("a,b;c,,", ",;", "?"));
}
@Test
public void testSplitSSSMultipleDelimCharsWithEmptyValue() {
// Multiple delimiters
- assertThat(JOrphanUtils.split("a,b;c,,", ",;", ""),
CoreMatchers.equalTo(new String[]{"a", "b", "c", "", ""}));
+ assertArrayEquals(new String[]{"a", "b", "c", "", ""},
JOrphanUtils.split("a,b;c,,", ",;", ""));
}
@Test
public void testSplitSSSSameDelimiterAsDefaultValue() {
- assertThat(JOrphanUtils.split("a,bc,,", ",", ","),
CoreMatchers.equalTo(new String[]{"a", "bc", ",", ","}));
+ assertArrayEquals(new String[]{"a", "bc", ",", ","},
JOrphanUtils.split("a,bc,,", ",", ","));
}
@Test
@@ -211,12 +216,12 @@ public class TestJorphanUtils {
@Test
public void testSplitStringStringNullWithSingleDelimiter() {
- assertThat(JOrphanUtils.split("a,bc,,", ",", null),
CoreMatchers.equalTo(new String[]{"a", "bc"}));
+ assertArrayEquals(new String[]{"a", "bc"},
JOrphanUtils.split("a,bc,,", ",", null));
}
@Test
public void testSplitStringStringNullWithMultipleDelimiter() {
- assertThat(JOrphanUtils.split("a,;bc,;,", ",;", null),
CoreMatchers.equalTo(new String[]{"a", "bc"}));
+ assertArrayEquals(new String[]{"a", "bc"},
JOrphanUtils.split("a,;bc,;,", ",;", null));
}
@Test
@@ -228,7 +233,7 @@ public class TestJorphanUtils {
@Test
public void testSplitSSSWithEmptyDelimiter() {
final String in = "a,;bc,;,";
- assertThat(JOrphanUtils.split(in, "", "x"), CoreMatchers.equalTo(new
String[]{in}));
+ assertArrayEquals(new String[]{in}, JOrphanUtils.split(in, "", "x"));
}
@Test
@@ -274,17 +279,9 @@ public class TestJorphanUtils {
@Test
public void testbaToByte() throws Exception {
- assertEqualsArray(new byte[]{}, JOrphanUtils.baToHexBytes(new
byte[]{}));
- assertEqualsArray(new byte[]{'0', '0'}, JOrphanUtils.baToHexBytes(new
byte[]{0}));
- assertEqualsArray("0f107f8081ff".getBytes(StandardCharsets.UTF_8),
- JOrphanUtils.baToHexBytes(new byte[]{15, 16, 127, -128, -127,
-1}));
- }
-
- private void assertEqualsArray(byte[] expected, byte[] actual) {
- assertEquals(expected.length, actual.length, "arrays must be same
length");
- for (int i = 0; i < expected.length; i++) {
- assertEquals(expected[i], actual[i], "values must be the same for
index: " + i);
- }
+ assertArrayEquals(new byte[]{}, JOrphanUtils.baToHexBytes(new
byte[]{}));
+ assertArrayEquals(new byte[]{'0', '0'}, JOrphanUtils.baToHexBytes(new
byte[]{0}));
+ assertArrayEquals("0f107f8081ff".getBytes(StandardCharsets.UTF_8),
JOrphanUtils.baToHexBytes(new byte[]{15, 16, 127, -128, -127, -1}));
}
@Test
@@ -373,16 +370,14 @@ public class TestJorphanUtils {
@Test
public void testReplaceValueWithNullValue() {
- assertThat(JOrphanUtils.replaceValue(null, null, false, null, null),
- CoreMatchers.is(0));
+ assertEquals(0, JOrphanUtils.replaceValue(null, null, false, null,
null));
}
@Test
public void testReplaceValueWithValidValueAndValidSetter() {
Holder h = new Holder();
- assertThat(JOrphanUtils.replaceValue("\\d+", "${port}", true, "80", s
-> h.value = s),
- CoreMatchers.is(1));
- assertThat(h.value, CoreMatchers.is("${port}"));
+ assertEquals(1, JOrphanUtils.replaceValue("\\d+", "${port}", true,
"80", s -> h.value = s));
+ assertEquals("${port}", h.value);
}
private static class Holder {
@@ -405,6 +400,9 @@ public class TestJorphanUtils {
@Test
public void testGenerateRandomAlphanumericPassword20() {
- assertThat(JOrphanUtils.generateRandomAlphanumericPassword(20),
Matchers.matchesPattern("[A-Za-z0-9]{20}"));
+ String password = JOrphanUtils.generateRandomAlphanumericPassword(20);
+ assertTrue(
+ password.matches("[A-Za-z0-9]{20}"),
+ () -> "generateRandomAlphanumericPassword(20) should match
pattern \"[A-Za-z0-9]{20}\", got " + password);
}
}
diff --git a/src/licenses/licenses/hamcrest-date/LICENSE
b/src/licenses/licenses/hamcrest-date/LICENSE
deleted file mode 100644
index 72934585dd..0000000000
--- a/src/licenses/licenses/hamcrest-date/LICENSE
+++ /dev/null
@@ -1,24 +0,0 @@
-Copyright (c) 2012, Stewart Bissett
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the author nor the names of its contributors may
- be used to endorse or promote products derived from this software
- without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthorization.java
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthorization.java
index 7d9a39689b..ab49f77302 100644
---
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthorization.java
+++
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthorization.java
@@ -17,10 +17,9 @@
package org.apache.jmeter.protocol.http.control;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.jmeter.protocol.http.control.AuthManager.Mechanism;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
public class TestAuthorization {
@@ -29,7 +28,7 @@ public class TestAuthorization {
public void testToBasicHeader() {
Authorization basicAuthorization = new
Authorization("http://example.com", "foo", "bar", null, "Test Realm",
Mechanism.BASIC);
- assertThat(basicAuthorization.toBasicHeader(), CoreMatchers.is("Basic
Zm9vOmJhcg=="));
+ assertEquals("Basic Zm9vOmJhcg==", basicAuthorization.toBasicHeader());
}
}
diff --git
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestBug60842HtmlParser.java
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestBug60842HtmlParser.java
index 9eb008d2e1..5e75d2fdff 100644
---
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestBug60842HtmlParser.java
+++
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestBug60842HtmlParser.java
@@ -17,7 +17,7 @@
package org.apache.jmeter.protocol.http.parser;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.net.URL;
import java.nio.charset.StandardCharsets;
@@ -29,7 +29,6 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -114,10 +113,11 @@ class TestBug60842HtmlParser {
StandardCharsets.UTF_8.name());
List<String> urlNames = c.stream().map(u -> u.toString())
.collect(Collectors.toList());
- assertThat(
+ assertEquals(
+ links.toString(),
+ urlNames.toString(),
String.format("Parse with %s the page %s to get %s",
- parser.getClass().getSimpleName(), html, links),
- urlNames, CoreMatchers.is(CoreMatchers.equalTo(links)));
+ parser.getClass().getSimpleName(), html, links));
}
}
diff --git
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestCssParser.java
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestCssParser.java
index 0482d58261..c85bd547dc 100644
---
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestCssParser.java
+++
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/parser/TestCssParser.java
@@ -17,10 +17,8 @@
package org.apache.jmeter.protocol.http.parser;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.collection.IsEmptyCollection.empty;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.net.MalformedURLException;
import java.net.URL;
@@ -30,7 +28,6 @@ import java.util.Iterator;
import java.util.List;
import org.apache.jmeter.junit.JMeterTestCase;
-import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
public class TestCssParser extends JMeterTestCase {
@@ -48,24 +45,24 @@ public class TestCssParser extends JMeterTestCase {
public void testGetEmbeddedResourceURLsNoUrls() throws Exception {
CssParser nonIgnoreParser = new CssParser();
List<URL> result = extractUrls(nonIgnoreParser, "..");
- assertThat(result, is(empty()));
+ assertEquals("[]", result.toString());
}
@Test
public void testGetEmbeddedResourceURLsnOneUrl() throws Exception {
List<URL> result = extractUrls("@import
url(http://example.com/abc.css);");
- assertThat(result, is(not(empty())));
+ assertEquals("[http://example.com/abc.css]", result.toString());
}
@Test
public void testExtractUrlsFromBrokenData() throws Exception {
List<URL> result = extractUrls(CSS_IN_ERROR);
- assertThat(result, is(empty()));
+ assertEquals("[]", result.toString());
}
@Test
public void testIsReusable() {
- assertThat(parser.isReusable(), CoreMatchers.is(true));
+ assertTrue(parser.isReusable());
}
private List<URL> extractUrls(String css) throws
LinkExtractorParseException,
diff --git
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestDecompression.java
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestDecompression.java
index 24938c2ed9..40b972ec55 100644
---
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestDecompression.java
+++
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestDecompression.java
@@ -17,6 +17,10 @@
package org.apache.jmeter.protocol.http.sampler;
+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.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -26,9 +30,6 @@ import java.util.function.Consumer;
import org.apache.jmeter.protocol.http.control.Header;
import org.apache.jmeter.protocol.http.control.HeaderManager;
-import org.hamcrest.Matcher;
-import org.hamcrest.MatcherAssert;
-import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -39,6 +40,8 @@ import com.github.tomakehurst.wiremock.client.MappingBuilder;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+import kotlin.text.StringsKt;
+
public class TestDecompression {
enum ClientGzip {
REQUESTED, NOT_REQUESTED
@@ -91,16 +94,19 @@ public class TestDecompression {
HTTPSampleResult res = http.sample(new URL(server.url("/gzip")),
"GET", false, 1);
Assertions.assertAll(
+ () -> assertEquals(expectedResponse,
res.getResponseDataAsString(), "response body"),
() -> {
- Matcher<String> matcher;
if (clientGzip == ClientGzip.NOT_REQUESTED ||
serverGzip == ServerGzip.NOT_SUPPORTED) {
- matcher =
Matchers.not(Matchers.containsStringIgnoringCase("Content-Encoding:"));
+ assertFalse(
+
StringsKt.contains(res.getResponseHeaders(), "Content-Encoding:", false),
+ () -> "clientGzip is " + clientGzip + ",
so Content-Encoding header should NOT be present"
+ );
} else {
- matcher =
Matchers.containsStringIgnoringCase("Content-Encoding: gzip");
+ assertTrue(
+
StringsKt.contains(res.getResponseHeaders(), "Content-Encoding: gzip", false),
+ () -> "clientGzip is " + clientGzip + ",
so Content-Encoding: gzip header should be present"
+ );
}
- MatcherAssert.assertThat("getResponseHeaders",
res.getResponseHeaders(), matcher);
- }, () -> {
- Assertions.assertEquals(expectedResponse,
res.getResponseDataAsString(), "response body");
}
);
} finally {
diff --git
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestRedirects.java
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestRedirects.java
index 849ab03818..42e63d359b 100644
---
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestRedirects.java
+++
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestRedirects.java
@@ -72,7 +72,7 @@ class TestRedirects {
if (shouldRedirect) {
Assertions.assertEquals(server.url("/redirected"),
res.getRedirectLocation());
} else {
- Assertions.assertEquals(null, res.getRedirectLocation());
+ Assertions.assertNull(res.getRedirectLocation());
}
Assertions.assertEquals("" + redirectCode, res.getResponseCode());
} finally {
diff --git
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestSerializedHTTPSampler.java
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestSerializedHTTPSampler.java
index 512a4fe52e..becffb7666 100644
---
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestSerializedHTTPSampler.java
+++
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestSerializedHTTPSampler.java
@@ -17,9 +17,7 @@
package org.apache.jmeter.protocol.http.sampler;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import java.io.File;
@@ -45,7 +43,8 @@ public class TestSerializedHTTPSampler extends JMeterTestCase
implements JMeterS
sampler.setHTTPFiles(new HTTPFileArg[]{new
HTTPFileArg(file.getName(), "", "")});
SampleResult sample = sampler.sample();
- assertThat(sample.getResponseDataAsString(),
not(containsString("java.io.FileNotFoundException:")));
+
assertFalse(sample.getResponseDataAsString().contains("java.io.FileNotFoundException:"),
+ () -> sample.getResponseDataAsString() + " should not
contain java.io.FileNotFoundException:");
} finally {
FileServer.getFileServer().setBase(baseDir);
}
diff --git
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java
index 88003b84b7..6688898f76 100644
---
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java
+++
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java
@@ -17,6 +17,8 @@
package org.apache.jmeter.protocol.http.visualizers;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.HashMap;
@@ -25,8 +27,6 @@ import java.util.Map;
import java.util.stream.Stream;
import org.apache.jorphan.util.StringUtilities;
-import org.hamcrest.MatcherAssert;
-import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@@ -233,9 +233,11 @@ class RequestViewHTTPTest {
Map<String, String[]> params = RequestViewHTTP.getQueryMap(query);
Assertions.assertNotNull(params);
Assertions.assertEquals(expected.size(), params.size());
- expected.forEach((key, values) -> {
- MatcherAssert.assertThat(params, Matchers.hasKey(key));
- Assertions.assertArrayEquals(values.toArray(), params.get(key));
- });
+ expected.forEach((key, values) ->
+ assertEquals(
+ values.toString(),
+ Arrays.asList(params.get(key)).toString(),
+ "RequestViewHTTP.getQueryMap(..).get(" + key + ")"
+ ));
}
}
diff --git
a/src/protocol/jms/src/test/java/org/apache/jmeter/protocol/jms/sampler/render/BinaryMessageRendererTest.java
b/src/protocol/jms/src/test/java/org/apache/jmeter/protocol/jms/sampler/render/BinaryMessageRendererTest.java
index 9feba1ac6a..bba2c621fb 100644
---
a/src/protocol/jms/src/test/java/org/apache/jmeter/protocol/jms/sampler/render/BinaryMessageRendererTest.java
+++
b/src/protocol/jms/src/test/java/org/apache/jmeter/protocol/jms/sampler/render/BinaryMessageRendererTest.java
@@ -17,87 +17,23 @@
package org.apache.jmeter.protocol.jms.sampler.render;
-import static org.hamcrest.CoreMatchers.allOf;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import org.apache.jmeter.threads.JMeterVariables;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.hamcrest.MatcherAssert;
-import org.hamcrest.TypeSafeMatcher;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
public class BinaryMessageRendererTest extends MessageRendererTest<byte[]> {
- public static class ThrowableMessageMatcher<T extends Throwable> extends
- TypeSafeMatcher<T> {
-
- private final Matcher<String> matcher;
-
- public ThrowableMessageMatcher(Matcher<String> matcher) {
- this.matcher = matcher;
- }
-
- public void describeTo(Description description) {
- description.appendText("exception with message ");
- description.appendDescriptionOf(matcher);
- }
-
- @Override
- protected boolean matchesSafely(T item) {
- return matcher.matches(item.getMessage());
- }
-
- @Override
- protected void describeMismatchSafely(T item, Description description)
{
- description.appendText("message ");
- matcher.describeMismatch(item.getMessage(), description);
- }
- }
-
- public static class ThrowableCauseMatcher<T extends Throwable> extends
- TypeSafeMatcher<T> {
-
- private final Matcher<?> causeMatcher;
-
- public ThrowableCauseMatcher(Matcher<?> causeMatcher) {
- this.causeMatcher = causeMatcher;
- }
-
- public void describeTo(Description description) {
- description.appendText("exception with cause ");
- description.appendDescriptionOf(causeMatcher);
- }
-
- @Override
- protected boolean matchesSafely(T item) {
- return causeMatcher.matches(item.getCause());
- }
-
- @Override
- protected void describeMismatchSafely(T item, Description description)
{
- description.appendText("cause ");
- causeMatcher.describeMismatch(item.getCause(), description);
- }
- }
-
- public static <T extends Throwable> Matcher<T> hasMessage(final
Matcher<String> matcher) {
- return new ThrowableMessageMatcher<T>(matcher);
- }
-
- public static <T extends Throwable> Matcher<T> hasCause(final Matcher<?>
matcher) {
- return new ThrowableCauseMatcher<T>(matcher);
- }
-
private BinaryMessageRenderer render =
RendererFactory.getInstance().getBinary();
@Override
@@ -129,11 +65,14 @@ public class BinaryMessageRendererTest extends
MessageRendererTest<byte[]> {
RuntimeException.class,
() ->
render.getContent("__file_that_may_not_exists_else_it_will_fail")
);
-
- MatcherAssert.assertThat(ex, allOf(
- hasMessage(containsString("Can't read content of
__file_that_may_not_exists_else_it_will_fail")),
- hasCause(instanceOf(IOException.class))
- ));
+ assertAll(
+ () -> assertInstanceOf(IOException.class, ex.getCause(),
"ex.getCause()"),
+ () -> assertContains(
+ ex.getMessage(),
+ "Can't read content of
__file_that_may_not_exists_else_it_will_fail",
+ "ex.getCause().getMessage()"
+ )
+ );
}
@Test
@@ -159,11 +98,12 @@ public class BinaryMessageRendererTest extends
MessageRendererTest<byte[]> {
RuntimeException.class,
() -> render.getValueFromFile("utf8.txt", "banana", true,
cache)
);
- MatcherAssert.assertThat(
- ex,
- allOf(
- hasMessage(containsString("utf8.txt")),
-
hasCause(instanceOf(UnsupportedEncodingException.class))
+ assertAll(
+ () -> assertInstanceOf(UnsupportedEncodingException.class,
ex.getCause(), "ex.getCause()"),
+ () -> assertContains(
+ ex.getMessage(),
+ "utf8.txt",
+ "ex.getCause().getMessage()"
)
);
}
@@ -176,6 +116,10 @@ public class BinaryMessageRendererTest extends
MessageRendererTest<byte[]> {
assertCacheContentInBytes(text);
}
+ private void assertContains(String value, String substring, String
message) {
+ assertTrue(value.contains(substring), () -> message + ": " + value + "
should contain " + substring);
+ }
+
protected void assertValueFromFile(String expected, String fileName,
boolean hasVariable) {
assertValueFromFile(actual -> assertBytesEquals(expected, actual),
fileName, hasVariable);
}
diff --git a/src/protocol/junit/build.gradle.kts
b/src/protocol/junit/build.gradle.kts
index f2612645b7..c9fe345b1e 100644
--- a/src/protocol/junit/build.gradle.kts
+++ b/src/protocol/junit/build.gradle.kts
@@ -23,9 +23,6 @@ dependencies {
api(projects.src.core)
api("junit:junit")
- implementation("org.exparity:hamcrest-date") {
- because("hamcrest-date.jar was historically shipped with JMeter")
- }
implementation("com.miglayout:miglayout-swing")
testImplementation(testFixtures(projects.src.core))