-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
256 additions
and
335 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
package testhelpers | ||
|
||
import androidx.test.core.app.ApplicationProvider | ||
import org.junit.runner.RunWith | ||
import org.matomo.sdk.Matomo | ||
import org.matomo.sdk.Matomo.Companion.getInstance | ||
import org.matomo.sdk.Tracker | ||
import org.robolectric.annotation.Config | ||
|
||
@Config(sdk = [19], manifest = Config.NONE) | ||
@RunWith(FullEnvTestRunner::class) | ||
abstract class DefaultTestCase : BaseTest() { | ||
fun createTracker(): Tracker { | ||
val app = ApplicationProvider.getApplicationContext<MatomoTestApplication>() | ||
val tracker = app.onCreateTrackerConfig().build(getInstance(ApplicationProvider.getApplicationContext())) | ||
tracker.preferences.edit().clear().apply() | ||
return tracker | ||
} | ||
|
||
val matomo: Matomo? | ||
get() = getInstance(ApplicationProvider.getApplicationContext()) | ||
} |
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
This file was deleted.
Oops, something went wrong.
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,25 @@ | ||
/* | ||
* Android SDK for Matomo | ||
* | ||
* @link https://github.com/matomo-org/matomo-android-sdk | ||
* @license https://github.com/matomo-org/matomo-sdk-android/blob/master/LICENSE BSD-3 Clause | ||
*/ | ||
package testhelpers | ||
|
||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.TestLifecycle | ||
import org.robolectric.util.inject.Injector | ||
|
||
/** | ||
* Tries to emulate a full app environment to satisfy more in-depth tests | ||
*/ | ||
@Suppress("unused") | ||
open class FullEnvTestRunner : RobolectricTestRunner { | ||
constructor(testClass: Class<*>?) : super(testClass) | ||
|
||
protected constructor(testClass: Class<*>?, injector: Injector?) : super(testClass, injector) | ||
|
||
override fun getTestLifecycleClass(): Class<out TestLifecycle<*>?> { | ||
return FullEnvTestLifeCycle::class.java | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
package testhelpers | ||
|
||
import android.util.Log | ||
import timber.log.Timber | ||
|
||
class JUnitTree : Timber.DebugTree() { | ||
private val minLogLevel = Log.VERBOSE | ||
|
||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { | ||
if (priority < minLogLevel) return | ||
println(System.currentTimeMillis().toString() + " " + priorityToString(priority) + "/" + tag + ": " + message) | ||
} | ||
|
||
companion object { | ||
private fun priorityToString(priority: Int): String { | ||
return when (priority) { | ||
Log.ERROR -> "E" | ||
Log.WARN -> "W" | ||
Log.INFO -> "I" | ||
Log.DEBUG -> "D" | ||
Log.VERBOSE -> "V" | ||
else -> priority.toString() | ||
} | ||
} | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
tracker/src/test/java/testhelpers/MatomoTestApplication.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
tracker/src/test/java/testhelpers/MatomoTestApplication.kt
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,33 @@ | ||
package testhelpers | ||
|
||
import org.matomo.sdk.TrackerBuilder | ||
import org.matomo.sdk.extra.MatomoApplication | ||
import org.robolectric.TestLifecycleApplication | ||
import org.robolectric.shadows.ShadowLog | ||
import java.lang.reflect.Method | ||
|
||
|
||
class MatomoTestApplication : MatomoApplication(), TestLifecycleApplication { | ||
override fun onCreate() { | ||
ShadowLog.stream = System.out | ||
super.onCreate() | ||
} | ||
|
||
override fun beforeTest(method: Method) { | ||
} | ||
|
||
override fun prepareTest(test: Any) { | ||
} | ||
|
||
override fun afterTest(method: Method) { | ||
} | ||
|
||
override fun getPackageName(): String { | ||
return "11" | ||
} | ||
|
||
|
||
override fun onCreateTrackerConfig(): TrackerBuilder { | ||
return TrackerBuilder.createDefault("http://example.com", 1) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
package testhelpers | ||
|
||
import org.matomo.sdk.QueryParams | ||
import org.matomo.sdk.TrackMe | ||
|
||
class QueryHashMap(trackMe: TrackMe) : HashMap<String?, String?>(trackMe.toMap()) { | ||
fun get(key: QueryParams): String? { | ||
return get(key.toString()) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
package testhelpers | ||
|
||
import android.app.Activity | ||
import android.os.Bundle | ||
|
||
class TestActivity : Activity() { | ||
public override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
title = testTitle | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
val testTitle: String | ||
get() = "Test Activity" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
package testhelpers | ||
|
||
import timber.log.Timber | ||
|
||
object TestHelper { | ||
@JvmStatic | ||
fun sleep(millis: Long) { | ||
try { | ||
Thread.sleep(millis) | ||
} catch (e: InterruptedException) { | ||
Timber.e(e) | ||
} | ||
} | ||
} |
Oops, something went wrong.