ListItemView extends FrameLayout { public void setVariant(@ListItemVariant int variant) { this.variant = variant; @LayoutRes int layout = getLayoutFromVariant(variant); removeAllViews(); LayoutInflater inflater = LayoutInflater.from(getContext()); inflater.inflate(layout, this); findChildViews(); setTexts(); setDrawables(); } ListItemView(Context context);  ListItemView(Context context, AttributeSet attrs);  ListItemView(Context context, AttributeSet attrs, int defStyleAttr); @TargetApi(21)  ListItemView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes); @ListItemVariant int getVariant(); void setVariant(@ListItemVariant int variant); CharSequence getPrimaryText(); void setPrimaryText(@StringRes int textRes); void setPrimaryText(CharSequence text); @Nullable CharSequence getSecondaryText(); void setSecondaryText(@StringRes int textRes); void setSecondaryText(CharSequence text); @Nullable CharSequence getTertiaryText(); void setTertiaryText(@StringRes int textRes); void setTertiaryText(CharSequence text); @Nullable Drawable getIcon(); void setIcon(@DrawableRes int iconRes); void setIcon(Drawable icon); @Nullable Drawable getAvatar(); void setAvatar(@DrawableRes int avatarRes); void setAvatar(Drawable avatar); static final int VARIANT_ONE_LINE_TEXT; static final int VARIANT_ONE_LINE_TEXT_ICON; static final int VARIANT_ONE_LINE_TEXT_AVATAR; static final int VARIANT_ONE_LINE_TEXT_ICON_AVATAR; static final int VARIANT_TWO_LINE_TEXT; static final int VARIANT_TWO_LINE_TEXT_ICON; static final int VARIANT_TWO_LINE_TEXT_AVATAR; static final int VARIANT_TWO_LINE_TEXT_ICON_AVATAR; static final int VARIANT_THREE_LINE_TEXT; static final int VARIANT_THREE_LINE_TEXT_ICON; static final int VARIANT_THREE_LINE_TEXT_AVATAR; static final int VARIANT_THREE_LINE_TEXT_ICON_AVATAR; }
@Test public void givenOneLineText_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_ONE_LINE_TEXT); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_ONE_LINE_TEXT) .doesNotHaveSecondaryTextView() .doesNotHaveTertiaryTextView() .doesNotHaveIconView() .doesNotHaveAvatarView(); }
@Test public void givenThreeLineTextAvatar_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_THREE_LINE_TEXT_AVATAR); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_THREE_LINE_TEXT_AVATAR) .hasSecondaryTextView() .hasTertiaryTextView() .hasAvatarView() .doesNotHaveIconView(); }
@Test public void givenThreeLineTextIconAndAvatar_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_THREE_LINE_TEXT_ICON_AVATAR); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_THREE_LINE_TEXT_ICON_AVATAR) .hasSecondaryTextView() .hasTertiaryTextView() .hasIconView() .hasAvatarView(); }
@Test @SuppressWarnings("WrongConstant") public void givenInvalidVariant_whenSetVariant_thenHasDefaultVariant() { listItemView.setVariant(10000); assertThat(listItemView) .doesNotHaveSecondaryTextView() .doesNotHaveTertiaryTextView() .doesNotHaveIconView() .doesNotHaveAvatarView(); }
@Test public void givenOneLineTextIcon_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_ONE_LINE_TEXT_ICON); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_ONE_LINE_TEXT_ICON) .hasIconView() .doesNotHaveSecondaryTextView() .doesNotHaveTertiaryTextView() .doesNotHaveAvatarView(); }
@Test public void givenOneLineTextAvatar_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_ONE_LINE_TEXT_AVATAR); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_ONE_LINE_TEXT_AVATAR) .hasAvatarView() .doesNotHaveSecondaryTextView() .doesNotHaveTertiaryTextView() .doesNotHaveIconView(); }
@Test public void givenOneLineTextIconAndAvatar_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_ONE_LINE_TEXT_ICON_AVATAR); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_ONE_LINE_TEXT_ICON_AVATAR) .hasIconView() .hasAvatarView() .doesNotHaveSecondaryTextView() .doesNotHaveTertiaryTextView(); }
@Test public void givenTwoLineText_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_TWO_LINE_TEXT); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_TWO_LINE_TEXT) .hasSecondaryTextView() .doesNotHaveTertiaryTextView() .doesNotHaveIconView() .doesNotHaveAvatarView(); }
@Test public void givenTwoLineTextIcon_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_TWO_LINE_TEXT_ICON); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_TWO_LINE_TEXT_ICON) .hasSecondaryTextView() .hasIconView() .doesNotHaveTertiaryTextView() .doesNotHaveAvatarView(); }
@Test public void givenTwoLineTextAvatar_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_TWO_LINE_TEXT_AVATAR); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_TWO_LINE_TEXT_AVATAR) .hasSecondaryTextView() .hasAvatarView() .doesNotHaveTertiaryTextView() .doesNotHaveIconView(); }
@Test public void givenTwoLineTextIconAndAvatar_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_TWO_LINE_TEXT_ICON_AVATAR); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_TWO_LINE_TEXT_ICON_AVATAR) .hasSecondaryTextView() .hasIconView() .hasAvatarView() .doesNotHaveTertiaryTextView(); }
@Test public void givenThreeLineText_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_THREE_LINE_TEXT); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_THREE_LINE_TEXT) .hasSecondaryTextView() .hasTertiaryTextView() .doesNotHaveIconView() .doesNotHaveAvatarView(); }
@Test public void givenThreeLineTextIcon_whenSetVariant_thenVariantChanged() { listItemView.setVariant(ListItemView.VARIANT_THREE_LINE_TEXT_ICON); assertThat(listItemView) .hasVariant(ListItemView.VARIANT_THREE_LINE_TEXT_ICON) .hasSecondaryTextView() .hasTertiaryTextView() .hasIconView() .doesNotHaveAvatarView(); }