BAEL-1035 Introduction to Eclipse Collections (#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
This commit is contained in:
		
							parent
							
								
									310e89e4f0
								
							
						
					
					
						commit
						9b2e8ec9f9
					
				| @ -14,15 +14,7 @@ public class AllSatisfyPatternTest { | |||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void getList() { |     public void getList() { | ||||||
|         this.list = new FastList<>(); |         this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); | ||||||
|         list.add(1); |  | ||||||
|         list.add(8); |  | ||||||
|         list.add(5); |  | ||||||
|         list.add(41); |  | ||||||
|         list.add(31); |  | ||||||
|         list.add(17); |  | ||||||
|         list.add(23); |  | ||||||
|         list.add(38); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|  | |||||||
| @ -14,15 +14,7 @@ public class AnySatisfyPatternTest { | |||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void getList() { |     public void getList() { | ||||||
|         this.list = new FastList<>(); |         this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); | ||||||
|         list.add(1); |  | ||||||
|         list.add(8); |  | ||||||
|         list.add(5); |  | ||||||
|         list.add(41); |  | ||||||
|         list.add(31); |  | ||||||
|         list.add(17); |  | ||||||
|         list.add(23); |  | ||||||
|         list.add(38); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|  | |||||||
| @ -2,7 +2,8 @@ package com.baeldung.eclipsecollections; | |||||||
| 
 | 
 | ||||||
| import org.eclipse.collections.api.list.MutableList; | import org.eclipse.collections.api.list.MutableList; | ||||||
| import org.eclipse.collections.impl.list.mutable.FastList; | import org.eclipse.collections.impl.list.mutable.FastList; | ||||||
| import static org.junit.Assert.assertEquals; | 
 | ||||||
|  | import org.assertj.core.api.Assertions; | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| public class CollectPatternTest { | public class CollectPatternTest { | ||||||
| @ -16,7 +17,7 @@ public class CollectPatternTest { | |||||||
| 
 | 
 | ||||||
|         MutableList<String> lastNames = students.collect(Student::getLastName); |         MutableList<String> lastNames = students.collect(Student::getLastName); | ||||||
| 
 | 
 | ||||||
|         assertEquals("Hopkins", lastNames.get(0)); |         Assertions.assertThat(lastNames) | ||||||
|         assertEquals("Adams", lastNames.get(1)); |             .containsExactly("Hopkins", "Adams"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,9 +1,8 @@ | |||||||
| package com.baeldung.eclipsecollections; | 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.api.list.MutableList; | ||||||
| import org.eclipse.collections.impl.block.factory.Predicates; | import org.eclipse.collections.impl.list.mutable.FastList; | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| public class ConvertContainerToAnotherTest { | public class ConvertContainerToAnotherTest { | ||||||
| @ -12,9 +11,8 @@ public class ConvertContainerToAnotherTest { | |||||||
|     @Test |     @Test | ||||||
|     public void whenConvertContainerToAnother_thenCorrect() { |     public void whenConvertContainerToAnother_thenCorrect() { | ||||||
|         MutableList<String> cars = (MutableList) ConvertContainerToAnother.convertToList(); |         MutableList<String> cars = (MutableList) ConvertContainerToAnother.convertToList(); | ||||||
|          | 
 | ||||||
|         assertTrue(cars.anySatisfy(Predicates.equal("Toyota"))); |         Assertions.assertThat(cars) | ||||||
|         assertTrue(cars.anySatisfy(Predicates.equal("Mercedes"))); |             .containsExactlyElementsOf(FastList.newListWith("Volkswagen", "Toyota", "Mercedes")); | ||||||
|         assertTrue(cars.anySatisfy(Predicates.equal("Volkswagen"))); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,10 +1,9 @@ | |||||||
| package com.baeldung.eclipsecollections; | package com.baeldung.eclipsecollections; | ||||||
| 
 | 
 | ||||||
|  | import org.assertj.core.api.Assertions; | ||||||
| import org.eclipse.collections.api.list.MutableList; | import org.eclipse.collections.api.list.MutableList; | ||||||
| import org.eclipse.collections.impl.block.factory.Predicates; | import org.eclipse.collections.impl.block.factory.Predicates; | ||||||
| import org.eclipse.collections.impl.list.mutable.FastList; | import org.eclipse.collections.impl.list.mutable.FastList; | ||||||
| import static org.junit.Assert.assertEquals; |  | ||||||
| 
 |  | ||||||
| import org.junit.Before; | import org.junit.Before; | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| @ -14,21 +13,14 @@ public class DetectPatternTest { | |||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void getList() { |     public void getList() { | ||||||
|         this.list = new FastList<>(); |         this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); | ||||||
|         list.add(1); |  | ||||||
|         list.add(8); |  | ||||||
|         list.add(5); |  | ||||||
|         list.add(41); |  | ||||||
|         list.add(31); |  | ||||||
|         list.add(17); |  | ||||||
|         list.add(23); |  | ||||||
|         list.add(38); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenDetect_thenCorrect() { |     public void whenDetect_thenCorrect() { | ||||||
|         Integer result = list.detect(Predicates.greaterThan(30)); |         Integer result = list.detect(Predicates.greaterThan(30)); | ||||||
| 
 | 
 | ||||||
|         assertEquals((int) result, 41); |         Assertions.assertThat(result) | ||||||
|  |             .isEqualTo(41); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,8 +1,12 @@ | |||||||
| package com.baeldung.eclipsecollections; | package com.baeldung.eclipsecollections; | ||||||
| 
 | 
 | ||||||
|  | import org.assertj.core.api.Assertions; | ||||||
| import org.eclipse.collections.api.list.MutableList; | import org.eclipse.collections.api.list.MutableList; | ||||||
| import org.eclipse.collections.impl.list.mutable.FastList; | 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.Before; | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| @ -13,6 +17,7 @@ public class FlatCollectTest { | |||||||
|     MutableList<String> addresses3; |     MutableList<String> addresses3; | ||||||
|     MutableList<String> addresses4; |     MutableList<String> addresses4; | ||||||
| 
 | 
 | ||||||
|  |     List<String> expectedAddresses; | ||||||
|     MutableList<Student> students; |     MutableList<Student> students; | ||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
| @ -28,15 +33,18 @@ public class FlatCollectTest { | |||||||
|         Student student2 = new Student("George", "Adams", addresses2); |         Student student2 = new Student("George", "Adams", addresses2); | ||||||
|         this.addresses2 = FastList.newListWith(address3, address4); |         this.addresses2 = FastList.newListWith(address3, address4); | ||||||
|         this.students = FastList.newListWith(student1, student2); |         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 |     @Test | ||||||
|     public void whenFlatCollect_thenCorrect() { |     public void whenFlatCollect_thenCorrect() { | ||||||
|         MutableList<String> addresses = students.flatCollect(Student::getAddresses); |         MutableList<String> addresses = students.flatCollect(Student::getAddresses); | ||||||
| 
 | 
 | ||||||
|         assertEquals("73 Pacific St., Forest Hills, NY 11375", addresses.get(0)); |         Assertions.assertThat(addresses) | ||||||
|         assertEquals("93 Bayport Ave., South Richmond Hill, NY 11419", addresses.get(1)); |             .containsExactlyElementsOf(this.expectedAddresses); | ||||||
|         assertEquals("548 Market St, San Francisco, CA 94104", addresses.get(2)); |  | ||||||
|         assertEquals("8605 Santa Monica Blvd, West Hollywood, CA 90069", addresses.get(3)); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,13 +1,10 @@ | |||||||
| package com.baeldung.eclipsecollections; | 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.api.tuple.Pair; | ||||||
| import org.eclipse.collections.impl.map.mutable.UnifiedMap; | import org.eclipse.collections.impl.map.mutable.UnifiedMap; | ||||||
| import org.eclipse.collections.impl.tuple.Tuples; | import org.eclipse.collections.impl.tuple.Tuples; | ||||||
| import static org.junit.Assert.assertEquals; |  | ||||||
| 
 |  | ||||||
| import java.util.Map; |  | ||||||
| 
 |  | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| public class ForEachPatternTest { | public class ForEachPatternTest { | ||||||
|  | |||||||
| @ -1,10 +1,9 @@ | |||||||
| package com.baeldung.eclipsecollections; | package com.baeldung.eclipsecollections; | ||||||
| 
 | 
 | ||||||
|  | import org.assertj.core.api.Assertions; | ||||||
| import org.eclipse.collections.api.LazyIterable; | import org.eclipse.collections.api.LazyIterable; | ||||||
| import org.eclipse.collections.api.list.MutableList; | import org.eclipse.collections.api.list.MutableList; | ||||||
| import org.eclipse.collections.impl.block.factory.Predicates; |  | ||||||
| import org.eclipse.collections.impl.factory.Lists; | import org.eclipse.collections.impl.factory.Lists; | ||||||
| import static org.junit.Assert.assertTrue; |  | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| public class LazyIterationTest { | public class LazyIterationTest { | ||||||
| @ -19,8 +18,7 @@ public class LazyIterationTest { | |||||||
|         LazyIterable<Student> lazyStudents = students.asLazy(); |         LazyIterable<Student> lazyStudents = students.asLazy(); | ||||||
|         LazyIterable<String> lastNames = lazyStudents.collect(Student::getLastName); |         LazyIterable<String> lastNames = lazyStudents.collect(Student::getLastName); | ||||||
| 
 | 
 | ||||||
|         assertTrue(lastNames.anySatisfy(Predicates.equal("Hopkins"))); |         Assertions.assertThat(lastNames) | ||||||
|         assertTrue(lastNames.anySatisfy(Predicates.equal("Adams"))); |             .containsAll(Lists.mutable.with("Hopkins", "Adams", "Rodriguez")); | ||||||
|         assertTrue(lastNames.anySatisfy(Predicates.equal("Rodriguez"))); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,12 +1,9 @@ | |||||||
| package com.baeldung.eclipsecollections; | package com.baeldung.eclipsecollections; | ||||||
| 
 | 
 | ||||||
| import static org.junit.Assert.assertEquals; | import org.assertj.core.api.Assertions; | ||||||
| import static org.junit.Assert.assertTrue; |  | ||||||
| 
 |  | ||||||
| import org.eclipse.collections.api.block.predicate.Predicate; | import org.eclipse.collections.api.block.predicate.Predicate; | ||||||
| import org.eclipse.collections.api.list.MutableList; | import org.eclipse.collections.api.list.MutableList; | ||||||
| import org.eclipse.collections.api.partition.list.PartitionMutableList; | 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.eclipse.collections.impl.list.mutable.FastList; | ||||||
| import org.junit.Before; | import org.junit.Before; | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| @ -17,15 +14,7 @@ public class PartitionPatternTest { | |||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void getList() { |     public void getList() { | ||||||
|         this.list = new FastList<>(); |         this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); | ||||||
|         list.add(1); |  | ||||||
|         list.add(8); |  | ||||||
|         list.add(5); |  | ||||||
|         list.add(41); |  | ||||||
|         list.add(31); |  | ||||||
|         list.add(17); |  | ||||||
|         list.add(23); |  | ||||||
|         list.add(38); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
| @ -47,14 +36,9 @@ public class PartitionPatternTest { | |||||||
|         MutableList<Integer> smallerThanThirty = partitionedFolks.getRejected() |         MutableList<Integer> smallerThanThirty = partitionedFolks.getRejected() | ||||||
|             .sortThis(); |             .sortThis(); | ||||||
| 
 | 
 | ||||||
|         assertEquals(1, (int) smallerThanThirty.getFirst()); |         Assertions.assertThat(smallerThanThirty) | ||||||
|         assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(5))); |             .containsExactly(1, 5, 8, 17, 23); | ||||||
|         assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(8))); |         Assertions.assertThat(greaterThanThirty) | ||||||
|         assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(17))); |             .containsExactly(31, 38, 41); | ||||||
|         assertTrue(smallerThanThirty.anySatisfy(Predicates.equal(23))); |  | ||||||
| 
 |  | ||||||
|         assertTrue(greaterThanThirty.anySatisfy(Predicates.equal(31))); |  | ||||||
|         assertTrue(greaterThanThirty.anySatisfy(Predicates.equal(38))); |  | ||||||
|         assertTrue(greaterThanThirty.anySatisfy(Predicates.equal(41))); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,27 +1,21 @@ | |||||||
| package com.baeldung.eclipsecollections; | package com.baeldung.eclipsecollections; | ||||||
| 
 | 
 | ||||||
|  | import org.assertj.core.api.Assertions; | ||||||
| import org.eclipse.collections.api.list.MutableList; | import org.eclipse.collections.api.list.MutableList; | ||||||
| import org.eclipse.collections.impl.block.factory.Predicates; | import org.eclipse.collections.impl.block.factory.Predicates; | ||||||
| import org.eclipse.collections.impl.list.mutable.FastList; | import org.eclipse.collections.impl.list.mutable.FastList; | ||||||
| import static org.junit.Assert.assertEquals; |  | ||||||
| import org.junit.Before; | import org.junit.Before; | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| public class RejectPatternTest { | public class RejectPatternTest { | ||||||
| 
 | 
 | ||||||
|     MutableList<Integer> list; |     MutableList<Integer> list; | ||||||
|  |     MutableList<Integer> expectedList; | ||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void getList() { |     public void setup() { | ||||||
|         this.list = new FastList<>(); |         this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); | ||||||
|         list.add(1); |         this.expectedList = FastList.newListWith(1, 5, 8, 17, 23); | ||||||
|         list.add(8); |  | ||||||
|         list.add(5); |  | ||||||
|         list.add(41); |  | ||||||
|         list.add(31); |  | ||||||
|         list.add(17); |  | ||||||
|         list.add(23); |  | ||||||
|         list.add(38); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
| @ -29,10 +23,7 @@ public class RejectPatternTest { | |||||||
|         MutableList<Integer> notGreaterThanThirty = list.reject(Predicates.greaterThan(30)) |         MutableList<Integer> notGreaterThanThirty = list.reject(Predicates.greaterThan(30)) | ||||||
|             .sortThis(); |             .sortThis(); | ||||||
| 
 | 
 | ||||||
|         assertEquals(1, (int) notGreaterThanThirty.getFirst()); |         Assertions.assertThat(notGreaterThanThirty) | ||||||
|         assertEquals(5, (int) notGreaterThanThirty.get(1)); |             .containsExactlyElementsOf(this.expectedList); | ||||||
|         assertEquals(8, (int) notGreaterThanThirty.get(2)); |  | ||||||
|         assertEquals(17, (int) notGreaterThanThirty.get(3)); |  | ||||||
|         assertEquals(23, (int) notGreaterThanThirty.getLast()); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,9 +1,9 @@ | |||||||
| package com.baeldung.eclipsecollections; | package com.baeldung.eclipsecollections; | ||||||
| 
 | 
 | ||||||
|  | import org.assertj.core.api.Assertions; | ||||||
| import org.eclipse.collections.api.list.MutableList; | import org.eclipse.collections.api.list.MutableList; | ||||||
| import org.eclipse.collections.impl.block.factory.Predicates; | import org.eclipse.collections.impl.block.factory.Predicates; | ||||||
| import org.eclipse.collections.impl.list.mutable.FastList; | import org.eclipse.collections.impl.list.mutable.FastList; | ||||||
| import static org.junit.Assert.assertEquals; |  | ||||||
| import org.junit.Before; | import org.junit.Before; | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| @ -13,15 +13,7 @@ public class SelectPatternTest { | |||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void getList() { |     public void getList() { | ||||||
|         this.list = new FastList<>(); |         this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38); | ||||||
|         list.add(1); |  | ||||||
|         list.add(8); |  | ||||||
|         list.add(5); |  | ||||||
|         list.add(41); |  | ||||||
|         list.add(31); |  | ||||||
|         list.add(17); |  | ||||||
|         list.add(23); |  | ||||||
|         list.add(38); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
| @ -29,9 +21,8 @@ public class SelectPatternTest { | |||||||
|         MutableList<Integer> greaterThanThirty = list.select(Predicates.greaterThan(30)) |         MutableList<Integer> greaterThanThirty = list.select(Predicates.greaterThan(30)) | ||||||
|             .sortThis(); |             .sortThis(); | ||||||
| 
 | 
 | ||||||
|         assertEquals(31, (int) greaterThanThirty.getFirst()); |         Assertions.assertThat(greaterThanThirty) | ||||||
|         assertEquals(38, (int) greaterThanThirty.get(1)); |             .containsExactly(31, 38, 41); | ||||||
|         assertEquals(41, (int) greaterThanThirty.getLast()); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @SuppressWarnings("rawtypes") |     @SuppressWarnings("rawtypes") | ||||||
| @ -45,8 +36,7 @@ public class SelectPatternTest { | |||||||
|     public void givenListwhenSelectUsingLambda_thenCorrect() { |     public void givenListwhenSelectUsingLambda_thenCorrect() { | ||||||
|         MutableList<Integer> greaterThanThirty = selectUsingLambda(); |         MutableList<Integer> greaterThanThirty = selectUsingLambda(); | ||||||
| 
 | 
 | ||||||
|         assertEquals(31, (int) greaterThanThirty.getFirst()); |         Assertions.assertThat(greaterThanThirty) | ||||||
|         assertEquals(38, (int) greaterThanThirty.get(1)); |             .containsExactly(31, 38, 41); | ||||||
|         assertEquals(41, (int) greaterThanThirty.getLast()); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -4,19 +4,31 @@ import org.eclipse.collections.api.list.MutableList; | |||||||
| import org.eclipse.collections.api.tuple.Pair; | import org.eclipse.collections.api.tuple.Pair; | ||||||
| import org.eclipse.collections.impl.factory.Lists; | import org.eclipse.collections.impl.factory.Lists; | ||||||
| import org.eclipse.collections.impl.tuple.Tuples; | 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; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| public class ZipTest { | public class ZipTest { | ||||||
| 
 | 
 | ||||||
|  |     MutableList<Pair<String, String>> expectedPairs; | ||||||
|  | 
 | ||||||
|  |     @SuppressWarnings("unchecked") | ||||||
|  |     @Before | ||||||
|  |     public void setup() { | ||||||
|  |         Pair<String, String> pair1 = Tuples.pair("1", "Porsche"); | ||||||
|  |         Pair<String, String> pair2 = Tuples.pair("2", "Volvo"); | ||||||
|  |         Pair<String, String> pair3 = Tuples.pair("3", "Toyota"); | ||||||
|  |         expectedPairs = Lists.mutable.of(pair1, pair2, pair3); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenZip_thenCorrect() { |     public void whenZip_thenCorrect() { | ||||||
|         MutableList<String> numbers = Lists.mutable.with("1", "2", "3", "Ignored"); |         MutableList<String> numbers = Lists.mutable.with("1", "2", "3", "Ignored"); | ||||||
|         MutableList<String> cars = Lists.mutable.with("Porsche", "Volvo", "Toyota"); |         MutableList<String> cars = Lists.mutable.with("Porsche", "Volvo", "Toyota"); | ||||||
|         MutableList<Pair<String, String>> pairs = numbers.zip(cars); |         MutableList<Pair<String, String>> pairs = numbers.zip(cars); | ||||||
| 
 | 
 | ||||||
|         assertEquals(Tuples.pair("1", "Porsche"), pairs.get(0)); |         Assertions.assertThat(pairs) | ||||||
|         assertEquals(Tuples.pair("2", "Volvo"), pairs.get(1)); |             .containsExactlyElementsOf(this.expectedPairs); | ||||||
|         assertEquals(Tuples.pair("3", "Toyota"), pairs.get(2)); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,22 +1,33 @@ | |||||||
| package com.baeldung.eclipsecollections; | 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.list.MutableList; | ||||||
| import org.eclipse.collections.api.tuple.Pair; | 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.list.mutable.FastList; | ||||||
| import org.eclipse.collections.impl.tuple.Tuples; | import org.eclipse.collections.impl.tuple.Tuples; | ||||||
|  | import org.junit.Before; | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| public class ZipWithIndexTest { | public class ZipWithIndexTest { | ||||||
| 
 | 
 | ||||||
|  |     MutableList<Pair<String, Integer>> expectedPairs; | ||||||
|  | 
 | ||||||
|  |     @SuppressWarnings("unchecked") | ||||||
|  |     @Before | ||||||
|  |     public void setup() { | ||||||
|  |         Pair<String, Integer> pair1 = Tuples.pair("Porsche", 0); | ||||||
|  |         Pair<String, Integer> pair2 = Tuples.pair("Volvo", 1); | ||||||
|  |         Pair<String, Integer> pair3 = Tuples.pair("Toyota", 2); | ||||||
|  |         expectedPairs = Lists.mutable.of(pair1, pair2, pair3); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenZip_thenCorrect() { |     public void whenZip_thenCorrect() { | ||||||
|         MutableList<String> cars = FastList.newListWith("Porsche", "Volvo", "Toyota"); |         MutableList<String> cars = FastList.newListWith("Porsche", "Volvo", "Toyota"); | ||||||
|         MutableList<Pair<String, Integer>> pairs = cars.zipWithIndex(); |         MutableList<Pair<String, Integer>> pairs = cars.zipWithIndex(); | ||||||
| 
 | 
 | ||||||
|         assertEquals(Tuples.pair("Porsche", 0), pairs.get(0)); |         Assertions.assertThat(pairs) | ||||||
|         assertEquals(Tuples.pair("Volvo", 1), pairs.get(1)); |             .containsExactlyElementsOf(this.expectedPairs); | ||||||
|         assertEquals(Tuples.pair("Toyota", 2), pairs.get(2)); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user