Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olegosipenko committed Sep 20, 2023
1 parent 9cd2ba8 commit e7fa764
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class AssertExpectedDeviceTest {
assertThrows(ScreenshotBaselineNotDefinedException::class.java, rule::assertSame)
}

@ScreenshotInstrumentation
@Test
fun testMissingBaselineRecordMode() {
rule.setRecordModeEnabled(true)
.assertSame()
}

/**
* WHEN the baseline image does not match the current device settings THEN throw UnexpectedDeviceException
*
Expand Down
13 changes: 0 additions & 13 deletions Library/src/test/java/dev/testify/ScreenshotRuleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Build
import android.os.Bundle
import android.os.Looper
import android.view.View
Expand Down Expand Up @@ -59,8 +58,6 @@ import org.junit.Test
import org.junit.runner.Description
import org.junit.runners.model.Statement
import java.io.File
import java.lang.reflect.Field
import java.lang.reflect.Modifier

class ScreenshotRuleTest {

Expand All @@ -85,15 +82,6 @@ class ScreenshotRuleTest {
)
)

private fun setStaticFieldViaReflection(field: Field, value: Any) {
field.isAccessible = true
Field::class.java.getDeclaredField("modifiers").apply {
isAccessible = true
setInt(field, field.modifiers and Modifier.FINAL.inv())
}
field.set(null, value)
}

@Before
fun setUp() {
mockkStatic(::assertExpectedDevice)
Expand Down Expand Up @@ -122,7 +110,6 @@ class ScreenshotRuleTest {
every { mainLooper.thread } returns currentThread
every { Looper.getMainLooper() } returns mainLooper

setStaticFieldViaReflection(Build.VERSION::class.java.getField("SDK_INT"), 31)
every { getDeviceDimensions(any()) } returns (1024 to 2048)

subject = spyk(ScreenshotRule(Activity::class.java))
Expand Down
17 changes: 17 additions & 0 deletions Library/src/test/java/dev/testify/output/DestinationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,21 @@ class DestinationTest {
destination.description
)
}

@Test
fun `WHEN testStorage THEN data directory`() {
every { mockArguments.getString("useTestStorage") } returns "true"

val destination = getDestination(
mockContext,
"fileName",
extension = ".ext",
customKey = null,
root = "root"
)
assertEquals(
"/data/user/0/dev.testify.sample/app_images/root/screenshots/33-1080x2200@420dp-en_CA/fileName.ext",
destination.description
)
}
}

0 comments on commit e7fa764

Please sign in to comment.