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:
parent
c5a3c01108
commit
c8c29a7806
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue