This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push: new e01ac3b38 Use simpler and better JUnit APIs e01ac3b38 is described below commit e01ac3b3863d59bcd6b699999204499a9f16e3ae Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Sat Jan 18 11:16:53 2025 -0500 Use simpler and better JUnit APIs No need for absurdly obtuse and verbose hamcrest --- pom.xml | 6 -- .../commons/lang3/RandomStringUtilsTest.java | 62 ++++++++++--------- .../org/apache/commons/lang3/RandomUtilsTest.java | 70 +++++++++++++--------- .../java/org/apache/commons/lang3/StreamsTest.java | 26 +++----- .../lang3/StringUtilsEqualsIndexOfTest.java | 7 +-- .../org/apache/commons/lang3/StringUtilsTest.java | 6 +- .../org/apache/commons/lang3/ThreadUtilsTest.java | 8 +-- .../commons/lang3/builder/DiffBuilderTest.java | 18 ++---- ...onToStringBuilderExcludeWithAnnotationTest.java | 14 ++--- ...oncurrentInitializerCloseAndExceptionsTest.java | 7 +-- .../BackgroundInitializerSupplierTest.java | 5 +- .../MultiBackgroundInitializerSupplierTest.java | 7 +-- .../commons/lang3/reflect/MethodUtilsTest.java | 13 ++-- .../apache/commons/lang3/stream/StreamsTest.java | 20 +++---- .../apache/commons/lang3/time/StopWatchTest.java | 24 ++++---- 15 files changed, 134 insertions(+), 159 deletions(-) diff --git a/pom.xml b/pom.xml index dc275aa43..f475e1fe2 100644 --- a/pom.xml +++ b/pom.xml @@ -68,12 +68,6 @@ <artifactId>junit-pioneer</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest</artifactId> - <version>3.0</version> - <scope>test</scope> - </dependency> <dependency> <groupId>org.easymock</groupId> <artifactId>easymock</artifactId> diff --git a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java index 124696b99..4616c6605 100644 --- a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java @@ -16,12 +16,6 @@ */ package org.apache.commons.lang3; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThan; -import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -216,7 +210,7 @@ public class RandomStringUtilsTest extends AbstractLangTest { // Perform chi-square test with degrees of freedom = 3-1 = 2, testing at 1e-5 level. // This expects a failure rate of 1 in 100,000. // critical value: from scipy.stats import chi2; chi2(2).isf(1e-5) - assertThat("test homogeneity -- will fail about 1 in 100,000 times", chiSquare(expected, counts), lessThan(23.025850929940457d)); + assertTrue(chiSquare(expected, counts) < 23.025850929940457d, "test homogeneity -- will fail about 1 in 100,000 times"); } /** @@ -411,7 +405,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < LOOP_COUNT; i++) { final String s = RandomStringUtils.randomAlphabetic(expectedMinLengthInclusive, expectedMaxLengthExclusive); - assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); + assertTrue(s.length() >= expectedMinLengthInclusive, "within range"); + assertTrue(s.length() <= expectedMaxLengthExclusive - 1, "within range"); assertTrue(s.matches(pattern), s); if (s.length() < minCreatedLength) { @@ -422,8 +417,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { maxCreatedLength = s.length(); } } - assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); - assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); + assertEquals(expectedMinLengthInclusive, minCreatedLength, "min generated, may fail randomly rarely"); + assertEquals(expectedMaxLengthExclusive - 1, maxCreatedLength, "max generated, may fail randomly rarely"); } @ParameterizedTest @@ -437,7 +432,9 @@ public class RandomStringUtilsTest extends AbstractLangTest { int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < LOOP_COUNT; i++) { final String s = rsu.nextAlphabetic(expectedMinLengthInclusive, expectedMaxLengthExclusive); - assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); + assertTrue(s.length() >= expectedMinLengthInclusive, "within range"); + assertTrue(s.length() <= expectedMaxLengthExclusive - 1, "within range"); + assertTrue(s.matches(pattern), s); if (s.length() < minCreatedLength) { @@ -448,8 +445,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { maxCreatedLength = s.length(); } } - assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); - assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); + assertEquals(expectedMinLengthInclusive, minCreatedLength, "min generated, may fail randomly rarely"); + assertEquals(expectedMaxLengthExclusive - 1, maxCreatedLength, "max generated, may fail randomly rarely"); } /** @@ -505,7 +502,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < LOOP_COUNT; i++) { final String s = RandomStringUtils.randomAlphanumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive); - assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); + assertTrue(s.length() >= expectedMinLengthInclusive, "within range"); + assertTrue(s.length() <= expectedMaxLengthExclusive - 1, "within range"); assertTrue(s.matches(pattern), s); if (s.length() < minCreatedLength) { @@ -516,8 +514,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { maxCreatedLength = s.length(); } } - assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); - assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); + assertEquals(expectedMinLengthInclusive, minCreatedLength, "min generated, may fail randomly rarely"); + assertEquals(expectedMaxLengthExclusive - 1, maxCreatedLength, "max generated, may fail randomly rarely"); } /** @@ -537,7 +535,9 @@ public class RandomStringUtilsTest extends AbstractLangTest { r1 = rsu.nextAscii(50); assertEquals(50, r1.length(), "randomAscii(50) length"); for (int i = 0; i < r1.length(); i++) { - assertThat("char >= 32 && <= 127", (int) r1.charAt(i), allOf(greaterThanOrEqualTo(32), lessThanOrEqualTo(127))); + final int ch = (int) r1.charAt(i); + assertTrue(ch >= 32, "char >= 32"); + assertTrue(ch <= 127, "char <= 127"); } r2 = rsu.nextAscii(50); assertNotEquals(r1, r2, "!r1.equals(r2)"); @@ -651,7 +651,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < LOOP_COUNT; i++) { final String s = rsu.nextAscii(expectedMinLengthInclusive, expectedMaxLengthExclusive); - assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); + assertTrue(s.length() >= expectedMinLengthInclusive, "within range"); + assertTrue(s.length() <= expectedMaxLengthExclusive - 1, "within range"); assertTrue(s.matches(pattern), s); if (s.length() < minCreatedLength) { @@ -662,8 +663,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { maxCreatedLength = s.length(); } } - assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); - assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); + assertEquals(expectedMinLengthInclusive, minCreatedLength, "min generated, may fail randomly rarely"); + assertEquals(expectedMaxLengthExclusive - 1, maxCreatedLength, "max generated, may fail randomly rarely"); } @ParameterizedTest @@ -677,7 +678,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < LOOP_COUNT; i++) { final String s = rsu.nextGraph(expectedMinLengthInclusive, expectedMaxLengthExclusive); - assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); + assertTrue(s.length() >= expectedMinLengthInclusive, "within range"); + assertTrue(s.length() <= expectedMaxLengthExclusive - 1, "within range"); assertTrue(s.matches(pattern), s); if (s.length() < minCreatedLength) { @@ -688,8 +690,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { maxCreatedLength = s.length(); } } - assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); - assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); + assertEquals(expectedMinLengthInclusive, minCreatedLength, "min generated, may fail randomly rarely"); + assertEquals(expectedMaxLengthExclusive - 1, maxCreatedLength, "max generated, may fail randomly rarely"); } /** @@ -726,7 +728,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < LOOP_COUNT; i++) { final String s = rsu.nextNumeric(expectedMinLengthInclusive, expectedMaxLengthExclusive); - assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); + assertTrue(s.length() >= expectedMinLengthInclusive, "within range"); + assertTrue(s.length() <= expectedMaxLengthExclusive - 1, "within range"); assertTrue(s.matches(pattern), s); if (s.length() < minCreatedLength) { @@ -737,8 +740,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { maxCreatedLength = s.length(); } } - assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); - assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); + assertEquals(expectedMinLengthInclusive, minCreatedLength, "min generated, may fail randomly rarely"); + assertEquals(expectedMaxLengthExclusive - 1, maxCreatedLength, "max generated, may fail randomly rarely"); } @Test @@ -760,7 +763,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < LOOP_COUNT; i++) { final String s = rsu.nextPrint(expectedMinLengthInclusive, expectedMaxLengthExclusive); - assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); + assertTrue(s.length() >= expectedMinLengthInclusive, "within range"); + assertTrue(s.length() <= expectedMaxLengthExclusive - 1, "within range"); assertTrue(s.matches(pattern), s); if (s.length() < minCreatedLength) { @@ -771,8 +775,8 @@ public class RandomStringUtilsTest extends AbstractLangTest { maxCreatedLength = s.length(); } } - assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); - assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); + assertEquals(expectedMinLengthInclusive, minCreatedLength, "min generated, may fail randomly rarely"); + assertEquals(expectedMaxLengthExclusive - 1, maxCreatedLength, "max generated, may fail randomly rarely"); } /** diff --git a/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java b/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java index bbeafa173..06cc79c05 100644 --- a/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RandomUtilsTest.java @@ -16,10 +16,6 @@ */ package org.apache.commons.lang3; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.lessThan; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -109,7 +105,8 @@ public class RandomUtilsTest extends AbstractLangTest { @Test public void testExtremeRangeInt() { final int result = RandomUtils.nextInt(0, Integer.MAX_VALUE); - assertThat("result >= 0 && result < Integer.MAX_VALUE", result, allOf(greaterThanOrEqualTo(0), lessThan(Integer.MAX_VALUE))); + assertTrue(result >= 0); + assertTrue(result < Integer.MAX_VALUE); } /** @@ -119,7 +116,8 @@ public class RandomUtilsTest extends AbstractLangTest { @MethodSource("randomProvider") public void testExtremeRangeInt(final RandomUtils ru) { final int result = ru.randomInt(0, Integer.MAX_VALUE); - assertThat("result >= 0 && result < Integer.MAX_VALUE", result, allOf(greaterThanOrEqualTo(0), lessThan(Integer.MAX_VALUE))); + assertTrue(result >= 0); + assertTrue(result < Integer.MAX_VALUE); } /** @@ -128,7 +126,8 @@ public class RandomUtilsTest extends AbstractLangTest { @Test public void testExtremeRangeLong() { final long result = RandomUtils.nextLong(0, Long.MAX_VALUE); - assertThat("result >= 0 && result < Long.MAX_VALUE", result, allOf(greaterThanOrEqualTo(0L), lessThan(Long.MAX_VALUE))); + assertTrue(result >= 0); + assertTrue(result < Long.MAX_VALUE); } /** @@ -138,7 +137,8 @@ public class RandomUtilsTest extends AbstractLangTest { @MethodSource("randomProvider") public void testExtremeRangeLong(final RandomUtils ru) { final long result = ru.randomLong(0, Long.MAX_VALUE); - assertThat("result >= 0 && result < Long.MAX_VALUE", result, allOf(greaterThanOrEqualTo(0L), lessThan(Long.MAX_VALUE))); + assertTrue(result >= 0); + assertTrue(result < Long.MAX_VALUE); } /** @@ -226,7 +226,8 @@ public class RandomUtilsTest extends AbstractLangTest { @Test public void testNextDouble() { final double result = RandomUtils.nextDouble(33d, 42d); - assertThat("result >= 33d && result < 42d", result, allOf(greaterThanOrEqualTo(33d), lessThan(42d))); + assertTrue(result >= 33d); + assertTrue(result < 42d); } /** @@ -236,7 +237,8 @@ public class RandomUtilsTest extends AbstractLangTest { @MethodSource("randomProvider") public void testNextDouble(final RandomUtils ru) { final double result = ru.randomDouble(33d, 42d); - assertThat("result >= 33d && result < 42d", result, allOf(greaterThanOrEqualTo(33d), lessThan(42d))); + assertTrue(result >= 33d); + assertTrue(result < 42d); } @Test @@ -283,8 +285,9 @@ public class RandomUtilsTest extends AbstractLangTest { */ @Test public void testNextDoubleRandomResult() { - final double randomResult = RandomUtils.nextDouble(); - assertThat("randomResult >= 0 0 && randomResult < Double.MAX_VALUE", randomResult, allOf(greaterThanOrEqualTo(0d), lessThan(Double.MAX_VALUE))); + final double result = RandomUtils.nextDouble(); + assertTrue(result >= 0d); + assertTrue(result < Double.MAX_VALUE); } /** @@ -293,8 +296,9 @@ public class RandomUtilsTest extends AbstractLangTest { @ParameterizedTest @MethodSource("randomProvider") public void testNextDoubleRandomResult(final RandomUtils ru) { - final double randomResult = ru.randomDouble(); - assertThat("randomResult >= 0 0 && randomResult < Double.MAX_VALUE", randomResult, allOf(greaterThanOrEqualTo(0d), lessThan(Double.MAX_VALUE))); + final double result = ru.randomDouble(); + assertTrue(result >= 0d); + assertTrue(result < Double.MAX_VALUE); } /** @@ -303,7 +307,8 @@ public class RandomUtilsTest extends AbstractLangTest { @Test public void testNextFloat() { final float result = RandomUtils.nextFloat(33f, 42f); - assertThat("result >= 33f && result < 42f", result, allOf(greaterThanOrEqualTo(33f), lessThan(42f))); + assertTrue(result >= 33f); + assertTrue(result < 42f); } /** @@ -313,7 +318,8 @@ public class RandomUtilsTest extends AbstractLangTest { @MethodSource("randomProvider") public void testNextFloat(final RandomUtils ru) { final float result = ru.randomFloat(33f, 42f); - assertThat("result >= 33f && result < 42f", result, allOf(greaterThanOrEqualTo(33f), lessThan(42f))); + assertTrue(result >= 33f); + assertTrue(result < 42f); } @Test @@ -360,8 +366,9 @@ public class RandomUtilsTest extends AbstractLangTest { */ @Test public void testNextFloatRandomResult() { - final float randomResult = RandomUtils.nextFloat(); - assertThat("randomResult >= 0 && randomResult < Double.MAX_VALUE", randomResult, allOf(greaterThanOrEqualTo(0f), lessThan(Float.MAX_VALUE))); + final float result = RandomUtils.nextFloat(); + assertTrue(result >= 0f); + assertTrue(result < Float.MAX_VALUE); } /** @@ -370,8 +377,9 @@ public class RandomUtilsTest extends AbstractLangTest { @ParameterizedTest @MethodSource("randomProvider") public void testNextFloatRandomResult(final RandomUtils ru) { - final float randomResult = ru.randomFloat(); - assertThat("randomResult >= 0 && randomResult < Double.MAX_VALUE", randomResult, allOf(greaterThanOrEqualTo(0f), lessThan(Float.MAX_VALUE))); + final float result = ru.randomFloat(); + assertTrue(result >= 0f); + assertTrue(result < Float.MAX_VALUE); } /** @@ -380,7 +388,8 @@ public class RandomUtilsTest extends AbstractLangTest { @Test public void testNextInt() { final int result = RandomUtils.nextInt(33, 42); - assertThat("result >= 33 && result < 42", result, allOf(greaterThanOrEqualTo(33), lessThan(42))); + assertTrue(result >= 33); + assertTrue(result < 42); } /** @@ -390,7 +399,8 @@ public class RandomUtilsTest extends AbstractLangTest { @MethodSource("randomProvider") public void testNextInt(final RandomUtils ru) { final int result = ru.randomInt(33, 42); - assertThat("result >= 33 && result < 42", result, allOf(greaterThanOrEqualTo(33), lessThan(42))); + assertTrue(result >= 33); + assertTrue(result < 42); } @Test @@ -459,7 +469,8 @@ public class RandomUtilsTest extends AbstractLangTest { @Test public void testNextLong() { final long result = RandomUtils.nextLong(33L, 42L); - assertThat("result >= 33L && result < 42L", result, allOf(greaterThanOrEqualTo(33L), lessThan(42L))); + assertTrue(result >= 33L); + assertTrue(result < 42L); } /** @@ -469,7 +480,8 @@ public class RandomUtilsTest extends AbstractLangTest { @MethodSource("randomProvider") public void testNextLong(final RandomUtils ru) { final long result = ru.randomLong(33L, 42L); - assertThat("result >= 33L && result < 42L", result, allOf(greaterThanOrEqualTo(33L), lessThan(42L))); + assertTrue(result >= 33L); + assertTrue(result < 42L); } @Test @@ -516,8 +528,9 @@ public class RandomUtilsTest extends AbstractLangTest { */ @Test public void testNextLongRandomResult() { - final long randomResult = RandomUtils.nextLong(); - assertThat("randomResult >= 0 && randomResult < Long.MAX_VALUE", randomResult, allOf(greaterThanOrEqualTo(0L), lessThan(Long.MAX_VALUE))); + final long result = RandomUtils.nextLong(); + assertTrue(result >= 0L); + assertTrue(result < Long.MAX_VALUE); } /** @@ -526,8 +539,9 @@ public class RandomUtilsTest extends AbstractLangTest { @ParameterizedTest @MethodSource("randomProvider") public void testNextLongRandomResult(final RandomUtils ru) { - final long randomResult = ru.randomLong(); - assertThat("randomResult >= 0 && randomResult < Long.MAX_VALUE", randomResult, allOf(greaterThanOrEqualTo(0L), lessThan(Long.MAX_VALUE))); + final long result = ru.randomLong(); + assertTrue(result >= 0L); + assertTrue(result < Long.MAX_VALUE); } /** diff --git a/src/test/java/org/apache/commons/lang3/StreamsTest.java b/src/test/java/org/apache/commons/lang3/StreamsTest.java index ee9a133da..0896fd9b8 100644 --- a/src/test/java/org/apache/commons/lang3/StreamsTest.java +++ b/src/test/java/org/apache/commons/lang3/StreamsTest.java @@ -16,13 +16,9 @@ */ package org.apache.commons.lang3; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.hamcrest.core.IsNull.nullValue; -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.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.DynamicTest.dynamicTest; @@ -90,7 +86,7 @@ public class StreamsTest extends AbstractLangTest { .filter(asIntPredicate(iae)) .collect(Collectors.toList()); final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, testMethod); - assertThat(thrown.getMessage(), is(equalTo("Invalid argument: " + 5))); + assertEquals("Invalid argument: " + 5, thrown.getMessage()); }), dynamicTest("OutOfMemoryError", () -> { final OutOfMemoryError oome = new OutOfMemoryError(); @@ -99,7 +95,7 @@ public class StreamsTest extends AbstractLangTest { .filter(asIntPredicate(oome)) .collect(Collectors.toList()); final OutOfMemoryError thrown = assertThrows(OutOfMemoryError.class, testMethod); - assertThat(thrown.getMessage(), is(nullValue())); + assertNull(thrown.getMessage()); }), dynamicTest("SAXException", () -> { final SAXException se = new SAXException(); @@ -108,10 +104,8 @@ public class StreamsTest extends AbstractLangTest { .filter(asIntPredicate(se)) .collect(Collectors.toList()); final UndeclaredThrowableException thrown = assertThrows(UndeclaredThrowableException.class, testMethod); - assertAll( - () -> assertThat(thrown.getMessage(), is(nullValue())), - () -> assertThat(thrown.getCause(), is(equalTo(se))) - ); + assertNull(thrown.getMessage()); + assertEquals(se, thrown.getCause()); }) ); } @@ -124,22 +118,20 @@ public class StreamsTest extends AbstractLangTest { final IllegalArgumentException ise = new IllegalArgumentException(); final Executable testMethod = () -> Functions.stream(input).forEach(asIntConsumer(ise)); final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, testMethod); - assertThat(thrown.getMessage(), is(nullValue())); + assertNull(thrown.getMessage()); }), dynamicTest("OutOfMemoryError", () -> { final OutOfMemoryError oome = new OutOfMemoryError(); final Executable oomeTestMethod = () -> Functions.stream(input).forEach(asIntConsumer(oome)); final OutOfMemoryError oomeThrown = assertThrows(OutOfMemoryError.class, oomeTestMethod); - assertThat(oomeThrown.getMessage(), is(nullValue())); + assertNull(oomeThrown.getMessage()); }), dynamicTest("SAXException", () -> { final SAXException se = new SAXException(); final Executable seTestMethod = () -> Functions.stream(input).forEach(asIntConsumer(se)); final UndeclaredThrowableException seThrown = assertThrows(UndeclaredThrowableException.class, seTestMethod); - assertAll( - () -> assertThat(seThrown.getMessage(), is(nullValue())), - () -> assertThat(seThrown.getCause(), is(equalTo(se))) - ); + assertNull(seThrown.getMessage()); + assertEquals(se, seThrown.getCause()); }) ); } diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java index d84f81668..583146af1 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java @@ -20,9 +20,9 @@ import static org.apache.commons.lang3.Supplementary.CharU20000; import static org.apache.commons.lang3.Supplementary.CharU20001; import static org.apache.commons.lang3.Supplementary.CharUSuppCharHigh; import static org.apache.commons.lang3.Supplementary.CharUSuppCharLow; -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.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.params.provider.Arguments.arguments; @@ -30,7 +30,6 @@ import java.nio.CharBuffer; import java.util.Locale; import java.util.stream.Stream; -import org.hamcrest.core.IsNot; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -189,8 +188,8 @@ public class StringUtilsEqualsIndexOfTest extends AbstractLangTest { @Test public void testCustomCharSequence() { - assertThat(new CustomCharSequence(FOO), IsNot.<CharSequence>not(FOO)); - assertThat(FOO, IsNot.<CharSequence>not(new CustomCharSequence(FOO))); + assertNotEquals(FOO, new CustomCharSequence(FOO)); + assertNotEquals(new CustomCharSequence(FOO), FOO); assertEquals(new CustomCharSequence(FOO), new CustomCharSequence(FOO)); } diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index 2c2ed1f30..1f0cecb9f 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -16,8 +16,6 @@ */ package org.apache.commons.lang3; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -147,7 +145,7 @@ public class StringUtilsTest extends AbstractLangTest { assertTrue(actual.indexOf((char) ('a' + offset)) != -1, message + " -- should contain offset character"); } - assertThat(message + " -- should not be greater than maxWidth", actual.length(), lessThanOrEqualTo(maxWidth)); + assertTrue(actual.length() <= maxWidth, () -> message + " -- should not be greater than maxWidth"); assertEquals(expected, actual, message); } @@ -159,7 +157,7 @@ public class StringUtilsTest extends AbstractLangTest { assertTrue(actual.indexOf((char) ('a' + offset)) != -1, message + " -- should contain offset character"); } - assertThat(message + " -- should not be greater than maxWidth", actual.length(), lessThanOrEqualTo(maxWidth)); + assertTrue(actual.length() <= maxWidth, () -> message + " -- should not be greater than maxWidth"); assertEquals(expected, actual, message); } diff --git a/src/test/java/org/apache/commons/lang3/ThreadUtilsTest.java b/src/test/java/org/apache/commons/lang3/ThreadUtilsTest.java index bedd9e3b1..7c922480e 100644 --- a/src/test/java/org/apache/commons/lang3/ThreadUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ThreadUtilsTest.java @@ -19,8 +19,6 @@ package org.apache.commons.lang3; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -124,9 +122,9 @@ public class ThreadUtilsTest extends AbstractLangTest { for (final Thread thread : threads) { thread.start(); } - assertThat("getAllThreadGroups", ThreadUtils.getAllThreadGroups().size(), greaterThanOrEqualTo(7)); - assertThat("getAllThreads", ThreadUtils.getAllThreads().size(), greaterThanOrEqualTo(11)); - assertThat("findThreads(ThreadUtils.ALWAYS_TRUE_PREDICATE)", ThreadUtils.findThreads(Predicates.truePredicate()).size(), greaterThanOrEqualTo(11)); + assertTrue(ThreadUtils.getAllThreadGroups().size() >= 7, "getAllThreadGroups"); + assertTrue(ThreadUtils.getAllThreads().size() >= 11, "getAllThreads"); + assertTrue(ThreadUtils.findThreads(Predicates.truePredicate()).size() >= 11, "findThreads(ThreadUtils.truePredicate())"); assertEquals(1, ThreadUtils.findThreadsByName(t4.getName(), threadGroup3.getName()).size()); assertEquals(0, ThreadUtils.findThreadsByName(t4.getName(), threadGroup2.getName()).size()); assertEquals(2, ThreadUtils.findThreadsByName(t11.getName(), threadGroup7.getName()).size()); diff --git a/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java index f85c0d558..95988db6b 100644 --- a/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java @@ -16,8 +16,6 @@ */ package org.apache.commons.lang3.builder; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -30,7 +28,6 @@ import java.util.List; import org.apache.commons.lang3.AbstractLangTest; import org.apache.commons.lang3.ArrayUtils; -import org.hamcrest.Matcher; import org.junit.jupiter.api.Test; /** @@ -568,41 +565,36 @@ public class DiffBuilderTest extends AbstractLangTest { @Test public void testTriviallyEqualTestDisabled() { - final Matcher<Integer> equalToOne = equalTo(1); - // Constructor's arguments are not trivially equal, but not testing for that. final DiffBuilder<Integer> explicitTestAndNotEqual1 = new DiffBuilder<>(1, 2, null, false); explicitTestAndNotEqual1.append("letter", "X", "Y"); - assertThat(explicitTestAndNotEqual1.build().getNumberOfDiffs(), equalToOne); + assertEquals(1, explicitTestAndNotEqual1.build().getNumberOfDiffs()); // Constructor's arguments are trivially equal, but not testing for that. final DiffBuilder<Integer> explicitTestAndNotEqual2 = new DiffBuilder<>(1, 1, null, false); // This append(f, l, r) will not abort early. explicitTestAndNotEqual2.append("letter", "X", "Y"); - assertThat(explicitTestAndNotEqual2.build().getNumberOfDiffs(), equalToOne); + assertEquals(1, explicitTestAndNotEqual2.build().getNumberOfDiffs()); } @Test public void testTriviallyEqualTestEnabled() { - final Matcher<Integer> equalToZero = equalTo(0); - final Matcher<Integer> equalToOne = equalTo(1); - // The option to test if trivially equal is enabled by default. final DiffBuilder<Integer> implicitTestAndEqual = new DiffBuilder<>(1, 1, null); // This append(f, l, r) will abort without creating a Diff for letter. implicitTestAndEqual.append("letter", "X", "Y"); - assertThat(implicitTestAndEqual.build().getNumberOfDiffs(), equalToZero); + assertEquals(0, implicitTestAndEqual.build().getNumberOfDiffs()); final DiffBuilder<Integer> implicitTestAndNotEqual = new DiffBuilder<>(1, 2, null); // This append(f, l, r) will not abort early // because the constructor's arguments were not trivially equal. implicitTestAndNotEqual.append("letter", "X", "Y"); - assertThat(implicitTestAndNotEqual.build().getNumberOfDiffs(), equalToOne); + assertEquals(1, implicitTestAndNotEqual.build().getNumberOfDiffs()); // This is explicitly enabling the trivially equal test. final DiffBuilder<Integer> explicitTestAndEqual = new DiffBuilder<>(1, 1, null, true); explicitTestAndEqual.append("letter", "X", "Y"); - assertThat(explicitTestAndEqual.build().getNumberOfDiffs(), equalToZero); + assertEquals(0, explicitTestAndEqual.build().getNumberOfDiffs()); } } diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeWithAnnotationTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeWithAnnotationTest.java index b9abc17d2..78359fb78 100644 --- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeWithAnnotationTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeWithAnnotationTest.java @@ -17,9 +17,8 @@ package org.apache.commons.lang3.builder; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.commons.lang3.AbstractLangTest; import org.junit.jupiter.api.Test; @@ -48,11 +47,10 @@ public class ReflectionToStringBuilderExcludeWithAnnotationTest extends Abstract @Test public void test_toStringExclude() { final String toString = ReflectionToStringBuilder.toString(new TestFixture()); - - assertThat(toString, not(containsString(EXCLUDED_FIELD_NAME))); - assertThat(toString, not(containsString(EXCLUDED_FIELD_VALUE))); - assertThat(toString, containsString(INCLUDED_FIELD_NAME)); - assertThat(toString, containsString(INCLUDED_FIELD_VALUE)); + assertFalse(toString.contains(EXCLUDED_FIELD_NAME)); + assertFalse(toString.contains(EXCLUDED_FIELD_VALUE)); + assertTrue(toString.contains(INCLUDED_FIELD_NAME)); + assertTrue(toString.contains(INCLUDED_FIELD_VALUE)); } } diff --git a/src/test/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializerCloseAndExceptionsTest.java b/src/test/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializerCloseAndExceptionsTest.java index 46521017b..a57baae20 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializerCloseAndExceptionsTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/AbstractConcurrentInitializerCloseAndExceptionsTest.java @@ -16,10 +16,9 @@ */ package org.apache.commons.lang3.concurrent; -import static org.hamcrest.CoreMatchers.instanceOf; -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.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -93,8 +92,8 @@ public abstract class AbstractConcurrentInitializerCloseAndExceptionsTest extend ((AbstractConcurrentInitializer) initializer).close(); fail(); } catch (final Exception e) { - assertThat(e, instanceOf(ConcurrentException.class)); - assertThat(e.getCause(), instanceOf(IOException.class)); + assertInstanceOf(ConcurrentException.class, e); + assertInstanceOf(IOException.class, e.getCause()); } } diff --git a/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerSupplierTest.java b/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerSupplierTest.java index 27f9bead5..f023693cf 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerSupplierTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerSupplierTest.java @@ -16,9 +16,8 @@ */ package org.apache.commons.lang3.concurrent; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -117,7 +116,7 @@ public class BackgroundInitializerSupplierTest extends BackgroundInitializerTest init.close(); fail(); } catch (final Exception e) { - assertThat(e, instanceOf(ConcurrentException.class)); + assertInstanceOf(ConcurrentException.class, e); assertSame(ioException, e.getCause()); } } diff --git a/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerSupplierTest.java b/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerSupplierTest.java index af1668899..1eca13e52 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerSupplierTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerSupplierTest.java @@ -16,9 +16,8 @@ */ package org.apache.commons.lang3.concurrent; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -167,7 +166,7 @@ public class MultiBackgroundInitializerSupplierTest extends MultiBackgroundIniti initializer.close(); fail(); } catch (final Exception e) { - assertThat(e, instanceOf(ConcurrentException.class)); + assertInstanceOf(ConcurrentException.class, e); assertSame(ioException, e.getSuppressed()[0]); } } @@ -200,7 +199,7 @@ public class MultiBackgroundInitializerSupplierTest extends MultiBackgroundIniti initializer.close(); fail(); } catch (final Exception e) { - assertThat(e, instanceOf(ConcurrentException.class)); + assertInstanceOf(ConcurrentException.class, e); assertSame(npe, e.getSuppressed()[0]); } } diff --git a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java index 94d58046b..2a9f778ba 100644 --- a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java @@ -16,9 +16,6 @@ */ package org.apache.commons.lang3.reflect; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasItemInArray; -import static org.hamcrest.Matchers.hasItems; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -688,10 +685,8 @@ public class MethodUtilsTest extends AbstractLangTest { final List<Method> methodWithAnnotation = MethodUtils.getMethodsListWithAnnotation(MethodUtilsTest.class, Annotated.class); assertEquals(2, methodWithAnnotation.size()); - assertThat(methodWithAnnotation, hasItems( - MethodUtilsTest.class.getMethod("testGetMethodsWithAnnotation"), - MethodUtilsTest.class.getMethod("testGetMethodsListWithAnnotation") - )); + assertTrue(methodWithAnnotation.contains(MethodUtilsTest.class.getMethod("testGetMethodsWithAnnotation"))); + assertTrue(methodWithAnnotation.contains(MethodUtilsTest.class.getMethod("testGetMethodsListWithAnnotation"))); } @Test @@ -716,8 +711,8 @@ public class MethodUtilsTest extends AbstractLangTest { final Method[] methodsWithAnnotation = MethodUtils.getMethodsWithAnnotation(MethodUtilsTest.class, Annotated.class); assertEquals(2, methodsWithAnnotation.length); - assertThat(methodsWithAnnotation, hasItemInArray(MethodUtilsTest.class.getMethod("testGetMethodsWithAnnotation"))); - assertThat(methodsWithAnnotation, hasItemInArray(MethodUtilsTest.class.getMethod("testGetMethodsListWithAnnotation"))); + assertTrue(ArrayUtils.contains(methodsWithAnnotation, MethodUtilsTest.class.getMethod("testGetMethodsWithAnnotation"))); + assertTrue(ArrayUtils.contains(methodsWithAnnotation, MethodUtilsTest.class.getMethod("testGetMethodsListWithAnnotation"))); } @Test diff --git a/src/test/java/org/apache/commons/lang3/stream/StreamsTest.java b/src/test/java/org/apache/commons/lang3/stream/StreamsTest.java index 9ae76bdc5..4dd7b171d 100644 --- a/src/test/java/org/apache/commons/lang3/stream/StreamsTest.java +++ b/src/test/java/org/apache/commons/lang3/stream/StreamsTest.java @@ -16,13 +16,9 @@ */ package org.apache.commons.lang3.stream; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.hamcrest.core.IsNull.nullValue; -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.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.DynamicTest.dynamicTest; @@ -86,19 +82,20 @@ public class StreamsTest extends AbstractLangTest { final IllegalArgumentException iae = new IllegalArgumentException("Invalid argument: " + 5); final Executable testMethod = () -> Failable.stream(input).map(Integer::valueOf).filter(asIntPredicate(iae)).collect(Collectors.toList()); final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, testMethod); - assertThat(thrown.getMessage(), is(equalTo("Invalid argument: " + 5))); + assertEquals("Invalid argument: " + 5, thrown.getMessage()); }), dynamicTest("OutOfMemoryError", () -> { final OutOfMemoryError oome = new OutOfMemoryError(); final Executable testMethod = () -> Failable.stream(input).map(Integer::valueOf).filter(asIntPredicate(oome)).collect(Collectors.toList()); final OutOfMemoryError thrown = assertThrows(OutOfMemoryError.class, testMethod); - assertThat(thrown.getMessage(), is(nullValue())); + assertNull(thrown.getMessage()); }), dynamicTest("SAXException", () -> { final SAXException se = new SAXException(); final Executable testMethod = () -> Failable.stream(input).map(Integer::valueOf).filter(asIntPredicate(se)).collect(Collectors.toList()); final UndeclaredThrowableException thrown = assertThrows(UndeclaredThrowableException.class, testMethod); - assertAll(() -> assertThat(thrown.getMessage(), is(nullValue())), () -> assertThat(thrown.getCause(), is(equalTo(se)))); + assertNull(thrown.getMessage()); + assertEquals(se, thrown.getCause()); })); } @@ -110,19 +107,20 @@ public class StreamsTest extends AbstractLangTest { final IllegalArgumentException ise = new IllegalArgumentException(); final Executable testMethod = () -> Failable.stream(input).forEach(asIntConsumer(ise)); final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, testMethod); - assertThat(thrown.getMessage(), is(nullValue())); + assertNull(thrown.getMessage()); }), dynamicTest("OutOfMemoryError", () -> { final OutOfMemoryError oome = new OutOfMemoryError(); final Executable oomeTestMethod = () -> Failable.stream(input).forEach(asIntConsumer(oome)); final OutOfMemoryError oomeThrown = assertThrows(OutOfMemoryError.class, oomeTestMethod); - assertThat(oomeThrown.getMessage(), is(nullValue())); + assertNull(oomeThrown.getMessage()); }), dynamicTest("SAXException", () -> { final SAXException se = new SAXException(); final Executable seTestMethod = () -> Failable.stream(input).forEach(asIntConsumer(se)); final UndeclaredThrowableException seThrown = assertThrows(UndeclaredThrowableException.class, seTestMethod); - assertAll(() -> assertThat(seThrown.getMessage(), is(nullValue())), () -> assertThat(seThrown.getCause(), is(equalTo(se)))); + assertNull(seThrown.getMessage()); + assertEquals(se, seThrown.getCause()); })); } diff --git a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java index d9e4f7dc5..7abfac990 100644 --- a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java +++ b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java @@ -16,10 +16,6 @@ */ package org.apache.commons.lang3.time; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -142,7 +138,7 @@ public class StopWatchTest extends AbstractLangTest { watch.split(); final String formatSplitTime = watch.formatSplitTime(); assertNotEquals(ZERO_TIME_ELAPSED, formatSplitTime); - assertThat("formatSplitTime", formatSplitTime, startsWith(ZERO_HOURS_PREFIX)); + assertTrue(formatSplitTime.startsWith(ZERO_HOURS_PREFIX), "formatSplitTime"); } @Test @@ -152,8 +148,8 @@ public class StopWatchTest extends AbstractLangTest { ThreadUtils.sleepQuietly(MIN_DURATION); watch.split(); final String formatSplitTime = watch.formatSplitTime(); - assertThat("formatSplitTime", formatSplitTime, not(startsWith(MESSAGE))); - assertThat("formatSplitTime", formatSplitTime, startsWith(ZERO_HOURS_PREFIX)); + assertFalse(formatSplitTime.startsWith(MESSAGE), "formatSplitTime"); + assertTrue(formatSplitTime.startsWith(ZERO_HOURS_PREFIX), "formatSplitTime"); } @Test @@ -161,14 +157,14 @@ public class StopWatchTest extends AbstractLangTest { final StopWatch watch = StopWatch.create(); final String formatTime = watch.formatTime(); assertEquals(ZERO_TIME_ELAPSED, formatTime); - assertThat("formatTime", formatTime, startsWith(ZERO_HOURS_PREFIX)); + assertTrue(formatTime.startsWith(ZERO_HOURS_PREFIX), "formatTime"); } @Test public void testFormatTimeWithMessage() { final StopWatch watch = new StopWatch(MESSAGE); final String formatTime = watch.formatTime(); - assertThat("formatTime", formatTime, not(startsWith(MESSAGE))); + assertFalse(formatTime.startsWith(MESSAGE), "formatTime"); } @Test @@ -227,7 +223,7 @@ public class StopWatchTest extends AbstractLangTest { watch.start(); watch.getStartInstant(); - assertThat("getStartInstant", watch.getStartInstant(), greaterThanOrEqualTo(Instant.ofEpochMilli(beforeStopWatchMillis))); + assertTrue(watch.getStartInstant().compareTo(Instant.ofEpochMilli(beforeStopWatchMillis)) >= 0); watch.reset(); assertThrows(IllegalStateException.class, watch::getStartInstant, @@ -242,7 +238,7 @@ public class StopWatchTest extends AbstractLangTest { watch.start(); watch.getStartTime(); - assertThat("getStartTime", watch.getStartTime(), greaterThanOrEqualTo(beforeStopWatchMillis)); + assertTrue(watch.getStartTime() >= beforeStopWatchMillis, "getStartTime"); watch.reset(); assertThrows(IllegalStateException.class, watch::getStartTime, "Calling getStartTime on a reset, but unstarted StopWatch should throw an exception"); @@ -296,10 +292,10 @@ public class StopWatchTest extends AbstractLangTest { assertNull(StopWatch.create().getMessage()); final StopWatch stopWatch = new StopWatch(MESSAGE); assertEquals(MESSAGE, stopWatch.getMessage()); - assertThat("stopWatch.toString", stopWatch.toString(), startsWith(MESSAGE)); + assertTrue(stopWatch.toString().startsWith(MESSAGE), "stopWatch.toString"); stopWatch.start(); stopWatch.split(); - assertThat("stopWatch.toSplitString", stopWatch.toSplitString(), startsWith(MESSAGE)); + assertTrue(stopWatch.toSplitString().startsWith(MESSAGE), "stopWatch.toSplitString"); } @Test @@ -494,7 +490,7 @@ public class StopWatchTest extends AbstractLangTest { @Test public void testToStringWithMessage() throws InterruptedException { - assertThat("message", new StopWatch(MESSAGE).toString(), startsWith(MESSAGE)); + assertTrue(new StopWatch(MESSAGE).toString().startsWith(MESSAGE), "message"); // final StopWatch watch = new StopWatch(MESSAGE); watch.start();