Android Open Source - android-marvin Has Text






From Project

Back to project page android-marvin.

License

The source code is released under:

Apache License

If you think the Android project android-marvin listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.akquinet.android.marvin.matchers;
/*w  ww.  j  a  va 2s .  c om*/
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import android.view.View;
import android.widget.TextView;

public class HasText<T> extends TypeSafeMatcher<T> {
    private final String expected;

    public HasText(String expected) {
        this.expected = expected;
    }

    public boolean matchesSafely(Object arg) {
        return arg instanceof TextView
                && expected.equals(((TextView) arg).getText().toString());
    }

    public void describeTo(Description description) {
        description.appendText("hasText(")
                .appendValue(expected)
                .appendText(")");
    }
    
    protected void describeMismatchSafely(T actual, Description mismatchDescription) {
        mismatchDescription.appendValue(actual) .appendText(" had text ")
        .appendText(expected)
        .appendText(" ").appendValue(expected);
    }

    @Factory
    public static <T extends View> Matcher<T> hasText(String text) {
        return new HasText<T>(text);
    }
}


//public class HasText<T> extends BaseMatcher<T> {
//    private final String text;
//
//    public HasText(String text) {
//        this.text = text;
//    }
//
//    public boolean matches(Object arg) {
//        return arg instanceof TextView
//                && text.equals(((TextView) arg).getText().toString());
//    }
//
//    public void describeTo(Description description) {
//        description.appendText("hasText(")
//                .appendValue(text)
//                .appendText(")");
//    }
//
//    @Factory
//    public static <T extends View> Matcher<T> hasText(String text) {
//        return new HasText<T>(text);
//    }
//}





Java Source Code List

de.akquinet.android.marvin.ActivityTestCase.java
de.akquinet.android.marvin.AndroidMatchers.java
de.akquinet.android.marvin.AndroidTestCase.java
de.akquinet.android.marvin.ServiceTestCase.java
de.akquinet.android.marvin.actions.ActionFactory.java
de.akquinet.android.marvin.actions.ActivityAction.java
de.akquinet.android.marvin.actions.AwaitAction.java
de.akquinet.android.marvin.actions.BaseAction.java
de.akquinet.android.marvin.actions.FindViewAction.java
de.akquinet.android.marvin.actions.PerformAction.java
de.akquinet.android.marvin.actions.ViewAction.java
de.akquinet.android.marvin.actions.ViewFilter.java
de.akquinet.android.marvin.matchers.Condition.java
de.akquinet.android.marvin.matchers.HasText.java
de.akquinet.android.marvin.matchers.IsEnabled.java
de.akquinet.android.marvin.matchers.IsOnScreen.java
de.akquinet.android.marvin.matchers.IsVisible.java
de.akquinet.android.marvin.matchers.ViewGroupComparison.java
de.akquinet.android.marvin.matchers.util.WaitForConditionUtil.java
de.akquinet.android.marvin.monitor.ExtendedActivityMonitor.java
de.akquinet.android.marvin.monitor.StartedActivity.java
de.akquinet.android.marvin.util.MarvinConnectivityUtil.java
de.akquinet.android.marvin.util.TemporaryServiceConnection.java