UberButton extends AppCompatButton { @VisibleForTesting @DrawableRes int getBackgroundResource() { return backgroundResource; } UberButton(Context context);  UberButton(Context context, AttributeSet attrs);  UberButton(Context context, AttributeSet attrs, int defStyleAttr);  UberButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes); @Override void setBackgroundResource(@DrawableRes int backgroundResource);  }
@Test public void onCreate_whenNoAttributesSet_shouldUseUberButtonDefaults() { UberButton uberButton = new UberButton(context, null, 0, 0) { }; Resources resources = context.getResources(); assertEquals(R.drawable.uber_button_background_selector_black, uberButton.getBackgroundResource()); assertNull(uberButton.getCompoundDrawables()[0]); assertNull(uberButton.getCompoundDrawables()[1]); assertNull(uberButton.getCompoundDrawables()[2]); assertNull(uberButton.getCompoundDrawables()[3]); assertEquals(0, uberButton.getPaddingLeft(), 0); assertEquals(0, uberButton.getPaddingTop(), 0); assertEquals(0, uberButton.getPaddingRight(), 0); assertEquals(0, uberButton.getPaddingBottom(), 0); assertEquals(resources.getColor(R.color.uber_white), uberButton.getCurrentTextColor()); assertEquals(Typeface.NORMAL, uberButton.getTypeface().getStyle()); assertTrue(StringUtils.isEmpty(uberButton.getText().toString())); }
@Test public void onCreate_whenUberStyleSet_shouldUseUberStyle() { AttributeSet attributeSet = Robolectric.buildAttributeSet() .addAttribute(R.attr.ub__style, "white") .build(); UberButton uberButton = new UberButton(context, attributeSet, 0, R.style.UberButton_White) { }; Resources resources = context.getResources(); assertEquals(R.drawable.uber_button_background_selector_white, uberButton.getBackgroundResource()); assertNull(uberButton.getCompoundDrawables()[0]); assertNull(uberButton.getCompoundDrawables()[1]); assertNull(uberButton.getCompoundDrawables()[2]); assertNull(uberButton.getCompoundDrawables()[3]); assertEquals(0, uberButton.getPaddingLeft(), 0); assertEquals(0, uberButton.getPaddingTop(), 0); assertEquals(0, uberButton.getPaddingRight(), 0); assertEquals(0, uberButton.getPaddingBottom(), 0); assertEquals(resources.getColor(R.color.uber_black), uberButton.getCurrentTextColor()); assertEquals(Typeface.NORMAL, uberButton.getTypeface().getStyle()); assertTrue(uberButton.getGravity() != 0); assertTrue(StringUtils.isEmpty(uberButton.getText().toString())); }