From fdca014527b65acbf6fa47f4d6b24d12f53263a9 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Fri, 20 Oct 2023 02:24:07 +0200 Subject: [PATCH] [impr-list-of-lists] The size of list of lists (#15002) --- .../list/listoflists/ListOfListsUnitTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/listoflists/ListOfListsUnitTest.java b/core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/listoflists/ListOfListsUnitTest.java index 321fa475f6..f75ca453ea 100644 --- a/core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/listoflists/ListOfListsUnitTest.java +++ b/core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/listoflists/ListOfListsUnitTest.java @@ -71,4 +71,15 @@ public class ListOfListsUnitTest { assertThat(listOfLists.get(2)).containsExactly("Slack", "Zoom", "Microsoft Teams", "Telegram"); printListOfLists(listOfLists); } -} + + @Test + void givenListOfLists_whenGettingSizeOfSubListsAndSizeOfElements_thenGetExpectedResults() throws URISyntaxException, IOException { + List> listOfLists = getListOfListsFromCsv(); + // size of inner lists + assertThat(listOfLists).hasSize(3); + + // size of all elements in subLists + int totalElements = listOfLists.stream().mapToInt(List::size).sum(); + assertThat(totalElements).isEqualTo(12); + } +} \ No newline at end of file