
com.xtremelabs.robolectric.matchers.TextViewHasTextMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of robolectric Show documentation
Show all versions of robolectric Show documentation
An alternative Android testing framework.
package com.xtremelabs.robolectric.matchers;
import android.widget.TextView;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.junit.internal.matchers.TypeSafeMatcher;
public class TextViewHasTextMatcher extends TypeSafeMatcher {
private String expected;
private String actualText;
public TextViewHasTextMatcher(String expected) {
this.expected = expected;
}
@Override
public boolean matchesSafely(T actual) {
if (actual == null) {
return false;
}
final CharSequence charSequence = actual.getText();
if (charSequence == null || charSequence.toString() == null) {
return false;
}
actualText = charSequence.toString();
return actualText.equals(expected);
}
@Override
public void describeTo(Description description) {
description.appendText("[" + actualText + "]");
description.appendText(" to equal ");
description.appendText("[" + expected + "]");
}
@Factory
public static Matcher hasText(String expectedTextViewText) {
return new TextViewHasTextMatcher(expectedTextViewText);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy