mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
Bug 1825071 - Refactor FenixLogSink to remove mockkStatic usage.
This commit is contained in:
parent
6821e471c5
commit
25cc2864ff
@ -51,6 +51,7 @@ import mozilla.components.service.glean.net.ConceptFetchHttpUploader
|
||||
import mozilla.components.support.base.facts.register
|
||||
import mozilla.components.support.base.log.Log
|
||||
import mozilla.components.support.base.log.logger.Logger
|
||||
import mozilla.components.support.base.log.sink.AndroidLogSink
|
||||
import mozilla.components.support.ktx.android.arch.lifecycle.addObservers
|
||||
import mozilla.components.support.ktx.android.content.isMainProcess
|
||||
import mozilla.components.support.ktx.android.content.runOnlyInMainProcess
|
||||
@ -214,7 +215,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
|
||||
setupCrashReporting()
|
||||
|
||||
// We want the log messages of all builds to go to Android logcat
|
||||
Log.addSink(FenixLogSink(logsDebug = Config.channel.isDebug))
|
||||
Log.addSink(FenixLogSink(logsDebug = Config.channel.isDebug, AndroidLogSink()))
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -12,10 +12,12 @@ import mozilla.components.support.base.log.sink.LogSink
|
||||
* Fenix [LogSink] implementation that writes to Android's log, depending on settings.
|
||||
*
|
||||
* @param logsDebug If set to false, removes logging of debug logs.
|
||||
* @param androidLogSink an [AndroidLogSink] that writes to Android's log.
|
||||
*/
|
||||
class FenixLogSink(private val logsDebug: Boolean = true) : LogSink {
|
||||
|
||||
private val androidLogSink = AndroidLogSink()
|
||||
class FenixLogSink(
|
||||
private val logsDebug: Boolean = true,
|
||||
private val androidLogSink: LogSink,
|
||||
) : LogSink {
|
||||
|
||||
override fun log(
|
||||
priority: Log.Priority,
|
||||
|
@ -4,78 +4,99 @@
|
||||
|
||||
package org.mozilla.fenix
|
||||
|
||||
import android.util.Log
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.spyk
|
||||
import io.mockk.verify
|
||||
import org.junit.After
|
||||
import mozilla.components.support.base.log.sink.AndroidLogSink
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
class FenixLogSinkTest {
|
||||
|
||||
private lateinit var androidLogSink: AndroidLogSink
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
mockkStatic(Log::class)
|
||||
}
|
||||
|
||||
@After
|
||||
fun teardown() {
|
||||
unmockkStatic(Log::class)
|
||||
androidLogSink = spyk(AndroidLogSink())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN we're in a release build WHEN we log debug statements THEN logs should not be forwarded`() {
|
||||
val logSink = FenixLogSink(false)
|
||||
val logSink = FenixLogSink(false, androidLogSink)
|
||||
logSink.log(
|
||||
mozilla.components.support.base.log.Log.Priority.DEBUG,
|
||||
"test",
|
||||
message = "test",
|
||||
)
|
||||
verify(exactly = 0) { Log.println(Log.DEBUG, "test", "test") }
|
||||
verify(exactly = 0) { androidLogSink.log(any(), any(), any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN we're in a release build WHEN we log error statements THEN logs should be forwarded`() {
|
||||
val logSink = FenixLogSink(false)
|
||||
val logSink = FenixLogSink(false, androidLogSink)
|
||||
logSink.log(
|
||||
mozilla.components.support.base.log.Log.Priority.ERROR,
|
||||
"test",
|
||||
message = "test",
|
||||
)
|
||||
verify(exactly = 1) { Log.println(Log.ERROR, "test", "test") }
|
||||
|
||||
verify(exactly = 1) {
|
||||
androidLogSink.log(
|
||||
mozilla.components.support.base.log.Log.Priority.ERROR,
|
||||
"test",
|
||||
message = "test",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN we're in a release build WHEN we log warn statements THEN logs should be forwarded`() {
|
||||
val logSink = FenixLogSink(false)
|
||||
val logSink = FenixLogSink(false, androidLogSink)
|
||||
logSink.log(
|
||||
mozilla.components.support.base.log.Log.Priority.WARN,
|
||||
"test",
|
||||
message = "test",
|
||||
)
|
||||
verify(exactly = 1) { Log.println(Log.WARN, "test", "test") }
|
||||
verify(exactly = 1) {
|
||||
androidLogSink.log(
|
||||
mozilla.components.support.base.log.Log.Priority.WARN,
|
||||
"test",
|
||||
message = "test",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN we're in a release build WHEN we log info statements THEN logs should be forwarded`() {
|
||||
val logSink = FenixLogSink(false)
|
||||
val logSink = FenixLogSink(false, androidLogSink)
|
||||
logSink.log(
|
||||
mozilla.components.support.base.log.Log.Priority.INFO,
|
||||
"test",
|
||||
message = "test",
|
||||
)
|
||||
verify(exactly = 1) { Log.println(Log.INFO, "test", "test") }
|
||||
verify(exactly = 1) {
|
||||
androidLogSink.log(
|
||||
mozilla.components.support.base.log.Log.Priority.INFO,
|
||||
"test",
|
||||
message = "test",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN we're in a debug build WHEN we log debug statements THEN logs should be forwarded`() {
|
||||
val logSink = FenixLogSink(true)
|
||||
val logSink = FenixLogSink(true, androidLogSink)
|
||||
logSink.log(
|
||||
mozilla.components.support.base.log.Log.Priority.DEBUG,
|
||||
"test",
|
||||
message = "test",
|
||||
)
|
||||
verify(exactly = 1) { Log.println(Log.DEBUG, "test", "test") }
|
||||
|
||||
verify(exactly = 1) {
|
||||
androidLogSink.log(
|
||||
mozilla.components.support.base.log.Log.Priority.DEBUG,
|
||||
"test",
|
||||
message = "test",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user