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:
Vini 2023-05-22 14:36:10 +02:00 committed by GitHub
commit a54aa7c49b
2 changed files with 10 additions and 10 deletions

View File

@ -6,6 +6,6 @@ import lombok.Data;
public class Country {
private final String name;
private final String capital;
private final String language;
}

View File

@ -50,16 +50,16 @@ public class ListContainsElementFromOtherListTest {
@Test
public void givenPropertiesInObjectsToCompare_whenUsingStreams_thenDetectElementsInTwoLists() {
Country france = new Country("France", "Paris");
Country belgium = new Country("Belgium", "Brussels");
Country spain = new Country("Spain", "Madrid");
List<Country> franceAndBelgium = Arrays.asList(france, belgium);
List<Country> belgiumAndSpain = Arrays.asList(belgium, spain);
Country france = new Country("France", "French");
Country mexico = new Country("Mexico", "Spanish");
Country spain = new Country("Spain", "Spanish");
List<Country> franceAndMexico = Arrays.asList(france, mexico);
List<Country> franceAndSpain = Arrays.asList(france, spain);
boolean shouldBeTrue = franceAndBelgium.stream()
.map(Country::getCapital)
.anyMatch(belgiumAndSpain.stream()
.map(Country::getCapital)
boolean shouldBeTrue = franceAndMexico.stream()
.map(Country::getLanguage)
.anyMatch(franceAndSpain.stream()
.map(Country::getLanguage)
.collect(toSet())::contains);
assertTrue(shouldBeTrue);