Merge pull request #14759 from sam-gardner/BAEL-6811-check-if-letter-is-emoji

BAEL-6811 Check if letter is emoji example code
This commit is contained in:
davidmartinezbarua 2023-09-18 12:35:24 -03:00 committed by GitHub
commit 9d0985112b
2 changed files with 39 additions and 0 deletions

View File

@ -23,6 +23,11 @@
<artifactId>commons-lang3</artifactId>
<version>${apache-commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>com.vdurmont</groupId>
<artifactId>emoji-java</artifactId>
<version>${emoji-java.version}</version>
</dependency>
</dependencies>
<build>
@ -52,6 +57,7 @@
<maven.compiler.target>11</maven.compiler.target>
<validator.version>1.7</validator.version>
<apache-commons-lang3.version>3.12.0</apache-commons-lang3.version>
<emoji-java.version>5.1.1</emoji-java.version>
</properties>
</project>

View File

@ -0,0 +1,33 @@
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;
public class FindEmojisUnitTest {
@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);
}
}