Skip to content

Commit 9b2e8ec

Browse files
Ahmed Tawilapivovarit
authored andcommitted
BAEL-1035 Introduction to Eclipse Collections (eugenp#2425)
* Evaluation article: Different Types of Bean Injection in Spring * added tests & changed configuration to Java-based config * removed xml config files * rename unit tests * BAEL-972 - Apache Commons Text * remove code from evaluation article * remove code from evaluation article * BAEL-972 - Apache Commons Text - added another example * BAEL-972 - Apache Commons Text - just indentation * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java - fix problems * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * fix formatting * BAEL-1033 minor refactor * BAEL-1035 Introduction to Eclipse Collections * format * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * cleanup * cleanup
1 parent 310e89e commit 9b2e8ec

13 files changed

Lines changed: 84 additions & 118 deletions

‎libraries/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternTest.java‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ public class AllSatisfyPatternTest {
1414

1515
@Before
1616
public void getList() {
17-
this.list = new FastList<>();
18-
list.add(1);
19-
list.add(8);
20-
list.add(5);
21-
list.add(41);
22-
list.add(31);
23-
list.add(17);
24-
list.add(23);
25-
list.add(38);
17+
this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38);
2618
}
2719

2820
@Test

‎libraries/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternTest.java‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ public class AnySatisfyPatternTest {
1414

1515
@Before
1616
public void getList() {
17-
this.list = new FastList<>();
18-
list.add(1);
19-
list.add(8);
20-
list.add(5);
21-
list.add(41);
22-
list.add(31);
23-
list.add(17);
24-
list.add(23);
25-
list.add(38);
17+
this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38);
2618
}
2719

2820
@Test

‎libraries/src/test/java/com/baeldung/eclipsecollections/CollectPatternTest.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import org.eclipse.collections.api.list.MutableList;
44
import org.eclipse.collections.impl.list.mutable.FastList;
5-
import static org.junit.Assert.assertEquals;
5+
6+
import org.assertj.core.api.Assertions;
67
import org.junit.Test;
78

89
public class CollectPatternTest {
@@ -16,7 +17,7 @@ public void whenCollect_thenCorrect() {
1617

1718
MutableList<String> lastNames = students.collect(Student::getLastName);
1819

19-
assertEquals("Hopkins", lastNames.get(0));
20-
assertEquals("Adams", lastNames.get(1));
20+
Assertions.assertThat(lastNames)
21+
.containsExactly("Hopkins", "Adams");
2122
}
2223
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.baeldung.eclipsecollections;
22

3-
import static org.junit.Assert.assertTrue;
4-
3+
import org.assertj.core.api.Assertions;
54
import org.eclipse.collections.api.list.MutableList;
6-
import org.eclipse.collections.impl.block.factory.Predicates;
5+
import org.eclipse.collections.impl.list.mutable.FastList;
76
import org.junit.Test;
87

98
public class ConvertContainerToAnotherTest {
@@ -12,9 +11,8 @@ public class ConvertContainerToAnotherTest {
1211
@Test
1312
public void whenConvertContainerToAnother_thenCorrect() {
1413
MutableList<String> cars = (MutableList) ConvertContainerToAnother.convertToList();
15-
16-
assertTrue(cars.anySatisfy(Predicates.equal("Toyota")));
17-
assertTrue(cars.anySatisfy(Predicates.equal("Mercedes")));
18-
assertTrue(cars.anySatisfy(Predicates.equal("Volkswagen")));
14+
15+
Assertions.assertThat(cars)
16+
.containsExactlyElementsOf(FastList.newListWith("Volkswagen", "Toyota", "Mercedes"));
1917
}
2018
}
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.baeldung.eclipsecollections;
22

3+
import org.assertj.core.api.Assertions;
34
import org.eclipse.collections.api.list.MutableList;
45
import org.eclipse.collections.impl.block.factory.Predicates;
56
import org.eclipse.collections.impl.list.mutable.FastList;
6-
import static org.junit.Assert.assertEquals;
7-
87
import org.junit.Before;
98
import org.junit.Test;
109

@@ -14,21 +13,14 @@ public class DetectPatternTest {
1413

1514
@Before
1615
public void getList() {
17-
this.list = new FastList<>();
18-
list.add(1);
19-
list.add(8);
20-
list.add(5);
21-
list.add(41);
22-
list.add(31);
23-
list.add(17);
24-
list.add(23);
25-
list.add(38);
16+
this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38);
2617
}
2718

2819
@Test
2920
public void whenDetect_thenCorrect() {
3021
Integer result = list.detect(Predicates.greaterThan(30));
3122

32-
assertEquals((int) result, 41);
23+
Assertions.assertThat(result)
24+
.isEqualTo(41);
3325
}
3426
}

‎libraries/src/test/java/com/baeldung/eclipsecollections/FlatCollectTest.java‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.baeldung.eclipsecollections;
22

3+
import org.assertj.core.api.Assertions;
34
import org.eclipse.collections.api.list.MutableList;
45
import org.eclipse.collections.impl.list.mutable.FastList;
5-
import static org.junit.Assert.assertEquals;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
610
import org.junit.Before;
711
import org.junit.Test;
812

@@ -13,6 +17,7 @@ public class FlatCollectTest {
1317
MutableList<String> addresses3;
1418
MutableList<String> addresses4;
1519

20+
List<String> expectedAddresses;
1621
MutableList<Student> students;
1722

1823
@Before
@@ -28,15 +33,18 @@ public void setup() {
2833
Student student2 = new Student("George", "Adams", addresses2);
2934
this.addresses2 = FastList.newListWith(address3, address4);
3035
this.students = FastList.newListWith(student1, student2);
36+
this.expectedAddresses = new ArrayList<>();
37+
this.expectedAddresses.add("73 Pacific St., Forest Hills, NY 11375");
38+
this.expectedAddresses.add("93 Bayport Ave., South Richmond Hill, NY 11419");
39+
this.expectedAddresses.add("548 Market St, San Francisco, CA 94104");
40+
this.expectedAddresses.add("8605 Santa Monica Blvd, West Hollywood, CA 90069");
3141
}
3242

3343
@Test
3444
public void whenFlatCollect_thenCorrect() {
3545
MutableList<String> addresses = students.flatCollect(Student::getAddresses);
3646

37-
assertEquals("73 Pacific St., Forest Hills, NY 11375", addresses.get(0));
38-
assertEquals("93 Bayport Ave., South Richmond Hill, NY 11419", addresses.get(1));
39-
assertEquals("548 Market St, San Francisco, CA 94104", addresses.get(2));
40-
assertEquals("8605 Santa Monica Blvd, West Hollywood, CA 90069", addresses.get(3));
47+
Assertions.assertThat(addresses)
48+
.containsExactlyElementsOf(this.expectedAddresses);
4149
}
4250
}

‎libraries/src/test/java/com/baeldung/eclipsecollections/ForEachPatternTest.java‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package com.baeldung.eclipsecollections;
22

3-
import org.eclipse.collections.api.block.procedure.Procedure;
3+
import static org.junit.Assert.assertEquals;
4+
45
import org.eclipse.collections.api.tuple.Pair;
56
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
67
import org.eclipse.collections.impl.tuple.Tuples;
7-
import static org.junit.Assert.assertEquals;
8-
9-
import java.util.Map;
10-
118
import org.junit.Test;
129

1310
public class ForEachPatternTest {

‎libraries/src/test/java/com/baeldung/eclipsecollections/LazyIterationTest.java‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.baeldung.eclipsecollections;
22

3+
import org.assertj.core.api.Assertions;
34
import org.eclipse.collections.api.LazyIterable;
45
import org.eclipse.collections.api.list.MutableList;
5-
import org.eclipse.collections.impl.block.factory.Predicates;
66
import org.eclipse.collections.impl.factory.Lists;
7-
import static org.junit.Assert.assertTrue;
87
import org.junit.Test;
98

109
public class LazyIterationTest {
@@ -19,8 +18,7 @@ public void whenLazyIteration_thenCorrect() {
1918
LazyIterable<Student> lazyStudents = students.asLazy();
2019
LazyIterable<String> lastNames = lazyStudents.collect(Student::getLastName);
2120

22-
assertTrue(lastNames.anySatisfy(Predicates.equal("Hopkins")));
23-
assertTrue(lastNames.anySatisfy(Predicates.equal("Adams")));
24-
assertTrue(lastNames.anySatisfy(Predicates.equal("Rodriguez")));
21+
Assertions.assertThat(lastNames)
22+
.containsAll(Lists.mutable.with("Hopkins", "Adams", "Rodriguez"));
2523
}
2624
}
Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package com.baeldung.eclipsecollections;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertTrue;
5-
3+
import org.assertj.core.api.Assertions;
64
import org.eclipse.collections.api.block.predicate.Predicate;
75
import org.eclipse.collections.api.list.MutableList;
86
import org.eclipse.collections.api.partition.list.PartitionMutableList;
9-
import org.eclipse.collections.impl.block.factory.Predicates;
107
import org.eclipse.collections.impl.list.mutable.FastList;
118
import org.junit.Before;
129
import org.junit.Test;
@@ -17,15 +14,7 @@ public class PartitionPatternTest {
1714

1815
@Before
1916
public void getList() {
20-
this.list = new FastList<>();
21-
list.add(1);
22-
list.add(8);
23-
list.add(5);
24-
list.add(41);
25-
list.add(31);
26-
list.add(17);
27-
list.add(23);
28-
list.add(38);
17+
this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38);
2918
}
3019

3120
@Test
@@ -47,14 +36,9 @@ public boolean accept(Integer each) {
4736
MutableList<Integer> smallerThanThirty = partitionedFolks.getRejected()
4837
.sortThis();
4938

50-
assertEquals(1, (int) smallerThanThirty.getFirst());
51-
assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(5)));
52-
assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(8)));
53-
assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(17)));
54-
assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(23)));
55-
56-
assertTrue(greaterThanThirty.anySatisfy(Predicates.equal(31)));
57-
assertTrue(greaterThanThirty.anySatisfy(Predicates.equal(38)));
58-
assertTrue(greaterThanThirty.anySatisfy(Predicates.equal(41)));
39+
Assertions.assertThat(smallerThanThirty)
40+
.containsExactly(1, 5, 8, 17, 23);
41+
Assertions.assertThat(greaterThanThirty)
42+
.containsExactly(31, 38, 41);
5943
}
6044
}
Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
package com.baeldung.eclipsecollections;
22

