Espresso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ImageViewAssert extends AbstractAssert<ImageViewAssert, ImageView> { | |
public ImageViewAssert(ImageView actual) { | |
super(actual, ImageViewAssert.class); | |
} | |
public static ImageViewAssert assertThat(ImageView actual) { | |
return new ImageViewAssert(actual); | |
} | |
public ImageViewAssert hasDrawable(Drawable drawable) { | |
isNotNull(); | |
Drawable actualDrawable = actual.getDrawable(); | |
if (sameBitmap(actualDrawable, drawable)) { | |
failWithMessage("error"); | |
} | |
return this; | |
} | |
public ImageViewAssert hasDrawable(int resId) { | |
isNotNull(); | |
Context context = InstrumentationRegistry.getTargetContext(); | |
Drawable drawable = ((BitmapDrawable) context.getResources().getDrawable(resId)); | |
Drawable actualDrawable = actual.getDrawable(); | |
if (!sameBitmap(actualDrawable, drawable)) { | |
failWithMessage("error"); | |
} | |
return this; | |
} | |
private boolean sameBitmap(Drawable actual, Drawable expected) { | |
Bitmap actualBitmap = ((BitmapDrawable) actual).getBitmap(); | |
Bitmap expectedBitmap = ((BitmapDrawable) expected).getBitmap(); | |
return actualBitmap.sameAs(expectedBitmap); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment