Skip to content

Commit

Permalink
For mozilla-mobile#13959: remove resetAfter & port tests to StrictMod…
Browse files Browse the repository at this point in the history
…eManager.
  • Loading branch information
mcomella committed Sep 29, 2020
1 parent dd73cb6 commit 42cca07
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 107 deletions.
28 changes: 0 additions & 28 deletions app/src/main/java/org/mozilla/fenix/ext/StrictMode.kt

This file was deleted.

40 changes: 40 additions & 0 deletions app/src/test/java/org/mozilla/fenix/StrictModeManagerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import io.mockk.slot
import io.mockk.unmockkStatic
import io.mockk.verify
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -73,4 +75,42 @@ class StrictModeManagerTest {
callbacks.captured.onFragmentResumed(fragmentManager, mockk())
verify { fragmentManager.unregisterFragmentLifecycleCallbacks(callbacks.captured) }
}

@Test
fun `GIVEN we're in a release build WHEN resetAfter is called THEN we return the value from the function block`() {
val expected = "Hello world"
val actual = releaseManager.resetAfter(StrictMode.allowThreadDiskReads()) { expected }
assertEquals(expected, actual)
}

@Test
fun `GIVEN we're in a debug build WHEN resetAfter is called THEN we return the value from the function block`() {
val expected = "Hello world"
val actual = debugManager.resetAfter(StrictMode.allowThreadDiskReads()) { expected }
assertEquals(expected, actual)
}

@Test
fun `GIVEN we're in a release build WHEN resetAfter is called THEN the old policy is not set`() {
releaseManager.resetAfter(StrictMode.allowThreadDiskReads()) { "" }
verify(exactly = 0) { StrictMode.setThreadPolicy(any()) }
}

@Test
fun `GIVEN we're in a debug build WHEN resetAfter is called THEN the old policy is set`() {
val expectedPolicy = StrictMode.allowThreadDiskReads()
debugManager.resetAfter(expectedPolicy) { "" }
verify { StrictMode.setThreadPolicy(expectedPolicy) }
}

@Test
fun `GIVEN we're in a debug build WHEN resetAfter is called and an exception is thrown from the function THEN the old policy is set`() {
val expectedPolicy = StrictMode.allowThreadDiskReads()
try {
debugManager.resetAfter(expectedPolicy) { throw IllegalStateException() }
@Suppress("UNREACHABLE_CODE") fail("Expected previous method to throw.")
} catch (e: IllegalStateException) { /* Do nothing */ }

verify { StrictMode.setThreadPolicy(expectedPolicy) }
}
}
79 changes: 0 additions & 79 deletions app/src/test/java/org/mozilla/fenix/ext/StrictModeTest.kt

This file was deleted.

0 comments on commit 42cca07

Please sign in to comment.