2017-08-15 23:48:47 -03:00
|
|
|
package com.baeldung.distinct;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import one.util.streamex.StreamEx;
|
|
|
|
|
|
|
|
|
|
public class DistinctWithStreamexUnitTest {
|
|
|
|
|
List<Person> personList;
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
public void init() {
|
|
|
|
|
personList = PersonDataGenerator.getPersonListWithFakeValues();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void whenFilterListByName_thenSizeShouldBe4() {
|
2018-03-04 17:39:09 +02:00
|
|
|
List<Person> personListFiltered = StreamEx.of(personList).distinct(Person::getName).toList();
|
2017-08-15 23:48:47 -03:00
|
|
|
assertTrue(personListFiltered.size() == 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void whenFilterListByAge_thenSizeShouldBe2() {
|
2018-03-04 17:39:09 +02:00
|
|
|
List<Person> personListFiltered = StreamEx.of(personList).distinct(Person::getAge).toList();
|
2017-08-15 23:48:47 -03:00
|
|
|
assertTrue(personListFiltered.size() == 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|