Skip to content

Commit

Permalink
Port PicassoDrawableTest to instrumented tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-horner committed Jul 8, 2022
1 parent 6c392b4 commit d27712b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ buildscript {
androidxCursorAdapter: 'androidx.cursoradapter:cursoradapter:1.0.0',
androidxExifInterface: 'androidx.exifinterface:exifinterface:1.3.3',
androidxFragment: 'androidx.fragment:fragment:1.4.0',
androidxJunit: 'androidx.test.ext:junit:1.1.3',
androidxLifecycle: 'androidx.lifecycle:lifecycle-common:2.4.0',
androidxStartup: 'androidx.startup:startup-runtime:1.1.0',
androidxTestRunner: 'androidx.test:runner:1.4.0',
Expand Down
2 changes: 2 additions & 0 deletions picasso/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ dependencies {
testImplementation deps.mockito
testImplementation deps.mockWebServer

androidTestImplementation deps.androidxJunit
androidTestImplementation deps.androidxTestRunner
androidTestImplementation deps.truth
}

spotless {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,27 @@
*/
package com.squareup.picasso3

import android.content.Context
import android.graphics.Bitmap
import android.graphics.Color.RED
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.squareup.picasso3.Picasso.LoadedFrom.DISK
import com.squareup.picasso3.Picasso.LoadedFrom.MEMORY
import com.squareup.picasso3.TestUtils.makeBitmap
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment

@RunWith(RobolectricTestRunner::class)
@RunWith(AndroidJUnit4::class)
class PicassoDrawableTest {
private val context: Context = RuntimeEnvironment.application
private val placeholder: Drawable = ColorDrawable(RED)
private val bitmap = makeBitmap()
private val bitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8)

@Test fun createWithNoPlaceholderAnimation() {
val pd = PicassoDrawable(
context, bitmap,
placeholder = null,
context = ApplicationProvider.getApplicationContext(),
bitmap = bitmap,
loadedFrom = DISK,
noFade = false,
debugging = false
Expand All @@ -49,7 +47,9 @@ class PicassoDrawableTest {

@Test fun createWithPlaceholderAnimation() {
val pd = PicassoDrawable(
context, bitmap, placeholder,
context = ApplicationProvider.getApplicationContext(),
bitmap = bitmap,
placeholder,
loadedFrom = DISK,
noFade = false,
debugging = false
Expand All @@ -61,8 +61,10 @@ class PicassoDrawableTest {

@Test fun createWithBitmapCacheHit() {
val pd = PicassoDrawable(
context, bitmap, placeholder,
loadedFrom = MEMORY,
context = ApplicationProvider.getApplicationContext(),
bitmap = bitmap,
placeholder,
loadedFrom = Picasso.LoadedFrom.MEMORY,
noFade = false,
debugging = false
)
Expand Down

0 comments on commit d27712b

Please sign in to comment.