Review Comments

This commit is contained in:
Niket Agrawal 2023-11-26 23:51:38 +05:30
parent 39f5de4e30
commit 7b83abb7ae
1 changed files with 11 additions and 3 deletions

View File

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