ImageViewTarget extends ViewTarget<ImageView> { @Override protected void onError(ImageView view, Exception e, Mirage.Source source, MirageRequest request) { if (animation() != null) { Drawable drawable; if (getErrorResourceId() > 0) { drawable = view.getContext().getResources().getDrawable(getErrorResourceId()); } else { drawable = getErrorDrawable(); } if (drawable != null) { if (!animation().animate(view, drawable, source)) { view.setImageDrawable(drawable); } } else { view.setImageDrawable(null); } } else { if (getErrorResourceId() != 0) { view.setImageResource(getErrorResourceId()); } else if (getErrorDrawable() != null) { view.setImageDrawable(getErrorDrawable()); } else { view.setImageDrawable(null); } } } ImageViewTarget(ImageView imageView);  ImageViewTarget(MirageRequest request, ImageView imageView); @Override ViewTarget<ImageView> fade();  }
@Test public void testOnError() { ImageView imageView = new ImageView(RuntimeEnvironment.application); ImageViewTarget target = new ImageViewTarget(imageView); target.onError(new IOException("test exc"), Mirage.Source.EXTERNAL, new MirageRequest()); Assert.assertNull(imageView.getDrawable()); imageView = new ImageView(RuntimeEnvironment.application); target = new ImageViewTarget(imageView); target.error(R.drawable.abc_btn_check_material); target.onError(new IOException("test exc"), Mirage.Source.EXTERNAL, new MirageRequest()); imageView = new ImageView(RuntimeEnvironment.application); target = new ImageViewTarget(imageView); target.error(new ColorDrawable(Color.RED)); target.onError(new IOException("test exc"), Mirage.Source.EXTERNAL, new MirageRequest()); Assert.assertNotNull(imageView.getDrawable()); }