Make test more readable and maintainable, and less verbose
- Use JUnit 5 APIs - Be consistent throughout tests
This commit is contained in:
parent
20a877f04a
commit
5711be7809
6
pom.xml
6
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>
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue