GridItemView extends FrameLayout { private int getColor(@ColorRes int colorRes) { return ContextCompat.getColor(getContext(), colorRes); } GridItemView(Context context);  GridItemView(Context context, AttributeSet attrs);  GridItemView(Context context, AttributeSet attrs, int defStyleAttr); @TargetApi(21)  GridItemView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes); @GridItemVariant int getVariant(); void setVariant(@GridItemVariant int variant); CharSequence getPrimaryText(); void setPrimaryText(@StringRes int textRes); void setPrimaryText(CharSequence text); ColorStateList getPrimaryTextColors(); @ColorInt int getCurrentPrimaryTextColor(); void setPrimaryTextColor(ColorStateList color); void setPrimaryTextColor(@ColorInt int color); void setPrimaryTextColorRes(@ColorRes int colorRes); CharSequence getSecondaryText(); void setSecondaryText(@StringRes int textRes); void setSecondaryText(CharSequence text); ColorStateList getSecondaryTextColors(); @ColorInt int getCurrentSecondaryTextColor(); void setSecondaryTextColor(ColorStateList color); void setSecondaryTextColor(@ColorInt int color); void setSecondaryTextColorRes(@ColorRes int colorRes); Drawable getIcon(); void setIcon(@DrawableRes int iconRes); void setIcon(Drawable icon); @IconGravity int getIconGravity(); void setIconGravity(@IconGravity int iconGravity); static final int VARIANT_ONE_LINE_TEXT; static final int VARIANT_ONE_LINE_TEXT_ICON; static final int VARIANT_TWO_LINE_TEXT; static final int VARIANT_TWO_LINE_TEXT_ICON; static final int ICON_GRAVITY_START; static final int ICON_GRAVITY_END; }
@Test public void givenTextColorsInAttrs_whenCreated_thenHasTextColors() { AttributeSet attrs = Robolectric.buildAttributeSet() .addAttribute(R.attr.ma_grid_item_variant, "two_line_text") .addAttribute(R.attr.ma_grid_text_primary_color, "@color/ma_orange_50") .addAttribute(R.attr.ma_grid_text_secondary_color, "@color/ma_light_blue_a700") .build(); GridItemView view = new GridItemView(RuntimeEnvironment.application, attrs, 0, 0); assertThat(view) .hasPrimaryTextColor(getColor(R.color.ma_orange_50)) .hasSecondaryTextColor(getColor(R.color.ma_light_blue_a700)); }