BAEL-6334 Make object properties example clearer

This commit is contained in:
Sam Gardner 2023-05-22 10:35:26 +01:00
parent 8430235bb1
commit 58633573a3
2 changed files with 10 additions and 10 deletions

View File

@ -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;
} }

View File

@ -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);