Merge pull request #14093 from sam-gardner/BAEL-6334-check-list-element-in-other-list
BAEL-6334 Make object properties example clearer
This commit is contained in:
commit
a54aa7c49b
|
@ -6,6 +6,6 @@ import lombok.Data;
|
||||||
public class Country {
|
public class Country {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String capital;
|
private final String language;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,16 +50,16 @@ public class ListContainsElementFromOtherListTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenPropertiesInObjectsToCompare_whenUsingStreams_thenDetectElementsInTwoLists() {
|
public void givenPropertiesInObjectsToCompare_whenUsingStreams_thenDetectElementsInTwoLists() {
|
||||||
Country france = new Country("France", "Paris");
|
Country france = new Country("France", "French");
|
||||||
Country belgium = new Country("Belgium", "Brussels");
|
Country mexico = new Country("Mexico", "Spanish");
|
||||||
Country spain = new Country("Spain", "Madrid");
|
Country spain = new Country("Spain", "Spanish");
|
||||||
List<Country> franceAndBelgium = Arrays.asList(france, belgium);
|
List<Country> franceAndMexico = Arrays.asList(france, mexico);
|
||||||
List<Country> belgiumAndSpain = Arrays.asList(belgium, spain);
|
List<Country> franceAndSpain = Arrays.asList(france, spain);
|
||||||
|
|
||||||
boolean shouldBeTrue = franceAndBelgium.stream()
|
boolean shouldBeTrue = franceAndMexico.stream()
|
||||||
.map(Country::getCapital)
|
.map(Country::getLanguage)
|
||||||
.anyMatch(belgiumAndSpain.stream()
|
.anyMatch(franceAndSpain.stream()
|
||||||
.map(Country::getCapital)
|
.map(Country::getLanguage)
|
||||||
.collect(toSet())::contains);
|
.collect(toSet())::contains);
|
||||||
|
|
||||||
assertTrue(shouldBeTrue);
|
assertTrue(shouldBeTrue);
|
||||||
|
|
Loading…
Reference in New Issue