Merge pull request #5154 from Doha2012/master

fix emoji test
This commit is contained in:
Loredana Crusoveanu 2018-09-07 14:40:18 +03:00 committed by GitHub
commit 977c50ad85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 26 deletions

View File

@ -1,8 +1,6 @@
package com.baeldung.string;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertEquals;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -12,35 +10,28 @@ import org.junit.Test;
import com.vdurmont.emoji.EmojiParser;
public class RemovingEmojiFromStringUnitTest {
String text = "la conférence, commencera à 10 heures 😅";
String text = "la conférence, commencera à 10 heures 😅";
String regex = "[^\\p{L}\\p{N}\\p{P}\\p{Z}]";
@Test
public void whenRemoveEmojiUsingLibrary_thenSuccess() {
String result = EmojiParser.removeAllEmojis(text);
System.out.println(result);
assertThat(result, not(containsString("😅")));
assertThat(result, containsString("à"));
assertThat(result, containsString("la"));
assertThat(result, containsString("10"));
assertEquals(result, "la conférence, commencera à 10 heures ");
}
@Test
public void whenReplaceEmojiUsingLibrary_thenSuccess() {
String result = EmojiParser.parseToAliases(text);
System.out.println(result);
assertThat(result, not(containsString("😅")));
assertThat(result, containsString("sweat_smile"));
assertEquals(result, "la conférence, commencera à 10 heures :sweat_smile:");
}
@Test
public void whenRemoveEmojiUsingRegex_thenSuccess() {
String result = text.replaceAll(regex, "");
System.out.println(result);
assertThat(result, not(containsString("😅")));
assertThat(result, containsString("à"));
assertThat(result, containsString("la"));
assertThat(result, containsString("10"));
assertEquals(result, "la conférence, commencera à 10 heures ");
}
@Test
@ -50,29 +41,20 @@ public class RemovingEmojiFromStringUnitTest {
String result = matcher.replaceAll("");
System.out.println(result);
assertThat(result, not(containsString("😅")));
assertThat(result, containsString("à"));
assertThat(result, containsString("la"));
assertThat(result, containsString("10"));
assertEquals(result, "la conférence, commencera à 10 heures ");
}
@Test
public void whenRemoveEmojiUsingCodepoints_thenSuccess() {
String result = text.replaceAll("[\\x{0001f300}-\\x{0001f64f}]|[\\x{0001f680}-\\x{0001f6ff}]", "");
System.out.println(result);
assertThat(result, not(containsString("😅")));
assertThat(result, containsString("à"));
assertThat(result, containsString("la"));
assertThat(result, containsString("10"));
assertEquals(result, "la conférence, commencera à 10 heures ");
}
@Test
public void whenRemoveEmojiUsingUnicode_thenSuccess() {
String result = text.replaceAll("[\ud83c\udf00-\ud83d\ude4f]|[\ud83d\ude80-\ud83d\udeff]", "");
System.out.println(result);
assertThat(result, not(containsString("😅")));
assertThat(result, containsString("à"));
assertThat(result, containsString("la"));
assertThat(result, containsString("10"));
assertEquals(result, "la conférence, commencera à 10 heures ");
}
}