Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Espresso
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