From 58633573a31cf294a6d35c6b96803c31b33efa6e Mon Sep 17 00:00:00 2001 From: Sam Gardner Date: Mon, 22 May 2023 10:35:26 +0100 Subject: [PATCH] BAEL-6334 Make object properties example clearer --- .../main/java/com/baeldung/list/Country.java | 2 +- .../ListContainsElementFromOtherListTest.java | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core-java-modules/core-java-collections-list-5/src/main/java/com/baeldung/list/Country.java b/core-java-modules/core-java-collections-list-5/src/main/java/com/baeldung/list/Country.java index 354aeca2d3..7ca7a4f185 100644 --- a/core-java-modules/core-java-collections-list-5/src/main/java/com/baeldung/list/Country.java +++ b/core-java-modules/core-java-collections-list-5/src/main/java/com/baeldung/list/Country.java @@ -6,6 +6,6 @@ import lombok.Data; public class Country { private final String name; - private final String capital; + private final String language; } diff --git a/core-java-modules/core-java-collections-list-5/src/test/java/com/baeldung/java/list/ListContainsElementFromOtherListTest.java b/core-java-modules/core-java-collections-list-5/src/test/java/com/baeldung/java/list/ListContainsElementFromOtherListTest.java index 0f47f7713a..4ce7c44282 100644 --- a/core-java-modules/core-java-collections-list-5/src/test/java/com/baeldung/java/list/ListContainsElementFromOtherListTest.java +++ b/core-java-modules/core-java-collections-list-5/src/test/java/com/baeldung/java/list/ListContainsElementFromOtherListTest.java @@ -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 franceAndBelgium = Arrays.asList(france, belgium); - List belgiumAndSpain = Arrays.asList(belgium, spain); + Country france = new Country("France", "French"); + Country mexico = new Country("Mexico", "Spanish"); + Country spain = new Country("Spain", "Spanish"); + List franceAndMexico = Arrays.asList(france, mexico); + List 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);