// Path: espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/Utils.java
// static final int NO_DRAWABLE = -1;
// 
// Path: espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/Utils.java
// static boolean drawableMatches(final View view, final Drawable drawable, @DrawableRes final int expectedId) {
//   final boolean isVisible = view.getVisibility() == VISIBLE;
// 
//   if (expectedId == NO_DRAWABLE) {
//     return isVisible && drawable == null;
//   }
// 
//   final Context context = view.getContext();
//   return isVisible && checkNotNull(drawable.getConstantState(), "constantState == null").equals(ContextCompat.getDrawable(context, expectedId).getConstantState());
// }


import android.graphics.drawable.Drawable;
import androidx.annotation.CheckResult;
import androidx.annotation.DrawableRes;
import androidx.test.espresso.matcher.BoundedMatcher;
import android.view.View;
import android.widget.ImageView;
import org.hamcrest.Description;
import static com.vanniktech.espresso.core.utils.Utils.NO_DRAWABLE;
import static com.vanniktech.espresso.core.utils.Utils.drawableMatches;
package com.vanniktech.espresso.core.utils;



public final class DrawableMatcher extends BoundedMatcher<View, ImageView> {
  /**
   * Matches that the given view has the expected drawable.
   *
   * <p>Example usage:</p>
   * <code>onView(withId(R.id.view)).check(matches(withDrawable(R.drawable.android)));</code>
   */
  @CheckResult public static DrawableMatcher withDrawable(@DrawableRes final int resourceId) {
    return new DrawableMatcher(resourceId);
  }

  /**
   * Matches that the given view has no drawable.
   *
   * <p>Example usage:</p>
   * <code>onView(withId(R.id.view)).check(matches(withNoDrawable()));</code>
   */
  @CheckResult public static DrawableMatcher withNoDrawable() {
    return new DrawableMatcher(NO_DRAWABLE);
  }

  private final int expectedId;

  private DrawableMatcher(final int expectedId) {
    super(ImageView.class);

    this.expectedId = expectedId;
  }

  @Override protected boolean matchesSafely(final ImageView imageView) {
    final Drawable drawable = imageView.getDrawable();
// Path: espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/Utils.java
// static final int NO_DRAWABLE = -1;
// 
// Path: espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/Utils.java
// static boolean drawableMatches(final View view, final Drawable drawable, @DrawableRes final int expectedId) {
//   final boolean isVisible = view.getVisibility() == VISIBLE;
// 
//   if (expectedId == NO_DRAWABLE) {
//     return isVisible && drawable == null;
//   }
// 
//   final Context context = view.getContext();
//   return isVisible && checkNotNull(drawable.getConstantState(), "constantState == null").equals(ContextCompat.getDrawable(context, expectedId).getConstantState());
// }


// Path: espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/DrawableMatcher.java
import android.graphics.drawable.Drawable;
import androidx.annotation.CheckResult;
import androidx.annotation.DrawableRes;
import androidx.test.espresso.matcher.BoundedMatcher;
import android.view.View;
import android.widget.ImageView;
import org.hamcrest.Description;
import static com.vanniktech.espresso.core.utils.Utils.NO_DRAWABLE;
import static com.vanniktech.espresso.core.utils.Utils.drawableMatches;

package com.vanniktech.espresso.core.utils;



public final class DrawableMatcher extends BoundedMatcher<View, ImageView> {
  /**
   * Matches that the given view has the expected drawable.
   *
   * <p>Example usage:</p>
   * <code>onView(withId(R.id.view)).check(matches(withDrawable(R.drawable.android)));</code>
   */
  @CheckResult public static DrawableMatcher withDrawable(@DrawableRes final int resourceId) {
    return new DrawableMatcher(resourceId);
  }

  /**
   * Matches that the given view has no drawable.
   *
   * <p>Example usage:</p>
   * <code>onView(withId(R.id.view)).check(matches(withNoDrawable()));</code>
   */
  @CheckResult public static DrawableMatcher withNoDrawable() {
    return new DrawableMatcher(NO_DRAWABLE);
  }

  private final int expectedId;

  private DrawableMatcher(final int expectedId) {
    super(ImageView.class);

    this.expectedId = expectedId;
  }

  @Override protected boolean matchesSafely(final ImageView imageView) {
    final Drawable drawable = imageView.getDrawable();
    return drawableMatches(imageView, drawable, expectedId);