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-pool.git
The following commit(s) were added to refs/heads/master by this push: new 0cff7649 Use simpler and better JUnit APIs 0cff7649 is described below commit 0cff76494f14420f57324f2c867fdd060594a328 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Sat Jan 18 17:38:01 2025 -0500 Use simpler and better JUnit APIs --- pom.xml | 6 ---- .../pool3/impl/TestDefaultPooledObject.java | 18 ++++------ .../commons/pool3/impl/TestGenericObjectPool.java | 38 ++++++++++------------ 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/pom.xml b/pom.xml index e065c30e..70f17e24 100644 --- a/pom.xml +++ b/pom.xml @@ -63,12 +63,6 @@ <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-library</artifactId> - <version>3.0</version> - <scope>test</scope> - </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> diff --git a/src/test/java/org/apache/commons/pool3/impl/TestDefaultPooledObject.java b/src/test/java/org/apache/commons/pool3/impl/TestDefaultPooledObject.java index e8db4ea5..64a37e96 100644 --- a/src/test/java/org/apache/commons/pool3/impl/TestDefaultPooledObject.java +++ b/src/test/java/org/apache/commons/pool3/impl/TestDefaultPooledObject.java @@ -16,12 +16,10 @@ */ package org.apache.commons.pool3.impl; -import static org.hamcrest.MatcherAssert.assertThat; -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.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Duration; import java.util.ArrayList; @@ -101,11 +99,8 @@ public class TestDefaultPooledObject { assertFalse(dpo.getActiveDuration().isNegative()); assertFalse(dpo.getActiveDuration().isZero()); // We use greaterThanOrEqualTo instead of equal because "now" many be different when each argument is evaluated. - assertThat(1L, lessThanOrEqualTo(2L)); // sanity check - assertThat(Duration.ZERO, lessThanOrEqualTo(Duration.ZERO.plusNanos(1))); // sanity check - assertThat(dpo.getActiveDuration(), lessThanOrEqualTo(dpo.getIdleDuration())); - // Deprecated - assertThat(dpo.getActiveDuration(), lessThanOrEqualTo(dpo.getActiveDuration())); + assertTrue(Duration.ZERO.compareTo(Duration.ZERO.plusNanos(1)) <= 0); // sanity check + assertTrue(dpo.getActiveDuration().compareTo(dpo.getIdleDuration()) <= 0); } @Test @@ -133,7 +128,8 @@ public class TestDefaultPooledObject { final Duration duration2 = dpo.getFullDuration(); assertNotNull(duration2); assertFalse(duration2.isNegative()); - assertThat(duration1, lessThan(duration2)); + assertTrue(duration1.compareTo(duration2) < 0); + } @Test @@ -146,7 +142,7 @@ public class TestDefaultPooledObject { // In the initial state, the idle duration is the time between "now" and the last return, which is the creation time. assertFalse(dpo.getIdleDuration().isNegative()); assertFalse(dpo.getIdleDuration().isZero()); - // We use greaterThanOrEqualTo instead of equal because "now" many be different when each argument is evaluated. - assertThat(dpo.getIdleDuration(), lessThanOrEqualTo(dpo.getActiveDuration())); + // We use <= instead of equal because "now" many be different when each argument is evaluated. + assertTrue(dpo.getIdleDuration().compareTo(dpo.getActiveDuration()) <= 0); } } \ No newline at end of file diff --git a/src/test/java/org/apache/commons/pool3/impl/TestGenericObjectPool.java b/src/test/java/org/apache/commons/pool3/impl/TestGenericObjectPool.java index 3c78fca6..caa3afff 100644 --- a/src/test/java/org/apache/commons/pool3/impl/TestGenericObjectPool.java +++ b/src/test/java/org/apache/commons/pool3/impl/TestGenericObjectPool.java @@ -17,8 +17,6 @@ package org.apache.commons.pool3.impl; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertInstanceOf; @@ -1134,9 +1132,9 @@ public class TestGenericObjectPool extends TestBaseObjectPool { final Instant lastReturnInstant1 = po.getLastReturnInstant(); final Instant lastUsedInstant1 = po.getLastUsedInstant(); - assertThat(po.getCreateInstant(), lessThanOrEqualTo(lastBorrowInstant1)); - assertThat(po.getCreateInstant(), lessThanOrEqualTo(lastReturnInstant1)); - assertThat(po.getCreateInstant(), lessThanOrEqualTo(lastUsedInstant1)); + assertTrue(po.getCreateInstant().compareTo(lastBorrowInstant1) <= 0); + assertTrue(po.getCreateInstant().compareTo(lastReturnInstant1) <= 0); + assertTrue(po.getCreateInstant().compareTo(lastUsedInstant1) <= 0); // Sleep MUST be "long enough" to detect that more than 0 milliseconds have // elapsed. @@ -1147,32 +1145,30 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertFalse(po.getActiveDuration().isZero()); // We use greaterThanOrEqualTo instead of equal because "now" many be different // when each argument is evaluated. - assertThat(1L, lessThanOrEqualTo(2L)); // sanity check - assertThat(Duration.ZERO, lessThanOrEqualTo(Duration.ZERO.plusNanos(1))); // sanity check - assertThat(po.getActiveDuration(), lessThanOrEqualTo(po.getIdleDuration())); - // Deprecated - assertThat(po.getActiveDuration(), lessThanOrEqualTo(po.getActiveDuration())); + assertTrue(Duration.ZERO.compareTo(Duration.ZERO.plusNanos(1)) <= 0); // sanity check + assertTrue(po.getActiveDuration().compareTo(po.getIdleDuration()) <= 0); + assertTrue(po.getActiveDuration().compareTo(po.getActiveDuration()) <= 0); // // TODO How to compare ID with AD since other tests may have touched the PO? - assertThat(po.getActiveDuration(), lessThanOrEqualTo(po.getIdleDuration())); + assertTrue(po.getActiveDuration().compareTo(po.getIdleDuration()) <= 0); // - assertThat(po.getCreateInstant(), lessThanOrEqualTo(po.getLastBorrowInstant())); - assertThat(po.getCreateInstant(), lessThanOrEqualTo(po.getLastReturnInstant())); - assertThat(po.getCreateInstant(), lessThanOrEqualTo(po.getLastUsedInstant())); + assertTrue(po.getCreateInstant().compareTo(po.getLastBorrowInstant()) <= 0); + assertTrue(po.getCreateInstant().compareTo(po.getLastReturnInstant()) <= 0); + assertTrue(po.getCreateInstant().compareTo(po.getLastUsedInstant()) <= 0); - assertThat(lastBorrowInstant1, lessThanOrEqualTo(po.getLastBorrowInstant())); - assertThat(lastReturnInstant1, lessThanOrEqualTo(po.getLastReturnInstant())); - assertThat(lastUsedInstant1, lessThanOrEqualTo(po.getLastUsedInstant())); + assertTrue(lastBorrowInstant1.compareTo(po.getLastBorrowInstant()) <= 0); + assertTrue(lastReturnInstant1.compareTo(po.getLastReturnInstant()) <= 0); + assertTrue(lastUsedInstant1.compareTo(po.getLastUsedInstant()) <= 0); genericObjectPool.returnObject(object); assertFalse(po.getActiveDuration().isNegative()); assertFalse(po.getActiveDuration().isZero()); - assertThat(po.getActiveDuration(), lessThanOrEqualTo(po.getActiveDuration())); + assertTrue(po.getActiveDuration().compareTo(po.getActiveDuration()) <= 0); - assertThat(lastBorrowInstant1, lessThanOrEqualTo(po.getLastBorrowInstant())); - assertThat(lastReturnInstant1, lessThanOrEqualTo(po.getLastReturnInstant())); - assertThat(lastUsedInstant1, lessThanOrEqualTo(po.getLastUsedInstant())); + assertTrue(lastBorrowInstant1.compareTo(po.getLastBorrowInstant()) <= 0); + assertTrue(lastReturnInstant1.compareTo(po.getLastReturnInstant()) <= 0); + assertTrue(lastUsedInstant1.compareTo(po.getLastUsedInstant()) <= 0); } /**