package com.xtremelabs.robolectric.matchers; import android.widget.CompoundButton; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.junit.internal.matchers.TypeSafeMatcher; public class CompoundButtonCheckedMatcher extends TypeSafeMatcher { private boolean expected; public CompoundButtonCheckedMatcher(boolean expected) { this.expected = expected; } @Override public boolean matchesSafely(T compoundButton) { return compoundButton != null && expected == compoundButton.isChecked(); } @Override public void describeTo(Description description) { description.appendText("to be [" + (expected ? "checked" : "unchecked") + "]"); } @Factory public static Matcher isChecked(boolean expectedChecked) { return new CompoundButtonCheckedMatcher(expectedChecked); } }