VariantEmojiManager implements VariantEmoji { @Override public void persist() { if (variantsList.size() > 0) { final StringBuilder stringBuilder = new StringBuilder(variantsList.size() * EMOJI_GUESS_SIZE); for (int i = 0; i < variantsList.size(); i++) { stringBuilder.append(variantsList.get(i).getUnicode()).append(EMOJI_DELIMITER); } stringBuilder.setLength(stringBuilder.length() - EMOJI_DELIMITER.length()); getPreferences().edit().putString(VARIANT_EMOJIS, stringBuilder.toString()).apply(); } else { getPreferences().edit().remove(VARIANT_EMOJIS).apply(); } } VariantEmojiManager(@NonNull final Context context); @Override @NonNull Emoji getVariant(final Emoji desiredEmoji); @Override void addVariant(@NonNull final Emoji newVariant); @Override void persist();  }
@Test public void persist() { variantEmojiManager.addVariant(variant1); variantEmojiManager.addVariant(variant2); variantEmojiManager.persist(); EmojiManager.install(TestEmojiProvider.from(variant1, variant2)); final VariantEmojiManager sharedPrefsManager = new VariantEmojiManager(RuntimeEnvironment.application); assertThat(sharedPrefsManager.getVariant(base)).isEqualTo(variant2); }