@ -11,10 +11,8 @@ import io.mockk.confirmVerified
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.slot
import io.mockk.unmockkObject
import io.mockk.unmockkStatic
import io.mockk.verify
import org.junit.After
@ -26,44 +24,49 @@ import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith ( FenixRobolectricTestRunner :: class )
class StrictModeManagerTest {
private lateinit var debugManager : StrictModeManager
private lateinit var releaseManager : StrictModeManager
@MockK ( relaxUnitFun = true ) private lateinit var fragmentManager : FragmentManager
@Before
fun setup ( ) {
MockKAnnotations . init ( this )
mockkStatic ( StrictMode :: class )
mockkObject ( Config )
// These tests log a warning that mockk couldn't set the backing field of Config.channel
// but it doesn't seem to impact their correctness so I'm ignoring it.
val debugConfig : Config = mockk { every { channel } returns ReleaseChannel . Debug }
debugManager = StrictModeManager ( debugConfig )
val releaseConfig : Config = mockk { every { channel } returns ReleaseChannel . Release }
releaseManager = StrictModeManager ( releaseConfig )
}
@After
fun teardown ( ) {
unmockkStatic ( StrictMode :: class )
unmockkObject ( Config )
}
@Test
fun `test enableStrictMode in release` ( ) {
every { Config . channel } returns ReleaseChannel . Release
StrictModeManager . enableStrictMode ( false )
releaseManager . enableStrictMode ( false )
verify ( exactly = 0 ) { StrictMode . setThreadPolicy ( any ( ) ) }
verify ( exactly = 0 ) { StrictMode . setVmPolicy ( any ( ) ) }
}
@Test
fun `test enableStrictMode in debug` ( ) {
every { Config . channel } returns ReleaseChannel . Debug
StrictModeManager . enableStrictMode ( false )
debugManager . enableStrictMode ( false )
verify { StrictMode . setThreadPolicy ( any ( ) ) }
verify { StrictMode . setVmPolicy ( any ( ) ) }
}
@Test
fun `test changeStrictModePolicies `( ) {
fun `test changeStrictModePolicies in debug `( ) {
val callbacks = slot < FragmentManager . FragmentLifecycleCallbacks > ( )
StrictMode Manager. attachListenerToDisablePenaltyDeath ( fragmentManager )
debug Manager. attachListenerToDisablePenaltyDeath ( fragmentManager )
verify { fragmentManager . registerFragmentLifecycleCallbacks ( capture ( callbacks ) , false ) }
confirmVerified ( fragmentManager )