Skip to content

Commit

Permalink
Simplify BitmapComparator (#435)
Browse files Browse the repository at this point in the history
* Simplify BitmapComparator

* Disable library module connectedCheck task
  • Loading branch information
Sloy authored Aug 26, 2021
1 parent 5a1ab37 commit 864961b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ jobs:
arch: x86
profile: pixel_2
disable-animations: true
script: ./gradlew connectedCheck
script: ./gradlew :sample:connectedCheck
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import androidx.annotation.DrawableRes
import android.view.View
import com.adevinta.android.barista.internal.util.BitmapComparator
import com.adevinta.android.barista.internal.util.DrawableToBitmapConverter
import org.hamcrest.Description
import org.hamcrest.TypeSafeMatcher
Expand Down Expand Up @@ -57,7 +56,7 @@ class BackgroundMatcher private constructor(@DrawableRes private val expectedDra
private fun hasSameBitmap(view: View, expectedDrawable: Drawable?): Boolean {
val viewBitmap = DrawableToBitmapConverter.getBitmap(view.background)
val expectedBitmap = DrawableToBitmapConverter.getBitmap(expectedDrawable)
return BitmapComparator.compare(viewBitmap, expectedBitmap)
return viewBitmap.sameAs(expectedBitmap)
}

private fun isSameColorDrawable(viewDrawable: ColorDrawable, expectedDrawable: ColorDrawable) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.widget.ImageView
import androidx.annotation.DrawableRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.drawable.DrawableCompat
import com.adevinta.android.barista.internal.util.BitmapComparator
import com.adevinta.android.barista.internal.util.DrawableToBitmapConverter
import com.google.android.material.button.MaterialButton
import org.hamcrest.Description
Expand Down Expand Up @@ -56,7 +55,7 @@ class DrawableMatcher private constructor(@DrawableRes private val expectedDrawa
resourceName = resources.getResourceEntryName(expectedDrawableRes)

val viewBitmap = DrawableToBitmapConverter.getBitmap(drawable)
return target.getExpectedBitmap()?.let { BitmapComparator.compare(viewBitmap, it) } ?: false
return target.getExpectedBitmap()?.let { viewBitmap.sameAs(it) } ?: false
}

override fun describeTo(description: Description) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.adevinta.android.barista.internal.util
package com.adevinta.android.barista.sample

import android.content.Context
import android.graphics.BitmapFactory
import androidx.test.core.app.ApplicationProvider
import com.adevinta.android.barista.test.R
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assert
import org.junit.Test

class BitmapComparatorTest {
Expand All @@ -15,18 +13,19 @@ class BitmapComparatorTest {
val aBitmap = BitmapFactory.decodeResource(ApplicationProvider.getApplicationContext<Context>().resources, R.drawable.ic_barista)
val theSameBitmap = BitmapFactory.decodeResource(ApplicationProvider.getApplicationContext<Context>().resources, R.drawable.ic_barista)

val result = BitmapComparator.compare(aBitmap, theSameBitmap)
val result = aBitmap.sameAs(theSameBitmap)

assertTrue(result)
Assert.assertTrue(result)
}

@Test
fun returnFalseWhenComparingDifferentDrawables() {
val aBitmap = BitmapFactory.decodeResource(ApplicationProvider.getApplicationContext<Context>().resources, R.drawable.ic_barista)
val aDifferentBitmap = BitmapFactory.decodeResource(ApplicationProvider.getApplicationContext<Context>().resources, R.drawable.ic_launcher)
val aDifferentBitmap =
BitmapFactory.decodeResource(ApplicationProvider.getApplicationContext<Context>().resources, R.drawable.ic_action_menu)

val result = BitmapComparator.compare(aBitmap, aDifferentBitmap)
val result = aBitmap.sameAs(aDifferentBitmap)

assertFalse(result)
Assert.assertFalse(result)
}
}

0 comments on commit 864961b

Please sign in to comment.