1 package com.xtremelabs.robolectric.matchers; 2 3 import android.widget.TextView; 4 import com.xtremelabs.robolectric.shadows.ShadowTextView; 5 import org.hamcrest.Description; 6 import org.hamcrest.Factory; 7 import org.hamcrest.Matcher; 8 import org.junit.internal.matchers.TypeSafeMatcher; 9 10 import static com.xtremelabs.robolectric.Robolectric.shadowOf; 11 12 public class HasCompoundDrawablesMatcher extends TypeSafeMatcher<TextView> { 13 private String message; 14 private ShadowTextView.CompoundDrawables expectedCompoundDrawables; 15 16 public HasCompoundDrawablesMatcher(int left, int top, int right, int bottom) { 17 expectedCompoundDrawables = new ShadowTextView.CompoundDrawables(left, top, right, bottom); 18 } 19 20 @Override 21 public boolean matchesSafely(TextView actual) { 22 if (actual == null) { 23 message = "actual view was null"; 24 return false; 25 } 26 27 ShadowTextView.CompoundDrawables actualCompoundDrawables = shadowOf(actual).getCompoundDrawablesImpl(); 28 if (!expectedCompoundDrawables.equals(actualCompoundDrawables)) { 29 message = "[" + actualCompoundDrawables + "] to equal [" + expectedCompoundDrawables + "]"; 30 return false; 31 } else { 32 return true; 33 } 34 } 35 36 @Override 37 public void describeTo(Description description) { 38 description.appendText(message); 39 } 40 41 @Factory 42 public static Matcher<TextView> hasCompoundDrawables(int left, int top, int right, int bottom) { 43 return new HasCompoundDrawablesMatcher(left, top, right, bottom); 44 } 45 } 46