1package com.xtremelabs.robolectric.matchers;
2
3import android.widget.CompoundButton;
4import org.hamcrest.Description;
5import org.hamcrest.Factory;
6import org.hamcrest.Matcher;
7import org.junit.internal.matchers.TypeSafeMatcher;
8
9public class CompoundButtonCheckedMatcher<T extends CompoundButton> extends TypeSafeMatcher<T> {
10    private boolean expected;
11
12    public CompoundButtonCheckedMatcher(boolean expected) {
13        this.expected = expected;
14    }
15
16    @Override public boolean matchesSafely(T compoundButton) {
17        return compoundButton != null && expected == compoundButton.isChecked();
18    }
19
20    @Override public void describeTo(Description description) {
21        description.appendText("to be [" + (expected ? "checked" : "unchecked") + "]");
22    }
23
24    @Factory
25    public static <T extends CompoundButton> Matcher<T> isChecked(boolean expectedChecked) {
26        return new CompoundButtonCheckedMatcher<T>(expectedChecked);
27    }
28}
29