Add tests for AssertJ example and update assertj-core dependency version.

This commit is contained in:
Vishal 2020-08-23 10:35:43 +05:30
parent 3cbfd383ed
commit aa223e69ea
2 changed files with 17 additions and 3 deletions

View File

@ -33,7 +33,7 @@
<dependency> <dependency>
<groupId>org.assertj</groupId> <groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId> <artifactId>assertj-core</artifactId>
<version>3.15.0</version> <version>3.16.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,13 +1,14 @@
package com.baeldung.listassert; package com.baeldung.listassert;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -29,7 +30,7 @@ public class OrderAgnosticListComparisonUnitTest {
@Test @Test
public void whenTestingForOrderAgnosticEquality_ShouldBeEqual() { public void whenTestingForOrderAgnosticEquality_ShouldBeEqual() {
assertThat(first, Matchers.containsInAnyOrder(second.toArray())); MatcherAssert.assertThat(first, Matchers.containsInAnyOrder(second.toArray()));
} }
@Test @Test
@ -37,4 +38,17 @@ public class OrderAgnosticListComparisonUnitTest {
assertTrue(CollectionUtils.isEqualCollection(first, second)); assertTrue(CollectionUtils.isEqualCollection(first, second));
assertFalse(CollectionUtils.isEqualCollection(first, third)); assertFalse(CollectionUtils.isEqualCollection(first, third));
} }
@Test
void whenTestingForOrderAgnosticEqualityBothList_ShouldBeEqual() {
assertThat(first).hasSameElementsAs(second);
}
@Test
void whenTestingForOrderAgnosticEqualityBothList_ShouldNotBeEqual() {
List<String> a = Arrays.asList("a", "a", "b", "c");
List<String> b = Arrays.asList("a", "b", "c");
assertThat(a).hasSameElementsAs(b);
}
} }