Skip to content

Instantly share code, notes, and snippets.

@veena14cs
Last active October 25, 2019 10:35
Show Gist options
  • Save veena14cs/f918bacca3396f489202f1c986afad1f to your computer and use it in GitHub Desktop.
Save veena14cs/f918bacca3396f489202f1c986afad1f to your computer and use it in GitHub Desktop.
@Test
fun testImageLoader_returnSuccess() {
val imageView = activityTestRule.activity.findViewById(R.id.test_url_parser_image_view) as ImageView
var drawable: Drawable? = null
val testBitmap: Bitmap? = null
val target = object : CustomTarget<Bitmap>() {
override fun onLoadCleared(placeholder: Drawable?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
drawable = BitmapDrawable(activityTestRule.activity.getResources(), resource);
imageView.setImageDrawable(drawable)
}
}
doAnswer(Answer() {
fun answer(invocation: InvocationOnMock) {
invocation.getArgument<CustomTarget<Bitmap>>(1).onResourceReady(testBitmap!!, null)
imageView.setImageBitmap(testBitmap)
}
}).`when`(imageLoader).load(OK_IMAGE_URL, target)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment