### Question:
EmojiTransformationMethod implements TransformationMethod { @Override public CharSequence getTransformation(@Nullable CharSequence source, @NonNull final View view) { if (view.isInEditMode()) { return source; } if (mTransformationMethod != null) { source = mTransformationMethod.getTransformation(source, view); } if (source != null) { switch (EmojiCompat.get().getLoadState()){ case EmojiCompat.LOAD_STATE_SUCCEEDED: return EmojiCompat.get().process(source); case EmojiCompat.LOAD_STATE_LOADING: case EmojiCompat.LOAD_STATE_FAILED: case EmojiCompat.LOAD_STATE_DEFAULT: default: break; } } return source; } EmojiTransformationMethod(TransformationMethod transformationMethod); @Override CharSequence getTransformation(@Nullable CharSequence source, @NonNull final View view); @Override void onFocusChanged(final View view, final CharSequence sourceText,
            final boolean focused, final int direction, final Rect previouslyFocusedRect);  }### Answer:
@Test public void testFilter_withNullSource() { assertNull(mTransformationMethod.getTransformation(null, mView)); verify(mEmojiCompat, never()).process(any(CharSequence.class)); }
@Test(expected = NullPointerException.class) public void testFilter_withNullView() { mTransformationMethod.getTransformation("", null); }
@Test public void testFilter_withNullTransformationMethod() { mTransformationMethod = new EmojiTransformationMethod(null); final CharSequence result = mTransformationMethod.getTransformation(mTestString, mView); assertTrue(TextUtils.equals(new SpannableString(mTestString), result)); verify(mEmojiCompat, times(1)).process(sameCharSequence(mTestString)); }
@Test public void testFilter() { final CharSequence result = mTransformationMethod.getTransformation(mTestString, mView); assertTrue(TextUtils.equals(new SpannableString(mTestString), result)); assertTrue(result instanceof Spannable); verify(mWrappedTransformationMethod, times(1)).getTransformation( sameCharSequence(mTestString), same(mView)); verify(mEmojiCompat, times(1)).process(sameCharSequence(mTestString)); verify(mEmojiCompat, never()).registerInitCallback(any(EmojiCompat.InitCallback.class)); }
@Test public void testFilter_whenEmojiCompatLoading() { when(mEmojiCompat.getLoadState()).thenReturn(EmojiCompat.LOAD_STATE_LOADING); final CharSequence result = mTransformationMethod.getTransformation(mTestString, mView); assertSame(mTestString, result); verify(mWrappedTransformationMethod, times(1)).getTransformation( sameCharSequence(mTestString), same(mView)); verify(mEmojiCompat, never()).process(sameCharSequence(mTestString)); verify(mEmojiCompat, never()).registerInitCallback(any(EmojiCompat.InitCallback.class)); }
@Test public void testFilter_whenEmojiCompatLoadFailed() { when(mEmojiCompat.getLoadState()).thenReturn(EmojiCompat.LOAD_STATE_FAILED); final CharSequence result = mTransformationMethod.getTransformation(mTestString, mView); assertSame(mTestString, result); verify(mWrappedTransformationMethod, times(1)).getTransformation( sameCharSequence(mTestString), same(mView)); verify(mEmojiCompat, never()).process(sameCharSequence(mTestString)); verify(mEmojiCompat, never()).registerInitCallback(any(EmojiCompat.InitCallback.class)); }
@Test public void testFilter_withManualLoadStrategy() { when(mEmojiCompat.getLoadState()).thenReturn(EmojiCompat.LOAD_STATE_DEFAULT); final CharSequence result = mTransformationMethod.getTransformation(mTestString, mView); assertSame(mTestString, result); verify(mWrappedTransformationMethod, times(1)).getTransformation( sameCharSequence(mTestString), same(mView)); verify(mEmojiCompat, never()).process(sameCharSequence(mTestString)); verify(mEmojiCompat, never()).registerInitCallback(any(EmojiCompat.InitCallback.class)); }