diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternTest.java index 1ea10317c7..ee369fc75b 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternTest.java @@ -14,15 +14,7 @@ public class AllSatisfyPatternTest { @Before public void getList() { - this.list = new FastList<>(); - list.add(1); - list.add(8); - list.add(5); - list.add(41); - list.add(31); - list.add(17); - list.add(23); - list.add(38); + this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); } @Test diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternTest.java index 58f8ad40af..a3314ebee6 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternTest.java @@ -14,15 +14,7 @@ public class AnySatisfyPatternTest { @Before public void getList() { - this.list = new FastList<>(); - list.add(1); - list.add(8); - list.add(5); - list.add(41); - list.add(31); - list.add(17); - list.add(23); - list.add(38); + this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); } @Test diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/CollectPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/CollectPatternTest.java index 5fb63794a1..ee384c2f9d 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/CollectPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/CollectPatternTest.java @@ -2,7 +2,8 @@ package com.baeldung.eclipsecollections; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.impl.list.mutable.FastList; -import static org.junit.Assert.assertEquals; + +import org.assertj.core.api.Assertions; import org.junit.Test; public class CollectPatternTest { @@ -16,7 +17,7 @@ public class CollectPatternTest { MutableList lastNames = students.collect(Student::getLastName); - assertEquals("Hopkins", lastNames.get(0)); - assertEquals("Adams", lastNames.get(1)); + Assertions.assertThat(lastNames) + .containsExactly("Hopkins", "Adams"); } } diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/ConvertContainerToAnotherTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/ConvertContainerToAnotherTest.java index b538abfa6e..4655431872 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/ConvertContainerToAnotherTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/ConvertContainerToAnotherTest.java @@ -1,9 +1,8 @@ package com.baeldung.eclipsecollections; -import static org.junit.Assert.assertTrue; - +import org.assertj.core.api.Assertions; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.impl.block.factory.Predicates; +import org.eclipse.collections.impl.list.mutable.FastList; import org.junit.Test; public class ConvertContainerToAnotherTest { @@ -12,9 +11,8 @@ public class ConvertContainerToAnotherTest { @Test public void whenConvertContainerToAnother_thenCorrect() { MutableList cars = (MutableList) ConvertContainerToAnother.convertToList(); - - assertTrue(cars.anySatisfy(Predicates.equal("Toyota"))); - assertTrue(cars.anySatisfy(Predicates.equal("Mercedes"))); - assertTrue(cars.anySatisfy(Predicates.equal("Volkswagen"))); + + Assertions.assertThat(cars) + .containsExactlyElementsOf(FastList.newListWith("Volkswagen", "Toyota", "Mercedes")); } } diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/DetectPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/DetectPatternTest.java index fc643f2840..c5b5e1c412 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/DetectPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/DetectPatternTest.java @@ -1,10 +1,9 @@ package com.baeldung.eclipsecollections; +import org.assertj.core.api.Assertions; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.list.mutable.FastList; -import static org.junit.Assert.assertEquals; - import org.junit.Before; import org.junit.Test; @@ -14,21 +13,14 @@ public class DetectPatternTest { @Before public void getList() { - this.list = new FastList<>(); - list.add(1); - list.add(8); - list.add(5); - list.add(41); - list.add(31); - list.add(17); - list.add(23); - list.add(38); + this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); } @Test public void whenDetect_thenCorrect() { Integer result = list.detect(Predicates.greaterThan(30)); - assertEquals((int) result, 41); + Assertions.assertThat(result) + .isEqualTo(41); } } diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/FlatCollectTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/FlatCollectTest.java index 3d1453e557..021c72e91e 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/FlatCollectTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/FlatCollectTest.java @@ -1,8 +1,12 @@ package com.baeldung.eclipsecollections; +import org.assertj.core.api.Assertions; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.impl.list.mutable.FastList; -import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + import org.junit.Before; import org.junit.Test; @@ -13,6 +17,7 @@ public class FlatCollectTest { MutableList addresses3; MutableList addresses4; + List expectedAddresses; MutableList students; @Before @@ -28,15 +33,18 @@ public class FlatCollectTest { Student student2 = new Student("George", "Adams", addresses2); this.addresses2 = FastList.newListWith(address3, address4); this.students = FastList.newListWith(student1, student2); + this.expectedAddresses = new ArrayList<>(); + this.expectedAddresses.add("73 Pacific St., Forest Hills, NY 11375"); + this.expectedAddresses.add("93 Bayport Ave., South Richmond Hill, NY 11419"); + this.expectedAddresses.add("548 Market St, San Francisco, CA 94104"); + this.expectedAddresses.add("8605 Santa Monica Blvd, West Hollywood, CA 90069"); } @Test public void whenFlatCollect_thenCorrect() { MutableList addresses = students.flatCollect(Student::getAddresses); - assertEquals("73 Pacific St., Forest Hills, NY 11375", addresses.get(0)); - assertEquals("93 Bayport Ave., South Richmond Hill, NY 11419", addresses.get(1)); - assertEquals("548 Market St, San Francisco, CA 94104", addresses.get(2)); - assertEquals("8605 Santa Monica Blvd, West Hollywood, CA 90069", addresses.get(3)); + Assertions.assertThat(addresses) + .containsExactlyElementsOf(this.expectedAddresses); } } diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/ForEachPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/ForEachPatternTest.java index e8d93a2af6..8cea575222 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/ForEachPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/ForEachPatternTest.java @@ -1,13 +1,10 @@ package com.baeldung.eclipsecollections; -import org.eclipse.collections.api.block.procedure.Procedure; +import static org.junit.Assert.assertEquals; + import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.tuple.Tuples; -import static org.junit.Assert.assertEquals; - -import java.util.Map; - import org.junit.Test; public class ForEachPatternTest { diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/LazyIterationTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/LazyIterationTest.java index 8fe1286d41..9c216ecc87 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/LazyIterationTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/LazyIterationTest.java @@ -1,10 +1,9 @@ package com.baeldung.eclipsecollections; +import org.assertj.core.api.Assertions; import org.eclipse.collections.api.LazyIterable; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.factory.Lists; -import static org.junit.Assert.assertTrue; import org.junit.Test; public class LazyIterationTest { @@ -19,8 +18,7 @@ public class LazyIterationTest { LazyIterable lazyStudents = students.asLazy(); LazyIterable lastNames = lazyStudents.collect(Student::getLastName); - assertTrue(lastNames.anySatisfy(Predicates.equal("Hopkins"))); - assertTrue(lastNames.anySatisfy(Predicates.equal("Adams"))); - assertTrue(lastNames.anySatisfy(Predicates.equal("Rodriguez"))); + Assertions.assertThat(lastNames) + .containsAll(Lists.mutable.with("Hopkins", "Adams", "Rodriguez")); } } diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/PartitionPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/PartitionPatternTest.java index 4d9619817b..c055413cd9 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/PartitionPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/PartitionPatternTest.java @@ -1,12 +1,9 @@ package com.baeldung.eclipsecollections; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - +import org.assertj.core.api.Assertions; import org.eclipse.collections.api.block.predicate.Predicate; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.partition.list.PartitionMutableList; -import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.list.mutable.FastList; import org.junit.Before; import org.junit.Test; @@ -17,15 +14,7 @@ public class PartitionPatternTest { @Before public void getList() { - this.list = new FastList<>(); - list.add(1); - list.add(8); - list.add(5); - list.add(41); - list.add(31); - list.add(17); - list.add(23); - list.add(38); + this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); } @Test @@ -47,14 +36,9 @@ public class PartitionPatternTest { MutableList smallerThanThirty = partitionedFolks.getRejected() .sortThis(); - assertEquals(1, (int) smallerThanThirty.getFirst()); - assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(5))); - assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(8))); - assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(17))); - assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(23))); - - assertTrue(greaterThanThirty.anySatisfy(Predicates.equal(31))); - assertTrue(greaterThanThirty.anySatisfy(Predicates.equal(38))); - assertTrue(greaterThanThirty.anySatisfy(Predicates.equal(41))); + Assertions.assertThat(smallerThanThirty) + .containsExactly(1, 5, 8, 17, 23); + Assertions.assertThat(greaterThanThirty) + .containsExactly(31, 38, 41); } } diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/RejectPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/RejectPatternTest.java index 044a8203d6..1666c86333 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/RejectPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/RejectPatternTest.java @@ -1,27 +1,21 @@ package com.baeldung.eclipsecollections; +import org.assertj.core.api.Assertions; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.list.mutable.FastList; -import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; public class RejectPatternTest { MutableList list; + MutableList expectedList; @Before - public void getList() { - this.list = new FastList<>(); - list.add(1); - list.add(8); - list.add(5); - list.add(41); - list.add(31); - list.add(17); - list.add(23); - list.add(38); + public void setup() { + this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); + this.expectedList = FastList.newListWith(1, 5, 8, 17, 23); } @Test @@ -29,10 +23,7 @@ public class RejectPatternTest { MutableList notGreaterThanThirty = list.reject(Predicates.greaterThan(30)) .sortThis(); - assertEquals(1, (int) notGreaterThanThirty.getFirst()); - assertEquals(5, (int) notGreaterThanThirty.get(1)); - assertEquals(8, (int) notGreaterThanThirty.get(2)); - assertEquals(17, (int) notGreaterThanThirty.get(3)); - assertEquals(23, (int) notGreaterThanThirty.getLast()); + Assertions.assertThat(notGreaterThanThirty) + .containsExactlyElementsOf(this.expectedList); } } diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/SelectPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/SelectPatternTest.java index 20c94f6028..d79c864fc5 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/SelectPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/SelectPatternTest.java @@ -1,9 +1,9 @@ package com.baeldung.eclipsecollections; +import org.assertj.core.api.Assertions; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.list.mutable.FastList; -import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; @@ -13,15 +13,7 @@ public class SelectPatternTest { @Before public void getList() { - this.list = new FastList<>(); - list.add(1); - list.add(8); - list.add(5); - list.add(41); - list.add(31); - list.add(17); - list.add(23); - list.add(38); + this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); } @Test @@ -29,9 +21,8 @@ public class SelectPatternTest { MutableList greaterThanThirty = list.select(Predicates.greaterThan(30)) .sortThis(); - assertEquals(31, (int) greaterThanThirty.getFirst()); - assertEquals(38, (int) greaterThanThirty.get(1)); - assertEquals(41, (int) greaterThanThirty.getLast()); + Assertions.assertThat(greaterThanThirty) + .containsExactly(31, 38, 41); } @SuppressWarnings("rawtypes") @@ -45,8 +36,7 @@ public class SelectPatternTest { public void givenListwhenSelectUsingLambda_thenCorrect() { MutableList greaterThanThirty = selectUsingLambda(); - assertEquals(31, (int) greaterThanThirty.getFirst()); - assertEquals(38, (int) greaterThanThirty.get(1)); - assertEquals(41, (int) greaterThanThirty.getLast()); + Assertions.assertThat(greaterThanThirty) + .containsExactly(31, 38, 41); } } diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/ZipTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/ZipTest.java index 9dfab8f32d..29f0c23954 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/ZipTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/ZipTest.java @@ -4,19 +4,31 @@ import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.tuple.Tuples; -import static org.junit.Assert.assertEquals; + +import org.assertj.core.api.Assertions; +import org.junit.Before; import org.junit.Test; public class ZipTest { + MutableList> expectedPairs; + + @SuppressWarnings("unchecked") + @Before + public void setup() { + Pair pair1 = Tuples.pair("1", "Porsche"); + Pair pair2 = Tuples.pair("2", "Volvo"); + Pair pair3 = Tuples.pair("3", "Toyota"); + expectedPairs = Lists.mutable.of(pair1, pair2, pair3); + } + @Test public void whenZip_thenCorrect() { MutableList numbers = Lists.mutable.with("1", "2", "3", "Ignored"); MutableList cars = Lists.mutable.with("Porsche", "Volvo", "Toyota"); MutableList> pairs = numbers.zip(cars); - assertEquals(Tuples.pair("1", "Porsche"), pairs.get(0)); - assertEquals(Tuples.pair("2", "Volvo"), pairs.get(1)); - assertEquals(Tuples.pair("3", "Toyota"), pairs.get(2)); + Assertions.assertThat(pairs) + .containsExactlyElementsOf(this.expectedPairs); } } diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/ZipWithIndexTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/ZipWithIndexTest.java index 3e8fe9b410..a2d8be44ec 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/ZipWithIndexTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/ZipWithIndexTest.java @@ -1,22 +1,33 @@ package com.baeldung.eclipsecollections; -import static org.junit.Assert.assertEquals; - +import org.assertj.core.api.Assertions; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.tuple.Pair; +import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.tuple.Tuples; +import org.junit.Before; import org.junit.Test; public class ZipWithIndexTest { + MutableList> expectedPairs; + + @SuppressWarnings("unchecked") + @Before + public void setup() { + Pair pair1 = Tuples.pair("Porsche", 0); + Pair pair2 = Tuples.pair("Volvo", 1); + Pair pair3 = Tuples.pair("Toyota", 2); + expectedPairs = Lists.mutable.of(pair1, pair2, pair3); + } + @Test public void whenZip_thenCorrect() { MutableList cars = FastList.newListWith("Porsche", "Volvo", "Toyota"); MutableList> pairs = cars.zipWithIndex(); - assertEquals(Tuples.pair("Porsche", 0), pairs.get(0)); - assertEquals(Tuples.pair("Volvo", 1), pairs.get(1)); - assertEquals(Tuples.pair("Toyota", 2), pairs.get(2)); + Assertions.assertThat(pairs) + .containsExactlyElementsOf(this.expectedPairs); } }