From 7b83abb7ae45c027906a1df7c71a4cf0607c8649 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Sun, 26 Nov 2023 23:51:38 +0530 Subject: [PATCH] Review Comments --- .../FirstMatchingElementUnitTest.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/streams/firstmatchingelement/FirstMatchingElementUnitTest.java b/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/streams/firstmatchingelement/FirstMatchingElementUnitTest.java index da4522d097..db9415e94b 100644 --- a/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/streams/firstmatchingelement/FirstMatchingElementUnitTest.java +++ b/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/streams/firstmatchingelement/FirstMatchingElementUnitTest.java @@ -44,12 +44,20 @@ public class FirstMatchingElementUnitTest { @Test public void whenUsingTakeWhile_thenFindFirstMatchingUserIndex() { long predicateIndex = userList.stream() - .takeWhile(user -> !user.getUserName() - .equals(searchName)) + .takeWhile(user -> !user.getUserName().equals(searchName)) .count(); assertEquals(1, predicateIndex); } - + + @Test + public void whenUsingTakeWhile_thenFindIndexFromNoMatchingElement() { + List userList = List.of(new User(1, "David"), new User(2, "Vick"), new User(3, "Roger"), new User(4, "James")); + long predicateIndex = userList.stream() + .takeWhile(user -> !user.getUserName().equals(searchName)) + .count(); + assertEquals(4, predicateIndex); + } + @Test public void whenUsingGoogleGuava_thenFindFirstMatchingUserIndex() { int index = Iterables.indexOf(userList, user -> searchName.equals(user.getUserName()));