diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternTest.java index 9f66fee0a8..1ea10317c7 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternTest.java @@ -5,13 +5,16 @@ import static org.junit.Assert.assertTrue; 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.Before; import org.junit.Test; public class AllSatisfyPatternTest { - @Test - public void whenAnySatisfiesCondition_thenCorrect() { - MutableList list = new FastList<>(); + MutableList list; + + @Before + public void getList() { + this.list = new FastList<>(); list.add(1); list.add(8); list.add(5); @@ -20,7 +23,10 @@ public class AllSatisfyPatternTest { list.add(17); list.add(23); list.add(38); + } + @Test + public void whenAnySatisfiesCondition_thenCorrect() { boolean result = list.allSatisfy(Predicates.greaterThan(0)); assertTrue(result); diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternTest.java index c3ab83abdc..58f8ad40af 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternTest.java @@ -5,13 +5,16 @@ import static org.junit.Assert.assertTrue; 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.Before; import org.junit.Test; public class AnySatisfyPatternTest { - @Test - public void whenAnySatisfiesCondition_thenCorrect() { - MutableList list = new FastList<>(); + MutableList list; + + @Before + public void getList() { + this.list = new FastList<>(); list.add(1); list.add(8); list.add(5); @@ -20,7 +23,10 @@ public class AnySatisfyPatternTest { list.add(17); list.add(23); list.add(38); + } + @Test + public void whenAnySatisfiesCondition_thenCorrect() { boolean result = list.anySatisfy(Predicates.greaterThan(30)); assertTrue(result); diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/DetectPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/DetectPatternTest.java index 39d77498ca..fc643f2840 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/DetectPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/DetectPatternTest.java @@ -4,13 +4,17 @@ 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 DetectPatternTest { - @Test - public void whenDetect_thenCorrect() { - MutableList list = new FastList<>(); + MutableList list; + + @Before + public void getList() { + this.list = new FastList<>(); list.add(1); list.add(8); list.add(5); @@ -19,7 +23,10 @@ public class DetectPatternTest { list.add(17); list.add(23); list.add(38); + } + @Test + public void whenDetect_thenCorrect() { Integer result = list.detect(Predicates.greaterThan(30)); assertEquals((int) result, 41); diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/PartitionPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/PartitionPatternTest.java new file mode 100644 index 0000000000..3e52829824 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/PartitionPatternTest.java @@ -0,0 +1,61 @@ +package com.baeldung.eclipsecollections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +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; + +public class PartitionPatternTest { + + MutableList list; + + @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); + } + + @SuppressWarnings({ "unused" }) + @Test + public void whenAnySatisfiesCondition_thenCorrect() { + MutableList numbers = list; + PartitionMutableList partitionedFolks = numbers.partition(new Predicate() { + + /** + * + */ + private static final long serialVersionUID = -1551138743683678406L; + + public boolean accept(Integer each) { + return each > 30; + } + }); + MutableList greaterThanThirty = partitionedFolks.getSelected() + .sortThis(); + 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))); + } +} diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/RejectPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/RejectPatternTest.java index 2cc1cdb945..044a8203d6 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/RejectPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/RejectPatternTest.java @@ -3,14 +3,17 @@ package com.baeldung.eclipsecollections; 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.Assert; +import static org.junit.Assert.assertEquals; +import org.junit.Before; import org.junit.Test; public class RejectPatternTest { - @Test - public void whenReject_thenCorrect() { - MutableList list = new FastList<>(); + MutableList list; + + @Before + public void getList() { + this.list = new FastList<>(); list.add(1); list.add(8); list.add(5); @@ -19,14 +22,17 @@ public class RejectPatternTest { list.add(17); list.add(23); list.add(38); + } + @Test + public void whenReject_thenCorrect() { MutableList notGreaterThanThirty = list.reject(Predicates.greaterThan(30)) .sortThis(); - Assert.assertEquals(1, (int) notGreaterThanThirty.getFirst()); - Assert.assertEquals(5, (int) notGreaterThanThirty.get(1)); - Assert.assertEquals(8, (int) notGreaterThanThirty.get(2)); - Assert.assertEquals(17, (int) notGreaterThanThirty.get(3)); - Assert.assertEquals(23, (int) notGreaterThanThirty.getLast()); + 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()); } } diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/SelectPatternTest.java b/libraries/src/test/java/com/baeldung/eclipsecollections/SelectPatternTest.java index c5e3af3a3f..20c94f6028 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/SelectPatternTest.java +++ b/libraries/src/test/java/com/baeldung/eclipsecollections/SelectPatternTest.java @@ -3,14 +3,17 @@ package com.baeldung.eclipsecollections; 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.Assert; +import static org.junit.Assert.assertEquals; +import org.junit.Before; import org.junit.Test; public class SelectPatternTest { - @Test - public void whenSelect_thenCorrect() { - MutableList list = new FastList<>(); + MutableList list; + + @Before + public void getList() { + this.list = new FastList<>(); list.add(1); list.add(8); list.add(5); @@ -19,36 +22,31 @@ public class SelectPatternTest { list.add(17); list.add(23); list.add(38); + } + @Test + public void givenListwhenSelect_thenCorrect() { MutableList greaterThanThirty = list.select(Predicates.greaterThan(30)) .sortThis(); - Assert.assertEquals(31, (int) greaterThanThirty.getFirst()); - Assert.assertEquals(38, (int) greaterThanThirty.get(1)); - Assert.assertEquals(41, (int) greaterThanThirty.getLast()); + assertEquals(31, (int) greaterThanThirty.getFirst()); + assertEquals(38, (int) greaterThanThirty.get(1)); + assertEquals(41, (int) greaterThanThirty.getLast()); } + @SuppressWarnings("rawtypes") public MutableList selectUsingLambda() { - MutableList 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); - return list.select(each -> each > 30) .sortThis(); } + @SuppressWarnings("unchecked") @Test - public void whenSelectUsingLambda_thenCorrect() { + public void givenListwhenSelectUsingLambda_thenCorrect() { MutableList greaterThanThirty = selectUsingLambda(); - Assert.assertEquals(31, (int) greaterThanThirty.getFirst()); - Assert.assertEquals(38, (int) greaterThanThirty.get(1)); - Assert.assertEquals(41, (int) greaterThanThirty.getLast()); + assertEquals(31, (int) greaterThanThirty.getFirst()); + assertEquals(38, (int) greaterThanThirty.get(1)); + assertEquals(41, (int) greaterThanThirty.getLast()); } }