PasswordEditText extends AppCompatEditText { public void togglePasswordVisibility() { setPasswordVisible(!passwordVisible); } PasswordEditText(Context context);  PasswordEditText(Context context, AttributeSet attrs);  PasswordEditText(Context context, AttributeSet attrs, int defStyleAttr); @Override void setInputType(int type); @Override boolean onTouchEvent(MotionEvent event); boolean isPasswordVisible(); void setPasswordVisible(boolean visible); void togglePasswordVisibility(); @ColorInt int getTintColor(); void setTintColor(@ColorInt int tintColor); void setTintColorRes(@ColorRes int tintColorRes); void setShownDrawable(Drawable shownDrawable); void setShownDrawable(@DrawableRes int shownDrawableRes); void setHiddenDrawable(Drawable hiddenDrawable); void setHiddenDrawable(@DrawableRes int hiddenDrawableRes); void setToggleType(@ToggleType int toggleType); static final int TOGGLE_OPACITY; static final int TOGGLE_STRIKETHROUGH; }
@Test public void givenCustomIconsInAttrs_whenCreatedAndVisibilityToggled_thenHasCustomShownIcon() { AttributeSet attrs = createCustomIconsAttributeSet(); PasswordEditText actual = new PasswordEditText(RuntimeEnvironment.application, attrs, 0); actual.togglePasswordVisibility(); assertThat(actual).hasToggle(R.drawable.ic_icon_square); }
@Test public void givenStrikeThroughTypeInAttrs_whenCreatedAndVisibilityToggled_thenHasDefaultToggle() { AttributeSet attrs = createStrikeThroughAttributeSet(); PasswordEditText actual = new PasswordEditText(RuntimeEnvironment.application, attrs, 0); actual.togglePasswordVisibility(); assertThat(actual) .hasDefaultToggle() .hasToggleShownAlpha(); }