This PR is related to BAEL-7556 (#15900)

* This commit is related to BAEL-7556

This commit aims to add a test class "FindUniqueEmailsUnitTest.java".

* Update FindUniqueEmailsUnitTest.java
This commit is contained in:
MohamedHelmyKassab 2024-02-21 10:11:24 +02:00 committed by GitHub
parent c5a3c01108
commit c8c29a7806
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
package com.baeldung.finduniqueemails;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class FindUniqueEmailsUnitTest {
String[] emailList = {"user@example.com", "user@example.com", "user@gmail.com", "admin@example.com", "USER@example.com"};
Set<String> expectedUniqueEmails = new HashSet<>();
FindUniqueEmailsUnitTest() {
expectedUniqueEmails.add("user@example.com");
expectedUniqueEmails.add("user@gmail.com");
expectedUniqueEmails.add("admin@example.com");
}
@Test
public void givenEmailList_whenUsingStringManipulation_thenFindUniqueEmails() {
Set<String> uniqueEmails = new HashSet<>();
for (String email : emailList) {
uniqueEmails.add(email.toLowerCase());
}
assertEquals(expectedUniqueEmails, uniqueEmails);
}
@Test
public void givenEmailList_whenUsingJavaStreams_thenFindUniqueEmails() {
Set<String> uniqueEmails = Arrays.stream(emailList)
.map(String::toLowerCase)
.collect(Collectors.toSet());
assertEquals(expectedUniqueEmails, uniqueEmails);
}
}