All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xtremelabs.robolectric.matchers.TextViewHasTextMatcher Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
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