-
-
Save o-vitaliy/a65e5742cbc1f3a7b59b09365b28292b to your computer and use it in GitHub Desktop.
FirebaseAnalyticsTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class FirebaseAnalyticsTest { | |
private val context = mockk<Context>(relaxed = true, relaxUnitFun = true) | |
private val mockedFirebaseAnalytics = | |
mockk<GFirebaseAnalytics>(relaxed = true, relaxUnitFun = true) | |
init { | |
mockkStatic(GFirebaseAnalytics::class) | |
every { GFirebaseAnalytics.getInstance(context) } returns mockedFirebaseAnalytics | |
} | |
private val analytics = FirebaseAnalytics(context) | |
@Test | |
fun `test track event`() { | |
MockBundle.mock() | |
val event = "event1" | |
val values = mapOf("value1" to "11") | |
analytics.trackEvent(event, values) | |
verify { | |
mockedFirebaseAnalytics.logEvent(event, match { it.getString("value1") == "11" }) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object MockBundle { | |
fun mock() { | |
mockkConstructor(Bundle::class) | |
val map = mutableMapOf<String, Any?>() | |
every { | |
anyConstructed<Bundle>().getString(any()) | |
} answers { | |
map[it.invocation.args[0] as String] as? String | |
} | |
every { anyConstructed<Bundle>().putString(any(), any()) } answers { | |
map[it.invocation.args[0] as String] = it.invocation.args[1] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment