Home | History | Annotate | Download | only in matchers
      1 package com.xtremelabs.robolectric.matchers;
      2 
      3 import android.widget.CompoundButton;
      4 import org.hamcrest.Description;
      5 import org.hamcrest.Factory;
      6 import org.hamcrest.Matcher;
      7 import org.junit.internal.matchers.TypeSafeMatcher;
      8 
      9 public 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