### Question:
EmojiTextWatcher implements android.text.TextWatcher { @Override public void onTextChanged(CharSequence charSequence, final int start, final int before, final int after) { if (mEditText.isInEditMode()) { return; } if (before <= after && charSequence instanceof Spannable) { switch (EmojiCompat.get().getLoadState()){ case EmojiCompat.LOAD_STATE_SUCCEEDED: final Spannable s = (Spannable) charSequence; EmojiCompat.get().process(s, start, start + after, mMaxEmojiCount, mEmojiReplaceStrategy); break; case EmojiCompat.LOAD_STATE_LOADING: case EmojiCompat.LOAD_STATE_DEFAULT: EmojiCompat.get().registerInitCallback(getInitCallback()); break; case EmojiCompat.LOAD_STATE_FAILED: default: break; } } } EmojiTextWatcher(EditText editText); @Override void onTextChanged(CharSequence charSequence, final int start, final int before,
            final int after); @Override void beforeTextChanged(CharSequence s, int start, int count, int after); @Override void afterTextChanged(Editable s);  }### Answer:
@Test public void testOnTextChanged_callsProcess() { final Spannable testString = new SpannableString("abc"); when(mEmojiCompat.getLoadState()).thenReturn(EmojiCompat.LOAD_STATE_SUCCEEDED); mTextWatcher.onTextChanged(testString, 0, 0, 1); verify(mEmojiCompat, times(1)).process(sameCharSequence(testString), eq(0), eq(1), eq(Integer.MAX_VALUE), anyInt()); verify(mEmojiCompat, times(0)).registerInitCallback(any(EmojiCompat.InitCallback.class)); }
@Test public void testOnTextChanged_whenEmojiCompatLoading() { final Spannable testString = new SpannableString("abc"); when(mEmojiCompat.getLoadState()).thenReturn(EmojiCompat.LOAD_STATE_LOADING); mTextWatcher.onTextChanged(testString, 0, 0, 1); verify(mEmojiCompat, times(0)).process(any(Spannable.class), anyInt(), anyInt(), anyInt(), anyInt()); verify(mEmojiCompat, times(1)).registerInitCallback(any(EmojiCompat.InitCallback.class)); }
@Test public void testOnTextChanged_whenEmojiCompatLoadFailed() { final Spannable testString = new SpannableString("abc"); when(mEmojiCompat.getLoadState()).thenReturn(EmojiCompat.LOAD_STATE_FAILED); mTextWatcher.onTextChanged(testString, 0, 0, 1); verify(mEmojiCompat, times(0)).process(any(Spannable.class), anyInt(), anyInt(), anyInt(), anyInt()); verify(mEmojiCompat, times(0)).registerInitCallback(any(EmojiCompat.InitCallback.class)); }
@Test public void testFilter_withManualLoadStrategy() { final Spannable testString = new SpannableString("abc"); when(mEmojiCompat.getLoadState()).thenReturn(EmojiCompat.LOAD_STATE_DEFAULT); mTextWatcher.onTextChanged(testString, 0, 0, 1); verify(mEmojiCompat, times(0)).process(any(Spannable.class), anyInt(), anyInt()); verify(mEmojiCompat, times(1)).registerInitCallback(any(EmojiCompat.InitCallback.class)); }