|
| 1 | +package com.baeldung.eclipsecollections; |
| 2 | + |
| 3 | +import org.eclipse.collections.api.list.MutableList; |
| 4 | +import org.eclipse.collections.impl.list.mutable.FastList; |
| 5 | +import static org.junit.Assert.assertEquals; |
| 6 | +import org.junit.Before; |
| 7 | +import org.junit.Test; |
| 8 | + |
| 9 | +public class FlatCollectTest { |
| 10 | + |
| 11 | + MutableList<String> addresses1; |
| 12 | + MutableList<String> addresses2; |
| 13 | + MutableList<String> addresses3; |
| 14 | + MutableList<String> addresses4; |
| 15 | + |
| 16 | + MutableList<Student> students; |
| 17 | + |
| 18 | + @Before |
| 19 | + public void setup() { |
| 20 | + String address1 = "73 Pacific St., Forest Hills, NY 11375"; |
| 21 | + String address2 = "93 Bayport Ave., South Richmond Hill, NY 11419"; |
| 22 | + String address3 = "548 Market St, San Francisco, CA 94104"; |
| 23 | + String address4 = "8605 Santa Monica Blvd, West Hollywood, CA 90069"; |
| 24 | + |
| 25 | + this.addresses1 = FastList.newListWith(address1, address2); |
| 26 | + this.addresses2 = FastList.newListWith(address3, address4); |
| 27 | + Student student1 = new Student("John", "Hopkins", addresses1); |
| 28 | + Student student2 = new Student("George", "Adams", addresses2); |
| 29 | + this.addresses2 = FastList.newListWith(address3, address4); |
| 30 | + this.students = FastList.newListWith(student1, student2); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void whenFlatCollect_thenCorrect() { |
| 35 | + MutableList<String> addresses = students.flatCollect(Student::getAddresses); |
| 36 | + |
| 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)); |
| 41 | + } |
| 42 | +} |
0 commit comments