2017-08-10 16:58:22 +03:00
|
|
|
package com.baeldung.eclipsecollections;
|
|
|
|
|
|
|
|
import org.eclipse.collections.api.list.MutableList;
|
|
|
|
import org.eclipse.collections.impl.list.mutable.FastList;
|
2017-08-12 18:42:04 +02:00
|
|
|
|
|
|
|
import org.assertj.core.api.Assertions;
|
2017-08-10 16:58:22 +03:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
public class CollectPatternTest {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void whenCollect_thenCorrect() {
|
|
|
|
Student student1 = new Student("John", "Hopkins");
|
|
|
|
Student student2 = new Student("George", "Adams");
|
|
|
|
|
|
|
|
MutableList<Student> students = FastList.newListWith(student1, student2);
|
|
|
|
|
|
|
|
MutableList<String> lastNames = students.collect(Student::getLastName);
|
|
|
|
|
2017-08-12 18:42:04 +02:00
|
|
|
Assertions.assertThat(lastNames)
|
|
|
|
.containsExactly("Hopkins", "Adams");
|
2017-08-10 16:58:22 +03:00
|
|
|
}
|
|
|
|
}
|