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-collections.git
The following commit(s) were added to refs/heads/master by this push: new 5711be780 Make test more readable and maintainable, and less verbose 5711be780 is described below commit 5711be7809f1350e19b9413c778b6a1d33432972 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue Oct 1 09:42:06 2024 -0400 Make test more readable and maintainable, and less verbose - Use JUnit 5 APIs - Be consistent throughout tests --- pom.xml | 6 ------ .../collections4/iterators/BoundedIteratorTest.java | 18 ++++++++---------- .../commons/collections4/list/GrowthListTest.java | 5 +---- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 195a2e03c..d243ddf4f 100644 --- a/pom.xml +++ b/pom.xml @@ -48,12 +48,6 @@ <artifactId>junit-jupiter-params</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/collections4/iterators/BoundedIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java index 36f66236e..52f8f8238 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java @@ -16,14 +16,11 @@ */ package org.apache.commons.collections4.iterators; -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.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.ArrayList; import java.util.Arrays; @@ -142,7 +139,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> { @Test public void testNegativeMax() { final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> new BoundedIterator<>(testList.iterator(), 3, -1)); - assertThat(thrown.getMessage(), is(equalTo("Max parameter must not be negative."))); + assertEquals("Max parameter must not be negative.", thrown.getMessage()); } /** @@ -152,7 +149,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> { @Test public void testNegativeOffset() { final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> new BoundedIterator<>(testList.iterator(), -1, 4)); - assertThat(thrown.getMessage(), is(equalTo("Offset parameter must not be negative."))); + assertEquals("Offset parameter must not be negative.", thrown.getMessage()); } /** @@ -236,7 +233,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> { assertFalse(iter.hasNext()); final NoSuchElementException thrown = assertThrows(NoSuchElementException.class, () -> iter.next()); - assertThat(thrown.getMessage(), is(nullValue())); + assertNull(thrown.getMessage()); iter.remove(); assertFalse(testListCopy.contains("f")); @@ -244,7 +241,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> { assertFalse(iter.hasNext()); final NoSuchElementException thrown1 = assertThrows(NoSuchElementException.class, () -> iter.next()); - assertThat(thrown1.getMessage(), is(nullValue())); + assertNull(thrown1.getMessage()); } /** @@ -294,7 +291,8 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> { assertEquals("b", iter.next()); final UnsupportedOperationException thrown = assertThrows(UnsupportedOperationException.class, () -> iter.remove()); - assertThat(thrown.getMessage(), is(nullValue())); + assertNull(thrown.getMessage()); + } /** @@ -307,7 +305,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> { final Iterator<E> iter = new BoundedIterator<>(testListCopy.iterator(), 1, 5); final IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> iter.remove()); - assertThat(thrown.getMessage(), is(equalTo("remove() can not be called before calling next()"))); + assertEquals("remove() can not be called before calling next()", thrown.getMessage()); } /** diff --git a/src/test/java/org/apache/commons/collections4/list/GrowthListTest.java b/src/test/java/org/apache/commons/collections4/list/GrowthListTest.java index 33aa99a16..a8764c0c4 100644 --- a/src/test/java/org/apache/commons/collections4/list/GrowthListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/GrowthListTest.java @@ -16,9 +16,6 @@ */ package org.apache.commons.collections4.list; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -131,7 +128,7 @@ public class GrowthListTest<E> extends AbstractListTest<E> { final Executable testMethod = () -> list.add(-1, element); final IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, testMethod, "List.add should throw IndexOutOfBoundsException [-1]"); - assertThat(thrown.getMessage(), is(equalTo("Index: -1, Size: 0"))); + assertEquals("Index: -1, Size: 0", thrown.getMessage()); } /**