|
| 1 | +package com.flipcash.app.internal.debug |
| 2 | + |
| 3 | +import android.provider.Settings |
| 4 | +import com.flipcash.app.updates.ReleaseStage |
| 5 | +import org.junit.runner.RunWith |
| 6 | +import org.robolectric.RobolectricTestRunner |
| 7 | +import org.robolectric.RuntimeEnvironment |
| 8 | +import org.robolectric.annotation.Config |
| 9 | +import kotlin.test.Test |
| 10 | +import kotlin.test.assertEquals |
| 11 | +import kotlin.test.assertFalse |
| 12 | +import kotlin.test.assertTrue |
| 13 | + |
| 14 | +@RunWith(RobolectricTestRunner::class) |
| 15 | +@Config(manifest = Config.NONE, application = android.app.Application::class) |
| 16 | +class TestLabTest { |
| 17 | + |
| 18 | + private val context = RuntimeEnvironment.getApplication() |
| 19 | + |
| 20 | + @Test |
| 21 | + fun `a Test Lab device reports the TestLab stage whatever the track`() { |
| 22 | + ReleaseStage.entries.forEach { stage -> |
| 23 | + assertEquals(TestLabStage, bugsnagReleaseStage(stage, onTestLab = true)) |
| 24 | + } |
| 25 | + assertEquals(TestLabStage, bugsnagReleaseStage(null, onTestLab = true)) |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + fun `any other device reports its track`() { |
| 30 | + assertEquals("Internal", bugsnagReleaseStage(ReleaseStage.Internal, onTestLab = false)) |
| 31 | + assertEquals("Production", bugsnagReleaseStage(ReleaseStage.Production, onTestLab = false)) |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + fun `an unresolved track on any other device is Unknown`() { |
| 36 | + assertEquals("Unknown", bugsnagReleaseStage(null, onTestLab = false)) |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + fun `the Test Lab setting marks the device`() { |
| 41 | + Settings.System.putString(context.contentResolver, "firebase.test.lab", "true") |
| 42 | + |
| 43 | + assertTrue(TestLab.isRunning(context)) |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + fun `a device without the setting is not Test Lab`() { |
| 48 | + assertFalse(TestLab.isRunning(context)) |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + fun `a setting other than true is not Test Lab`() { |
| 53 | + Settings.System.putString(context.contentResolver, "firebase.test.lab", "false") |
| 54 | + |
| 55 | + assertFalse(TestLab.isRunning(context)) |
| 56 | + } |
| 57 | +} |
0 commit comments