BAEL-6811 Check if letter is emoji example code
This commit is contained in:
parent
ac590b3823
commit
601275a5c9
@ -23,6 +23,16 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${apache-commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.kcthota</groupId>
|
||||
<artifactId>emoji4j</artifactId>
|
||||
<version>6.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vdurmont</groupId>
|
||||
<artifactId>emoji-java</artifactId>
|
||||
<version>5.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.baeldung.findemojis;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.vdurmont.emoji.EmojiManager;
|
||||
|
||||
import emoji4j.EmojiUtils;
|
||||
|
||||
public class FindEmojisUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenAWord_whenUsingEmoji4J_thenDetectEmoji() {
|
||||
boolean emoji = EmojiUtils.isEmoji("\uD83D\uDC3B");
|
||||
assertTrue(emoji);
|
||||
|
||||
boolean notEmoji = EmojiUtils.isEmoji("w");
|
||||
assertFalse(notEmoji);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAWord_whenUsingEmojiJava_thenDetectEmoji() {
|
||||
boolean emoji = EmojiManager.isEmoji("\uD83D\uDC3B");
|
||||
assertTrue(emoji);
|
||||
|
||||
boolean notEmoji = EmojiManager.isEmoji("w");
|
||||
assertFalse(notEmoji);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAWord_whenUsingRegex_thenDetectEmoji() {
|
||||
String regexPattern = "[\uD800-\uDBFF\uDC00-\uDFFF]+";
|
||||
String emojiString = "\uD83D\uDC3B";
|
||||
boolean emoji = emojiString.matches(regexPattern);
|
||||
assertTrue(emoji);
|
||||
|
||||
String notEmojiString = "w";
|
||||
boolean notEmoji = notEmojiString.matches(regexPattern);
|
||||
assertFalse(notEmoji);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user