blob: 9e38010bc25d9cdb90c7ca6a1c86f7c2500b76e6 [file] [log] [blame]
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<T extends CompoundButton> extends TypeSafeMatcher<T> {
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 <T extends CompoundButton> Matcher<T> isChecked(boolean expectedChecked) {
return new CompoundButtonCheckedMatcher<T>(expectedChecked);
}
}