Code example for TextView

Methods: addTextChangedListenerappendsetText

0
    verify(mockTextWatcher).onTextChanged(new SpannableStringBuilder(INITIAL_TEXT + NEW_TEXT), 0, INITIAL_TEXT.length(), INITIAL_TEXT.length());
  } 
 
  @Test 
  public void whenAppendingText_ShouldFireAfterTextChangedWithCorrectArgument() { 
    textView.setText(INITIAL_TEXT);
    MockTextWatcher mockTextWatcher = new MockTextWatcher();
    textView.addTextChangedListener(mockTextWatcher);
 
    textView.append(NEW_TEXT);
 
    assertThat(mockTextWatcher.afterTextChangeArgument.toString()).isEqualTo(INITIAL_TEXT + NEW_TEXT);
  } 
 
  @Test 
  public void removeTextChangedListener_shouldRemoveTheListener() throws Exception { 
    MockTextWatcher watcher = new MockTextWatcher();
    textView.addTextChangedListener(watcher);
    assertTrue(shadowOf(textView).getWatchers().contains(watcher));
 
    textView.removeTextChangedListener(watcher);