Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
forrestguice committed Feb 4, 2025
1 parent eaf78ad commit be34ec1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public static Matcher<View> hasDescendant(final Matcher<View> descendantMatcher)
return android.support.test.espresso.matcher.ViewMatchers.hasDescendant(descendantMatcher);
}

public static Matcher<View> hasBackground(final int drawableId) {
return android.support.test.espresso.matcher.ViewMatchers.hasBackground(drawableId);
}

public static Matcher<View> hasTextColor(final int colorResId) {
return android.support.test.espresso.matcher.ViewMatchers.hasTextColor(colorResId);
}

public static Matcher<View> isEnabled() {
return android.support.test.espresso.matcher.ViewMatchers.isEnabled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.AppCompatImageButton;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
Expand Down Expand Up @@ -76,22 +79,34 @@ public static Matcher<View> hasDrawable(int drawableResourceId) {
return new DrawableMatcher(drawableResourceId);
}
@TargetApi(12)
public static Matcher<View> hasDrawable(Drawable drawable) {
return new DrawableMatcher(drawable);
}
@TargetApi(12)
public static class DrawableMatcher extends TypeSafeMatcher<View>
{
protected int withResourceID;
public DrawableMatcher(int withResourceId) {
this.withResourceID = withResourceId;
}

protected Drawable drawable = null;
public DrawableMatcher(Drawable drawable) {
this.drawable = drawable;
}

@Override
protected boolean matchesSafely(View view)
{
if (!(view instanceof ImageView) && !(view instanceof AppCompatImageButton) && !(view instanceof ImageButton)) {
return false;
}
Drawable withDrawable = view.getContext().getResources().getDrawable(withResourceID);
if (withDrawable == null) {
return false;
Drawable withDrawable = drawable;
if (drawable == null) {
withDrawable = view.getContext().getResources().getDrawable(withResourceID);
if (withDrawable == null) {
return false;
}
}

Drawable d = null;
Expand All @@ -106,9 +121,15 @@ protected boolean matchesSafely(View view)
}

@Override
public void describeTo(Description description) {
description.appendText("with drawable resource id: ");
description.appendValue(withResourceID);
public void describeTo(Description description)
{
if (drawable != null) {
description.appendText("with drawable: ");
description.appendValue(drawable.toString());
} else {
description.appendText("with drawable resource id: ");
description.appendValue(withResourceID);
}
}

@Nullable
Expand Down Expand Up @@ -304,4 +325,26 @@ public void describeTo(Description description)
}
};
}

/**
* https://stackoverflow.com/a/34286462
*/
public static Matcher<View> isShowingError()
{
return new TypeSafeMatcher<View>()
{
@Override
public boolean matchesSafely(View view) {
if (view instanceof EditText) {
return (((EditText) view).getError() != null);
}
return false;
}

@Override
public void describeTo(Description description) {
description.appendText("with error text");
}
};
}
}

0 comments on commit be34ec1

Please sign in to comment.