From a4308adf2d9fbfa6575655c5a1beb6987f024309 Mon Sep 17 00:00:00 2001 From: Serchinastico <54cymru@gmail.com> Date: Wed, 30 Jan 2019 19:07:16 +0100 Subject: [PATCH] Execute executePendingBindings to fix tests --- .../ui/view/SuperHeroViewHolderTest.kt | 29 +++++++------------ .../ui/view/adapter/SuperHeroViewHolder.kt | 1 + .../ui/view/adapter/SuperHeroesAdapter.kt | 1 - 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/app/src/androidTest/java/com/karumi/jetpack/superheroes/ui/view/SuperHeroViewHolderTest.kt b/app/src/androidTest/java/com/karumi/jetpack/superheroes/ui/view/SuperHeroViewHolderTest.kt index 382c612..3f70a31 100644 --- a/app/src/androidTest/java/com/karumi/jetpack/superheroes/ui/view/SuperHeroViewHolderTest.kt +++ b/app/src/androidTest/java/com/karumi/jetpack/superheroes/ui/view/SuperHeroViewHolderTest.kt @@ -16,9 +16,9 @@ class SuperHeroViewHolderTest : ScreenshotTest { @Test fun showsAnySuperHero() { val superHero = givenASuperHero() - val (holder, binding) = givenASuperHeroViewHolder() + val holder = givenASuperHeroViewHolder() - renderViewHolder(superHero, holder, binding) + holder.render(superHero) compareScreenshot(holder, R.dimen.super_hero_row_height) } @@ -26,9 +26,9 @@ class SuperHeroViewHolderTest : ScreenshotTest { @Test fun showsSuperHeroesWithLongNames() { val superHero = givenASuperHeroWithALongName() - val (holder, binding) = givenASuperHeroViewHolder() + val holder = givenASuperHeroViewHolder() - renderViewHolder(superHero, holder, binding) + holder.render(superHero) compareScreenshot(holder, R.dimen.super_hero_row_height) } @@ -36,9 +36,9 @@ class SuperHeroViewHolderTest : ScreenshotTest { @Test fun showsSuperHeroesWithLongDescriptions() { val superHero = givenASuperHeroWithALongDescription() - val (holder, binding) = givenASuperHeroViewHolder() + val holder = givenASuperHeroViewHolder() - renderViewHolder(superHero, holder, binding) + holder.render(superHero) compareScreenshot(holder, R.dimen.super_hero_row_height) } @@ -46,23 +46,14 @@ class SuperHeroViewHolderTest : ScreenshotTest { @Test fun showsAvengersBadge() { val superHero = givenASuperHero(isAvenger = true) - val (holder, binding) = givenASuperHeroViewHolder() + val holder = givenASuperHeroViewHolder() - renderViewHolder(superHero, holder, binding) + holder.render(superHero) compareScreenshot(holder, R.dimen.super_hero_row_height) } - private fun renderViewHolder( - superHero: SuperHero, - holder: SuperHeroViewHolder, - binding: SuperHeroRowBinding - ) { - holder.render(superHero) - binding.executePendingBindings() - } - - private fun givenASuperHeroViewHolder(): Pair = + private fun givenASuperHeroViewHolder(): SuperHeroViewHolder = runOnUi { val context = InstrumentationRegistry.getInstrumentation().targetContext val inflater = LayoutInflater.from(context) @@ -71,7 +62,7 @@ class SuperHeroViewHolderTest : ScreenshotTest { SuperHeroViewHolder( binding, mock(SuperHeroesPresenter::class.java) - ) to binding + ) } private fun givenASuperHeroWithALongDescription(): SuperHero { diff --git a/app/src/main/java/com/karumi/jetpack/superheroes/ui/view/adapter/SuperHeroViewHolder.kt b/app/src/main/java/com/karumi/jetpack/superheroes/ui/view/adapter/SuperHeroViewHolder.kt index 950362e..13e329a 100644 --- a/app/src/main/java/com/karumi/jetpack/superheroes/ui/view/adapter/SuperHeroViewHolder.kt +++ b/app/src/main/java/com/karumi/jetpack/superheroes/ui/view/adapter/SuperHeroViewHolder.kt @@ -13,5 +13,6 @@ class SuperHeroViewHolder( fun render(superHero: SuperHero) { binding.superHero = superHero binding.listener = listener + binding.executePendingBindings() } } \ No newline at end of file diff --git a/app/src/main/java/com/karumi/jetpack/superheroes/ui/view/adapter/SuperHeroesAdapter.kt b/app/src/main/java/com/karumi/jetpack/superheroes/ui/view/adapter/SuperHeroesAdapter.kt index c90c638..fabd7f7 100644 --- a/app/src/main/java/com/karumi/jetpack/superheroes/ui/view/adapter/SuperHeroesAdapter.kt +++ b/app/src/main/java/com/karumi/jetpack/superheroes/ui/view/adapter/SuperHeroesAdapter.kt @@ -8,7 +8,6 @@ import com.karumi.jetpack.superheroes.R import com.karumi.jetpack.superheroes.databinding.SuperHeroRowBinding import com.karumi.jetpack.superheroes.domain.model.SuperHero import com.karumi.jetpack.superheroes.ui.presenter.SuperHeroesListener -import com.karumi.jetpack.superheroes.ui.presenter.SuperHeroesPresenter internal class SuperHeroesAdapter( private val listener: SuperHeroesListener