-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added more overloaded methods with an varargs Emoji parameter.
- All operations now also take non "fully-qualified" emojis into account.
- Loading branch information
Showing
3 changed files
with
113 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 27 additions & 24 deletions
51
lib/src/test/java/net/fellbaum/jemoji/EmojiManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,104 @@ | ||
package net.fellbaum.jemoji; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class EmojiManagerTest { | ||
|
||
public static final String ALL_EMOJIS_STRING = EmojiManager.getAllEmojisLengthDescending().stream().map(Emoji::getEmoji).collect(Collectors.joining()); | ||
private static final String SIMPLE_EMOJI_STRING = "Hello ❤️ World"; | ||
private static final String SIMPLE_EMOJI_STRING = "Hello ❤️ ❤ ❤❤️ World"; | ||
|
||
@Test | ||
public void extractEmojisInOrder() { | ||
List<Emoji> emojis = EmojiManager.extractEmojisInOrder(ALL_EMOJIS_STRING + ALL_EMOJIS_STRING); | ||
|
||
Assert.assertEquals(EmojiManager.getAllEmojisLengthDescending().size() * 2, emojis.size()); | ||
assertEquals(EmojiManager.getAllEmojisLengthDescending().size() * 2, emojis.size()); | ||
|
||
List<Emoji> allEmojis = new ArrayList<>(EmojiManager.getAllEmojisLengthDescending()); | ||
allEmojis.addAll(EmojiManager.getAllEmojisLengthDescending()); | ||
Assert.assertEquals(allEmojis, emojis); | ||
assertEquals(allEmojis, emojis); | ||
} | ||
|
||
@Test | ||
public void extractEmojis() { | ||
Set<Emoji> emojis = EmojiManager.extractEmojis(ALL_EMOJIS_STRING + ALL_EMOJIS_STRING); | ||
|
||
Assert.assertEquals(EmojiManager.getAllEmojisLengthDescending().size(), emojis.size()); | ||
assertEquals(EmojiManager.getAllEmojisLengthDescending().size(), emojis.size()); | ||
Set<Emoji> allEmojis = EmojiManager.getAllEmojis(); | ||
Assert.assertEquals(allEmojis, emojis); | ||
assertEquals(allEmojis, emojis); | ||
} | ||
|
||
@Test | ||
public void getEmoji() { | ||
String emojiString = "👍"; | ||
|
||
Optional<Emoji> emoji = EmojiManager.getEmoji(emojiString); | ||
Assert.assertTrue(emoji.isPresent()); | ||
Assert.assertEquals(emojiString, emoji.get().getEmoji()); | ||
assertTrue(emoji.isPresent()); | ||
assertEquals(emojiString, emoji.orElseThrow(RuntimeException::new).getEmoji()); | ||
} | ||
|
||
@Test | ||
public void isEmoji() { | ||
String emojiString = "\uD83D\uDC4D"; | ||
|
||
Assert.assertTrue(EmojiManager.isEmoji(emojiString)); | ||
assertTrue(EmojiManager.isEmoji(emojiString)); | ||
} | ||
|
||
@Test | ||
public void getByAlias() { | ||
String alias = "smile"; | ||
|
||
Optional<Emoji> emoji = EmojiManager.getByAlias(alias); | ||
Assert.assertTrue(emoji.isPresent()); | ||
Assert.assertEquals("😄", emoji.get().getEmoji()); | ||
assertTrue(emoji.isPresent()); | ||
assertEquals("😄", emoji.orElseThrow(RuntimeException::new).getEmoji()); | ||
} | ||
|
||
@Test | ||
public void getByAliasWithColon() { | ||
String alias = ":smile:"; | ||
|
||
Optional<Emoji> emoji = EmojiManager.getByAlias(alias); | ||
Assert.assertTrue(emoji.isPresent()); | ||
Assert.assertEquals("😄", emoji.get().getEmoji()); | ||
assertTrue(emoji.isPresent()); | ||
assertEquals("😄", emoji.orElseThrow(RuntimeException::new).getEmoji()); | ||
} | ||
|
||
@Test | ||
public void containsEmoji() { | ||
Assert.assertTrue(EmojiManager.containsEmoji(SIMPLE_EMOJI_STRING)); | ||
assertTrue(EmojiManager.containsEmoji(SIMPLE_EMOJI_STRING)); | ||
} | ||
|
||
@Test | ||
public void removeEmojis() { | ||
Assert.assertEquals("Hello World", EmojiManager.removeAllEmojis(SIMPLE_EMOJI_STRING)); | ||
assertEquals("Hello World", EmojiManager.removeAllEmojis(SIMPLE_EMOJI_STRING)); | ||
} | ||
|
||
@Test | ||
public void removeAllEmojisExcept() { | ||
Assert.assertEquals("Hello ❤️ World", EmojiManager.removeAllEmojisExcept(SIMPLE_EMOJI_STRING + "👍", Collections.singletonList(EmojiManager.getEmoji("❤️").get()))); | ||
assertEquals("Hello ❤️ ❤️ World", EmojiManager.removeAllEmojisExcept(SIMPLE_EMOJI_STRING + "👍", EmojiManager.getEmoji("❤️").orElseThrow(RuntimeException::new))); | ||
} | ||
|
||
@Test | ||
public void replaceEmojis() { | ||
Assert.assertEquals("Hello :heart: World", EmojiManager.replaceEmojis(SIMPLE_EMOJI_STRING, ":heart:", Collections.singletonList(EmojiManager.getEmoji("❤️").get()))); | ||
assertEquals("Hello :heart: ❤ ❤:heart: World", EmojiManager.replaceEmojis(SIMPLE_EMOJI_STRING, ":heart:", EmojiManager.getEmoji("❤️").orElseThrow(RuntimeException::new))); | ||
} | ||
|
||
@Test | ||
public void replaceOnlyUnqualifiedEmoji() { | ||
assertEquals("Hello ❤️ :heart: :heart:❤️ World", EmojiManager.replaceEmojis(SIMPLE_EMOJI_STRING, ":heart:", EmojiManager.getEmoji("❤").orElseThrow(RuntimeException::new))); | ||
} | ||
|
||
@Test | ||
public void replaceAllEmojis() { | ||
Assert.assertEquals("Hello something World something something something", EmojiManager.replaceAllEmojis(SIMPLE_EMOJI_STRING + " 👍 👨🏿🦱 😊", "something")); | ||
assertEquals("Hello something something somethingsomething World something something something", EmojiManager.replaceAllEmojis(SIMPLE_EMOJI_STRING + " 👍 👨🏿🦱 😊", "something")); | ||
} | ||
|
||
@Test | ||
public void replaceAllEmojisFunction() { | ||
Assert.assertEquals("Hello SMILEYS_AND_EMOTION World PEOPLE_AND_BODY PEOPLE_AND_BODY SMILEYS_AND_EMOTION", EmojiManager.replaceAllEmojis(SIMPLE_EMOJI_STRING + " 👍 👨🏿🦱 😊", emoji -> emoji.getGroup().toString())); | ||
assertEquals("Hello SMILEYS_AND_EMOTION SMILEYS_AND_EMOTION SMILEYS_AND_EMOTIONSMILEYS_AND_EMOTION World PEOPLE_AND_BODY PEOPLE_AND_BODY SMILEYS_AND_EMOTION", EmojiManager.replaceAllEmojis(SIMPLE_EMOJI_STRING + " 👍 👨🏿🦱 😊", emoji -> emoji.getGroup().toString())); | ||
} | ||
|
||
} |