-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: replace logging implementation when unit testing EventsBuilder
Fixes "Method d in android.util.Log not mocked"
- Loading branch information
Showing
3 changed files
with
30 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,32 @@ | ||
package com.parsely.parselyandroid | ||
|
||
import android.util.Log | ||
import android.util.Log as AndroidLog | ||
|
||
internal object Log { | ||
internal object AndroidLogWrapper : Log { | ||
|
||
fun i(message: String) { | ||
Log.i("Parsely", message) | ||
override fun i(message: String) { | ||
AndroidLog.i("Parsely", message) | ||
} | ||
|
||
fun d(message: String) { | ||
Log.d("Parsely", message) | ||
override fun d(message: String) { | ||
AndroidLog.d("Parsely", message) | ||
} | ||
|
||
fun e(message: String, throwable: Throwable? = null) { | ||
Log.e("Parsely", message, throwable) | ||
override fun e(message: String, throwable: Throwable?) { | ||
AndroidLog.e("Parsely", message, throwable) | ||
} | ||
} | ||
|
||
internal interface Log { | ||
fun i(message: String) | ||
fun d(message: String) | ||
fun e(message: String, throwable: Throwable?) | ||
|
||
companion object { | ||
var instance: Log = AndroidLogWrapper | ||
|
||
fun i(message: String) = instance.i(message) | ||
fun d(message: String) = instance.d(message) | ||
fun e(message: String, throwable: Throwable? = null) = instance.e(message, throwable) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ internal class EventsBuilderTest { | |
TEST_SITE_ID, | ||
clock | ||
) | ||
Log.instance = FakeLog | ||
} | ||
|
||
@Test | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.parsely.parselyandroid | ||
|
||
internal object FakeLog : Log { | ||
override fun i(message: String) = println(message) | ||
override fun d(message: String) = println(message) | ||
override fun e(message: String, throwable: Throwable?) = println(message + throwable?.message) | ||
} |