3+
import org.assertj.core.api.Assertions;
34
import org.eclipse.collections.api.list.MutableList;
45
import org.eclipse.collections.impl.block.factory.Predicates;
56
import org.eclipse.collections.impl.list.mutable.FastList;
6-
import static org.junit.Assert.assertEquals;
77
import org.junit.Before;
88
import org.junit.Test;
99

1010
public class RejectPatternTest {
1111

1212
MutableList<Integer> list;
13+
MutableList<Integer> expectedList;
1314

1415
@Before
15-
public void getList() {
16-
this.list = new FastList<>();
17-
list.add(1);
18-
list.add(8);
19-
list.add(5);
20-
list.add(41);
21-
list.add(31);
22-
list.add(17);
23-
list.add(23);
24-
list.add(38);
16+
public void setup() {
17+
this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38);
18+
this.expectedList = FastList.newListWith(1, 5, 8, 17, 23);
2519
}
2620

2721
@Test
2822
public void whenReject_thenCorrect() {
2923
MutableList<Integer> notGreaterThanThirty = list.reject(Predicates.greaterThan(30))
3024
.sortThis();
3125

32-
assertEquals(1, (int) notGreaterThanThirty.getFirst());
33-
assertEquals(5, (int) notGreaterThanThirty.get(1));
34-
assertEquals(8, (int) notGreaterThanThirty.get(2));
35-
assertEquals(17, (int) notGreaterThanThirty.get(3));
36-
assertEquals(23, (int) notGreaterThanThirty.getLast());
26+
Assertions.assertThat(notGreaterThanThirty)
27+
.containsExactlyElementsOf(this.expectedList);
3728
}
3829
}

0 commit comments

Comments
 (0)