Merge pull request #1275 from vector-im/feature/log_improvement
Log improvement for test
This commit is contained in:
commit
02e02ed691
|
@ -71,6 +71,15 @@ android {
|
|||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
androidTest {
|
||||
java.srcDirs += "src/sharedTest/java"
|
||||
}
|
||||
test {
|
||||
java.srcDirs += "src/sharedTest/java"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static def gitRevision() {
|
||||
|
@ -160,6 +169,8 @@ dependencies {
|
|||
testImplementation 'io.mockk:mockk:1.9.2.kotlin12'
|
||||
testImplementation 'org.amshove.kluent:kluent-android:1.44'
|
||||
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
|
||||
// Plant Timber tree for test
|
||||
testImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1'
|
||||
|
||||
androidTestImplementation 'androidx.test:core:1.2.0'
|
||||
androidTestImplementation 'androidx.test:runner:1.2.0'
|
||||
|
@ -171,5 +182,6 @@ dependencies {
|
|||
androidTestImplementation 'io.mockk:mockk-android:1.9.2.kotlin12'
|
||||
androidTestImplementation "androidx.arch.core:core-testing:$arch_version"
|
||||
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
|
||||
|
||||
// Plant Timber tree for test
|
||||
androidTestImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1'
|
||||
}
|
||||
|
|
|
@ -18,10 +18,15 @@ package im.vector.matrix.android
|
|||
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import im.vector.matrix.android.test.shared.createTimberTestRule
|
||||
import org.junit.Rule
|
||||
import java.io.File
|
||||
|
||||
interface InstrumentedTest {
|
||||
|
||||
@Rule
|
||||
fun timberTestRule() = createTimberTestRule()
|
||||
|
||||
fun context(): Context {
|
||||
return ApplicationProvider.getApplicationContext()
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ import kotlinx.coroutines.runBlocking
|
|||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import timber.log.Timber
|
||||
import java.util.ArrayList
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
@ -59,8 +58,6 @@ class CommonTestHelper(context: Context) {
|
|||
val matrix: Matrix
|
||||
|
||||
init {
|
||||
Timber.plant(Timber.DebugTree())
|
||||
|
||||
Matrix.initialize(context, MatrixConfiguration("TestFlavor"))
|
||||
|
||||
matrix = Matrix.getInstance(context)
|
||||
|
|
|
@ -20,7 +20,6 @@ package im.vector.matrix.android.internal.network.interceptors
|
|||
import im.vector.matrix.android.internal.di.MatrixScope
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import okio.Buffer
|
||||
import timber.log.Timber
|
||||
import java.io.IOException
|
||||
|
@ -37,7 +36,7 @@ import javax.inject.Inject
|
|||
* non-production environment.
|
||||
*/
|
||||
@MatrixScope
|
||||
internal class CurlLoggingInterceptor @Inject constructor(private val logger: HttpLoggingInterceptor.Logger)
|
||||
internal class CurlLoggingInterceptor @Inject constructor()
|
||||
: Interceptor {
|
||||
|
||||
/**
|
||||
|
@ -97,8 +96,8 @@ internal class CurlLoggingInterceptor @Inject constructor(private val logger: Ht
|
|||
// Add Json formatting
|
||||
curlCmd += " | python -m json.tool"
|
||||
|
||||
logger.log("--- cURL (" + request.url + ")")
|
||||
logger.log(curlCmd)
|
||||
Timber.d("--- cURL (${request.url})")
|
||||
Timber.d(curlCmd)
|
||||
|
||||
return chain.proceed(request)
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ internal object NetworkModule {
|
|||
@Provides
|
||||
@JvmStatic
|
||||
fun providesCurlLoggingInterceptor(): CurlLoggingInterceptor {
|
||||
return CurlLoggingInterceptor(HttpLoggingInterceptor.Logger.DEFAULT)
|
||||
return CurlLoggingInterceptor()
|
||||
}
|
||||
|
||||
@MatrixScope
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.matrix.android.internal.eventbus
|
||||
|
||||
import org.greenrobot.eventbus.Logger
|
||||
import timber.log.Timber
|
||||
import java.util.logging.Level
|
||||
|
||||
class EventBusTimberLogger : Logger {
|
||||
override fun log(level: Level, msg: String) {
|
||||
Timber.d(msg)
|
||||
}
|
||||
|
||||
override fun log(level: Level, msg: String, th: Throwable) {
|
||||
Timber.e(th, msg)
|
||||
}
|
||||
}
|
|
@ -49,6 +49,7 @@ import im.vector.matrix.android.internal.di.SessionId
|
|||
import im.vector.matrix.android.internal.di.Unauthenticated
|
||||
import im.vector.matrix.android.internal.di.UserId
|
||||
import im.vector.matrix.android.internal.di.UserMd5
|
||||
import im.vector.matrix.android.internal.eventbus.EventBusTimberLogger
|
||||
import im.vector.matrix.android.internal.network.AccessTokenInterceptor
|
||||
import im.vector.matrix.android.internal.network.DefaultNetworkConnectivityChecker
|
||||
import im.vector.matrix.android.internal.network.FallbackNetworkCallbackStrategy
|
||||
|
@ -205,7 +206,10 @@ internal abstract class SessionModule {
|
|||
@Provides
|
||||
@SessionScope
|
||||
fun providesEventBus(): EventBus {
|
||||
return EventBus.builder().build()
|
||||
return EventBus
|
||||
.builder()
|
||||
.logger(EventBusTimberLogger())
|
||||
.build()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
|
|
@ -74,7 +74,6 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters)
|
|||
it.state = PusherState.FAILED_TO_REGISTER
|
||||
}
|
||||
}
|
||||
// always return success, or the chain will be stuck for ever!
|
||||
Result.failure()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package im.vector.matrix.android.internal.network.interceptors
|
|||
import im.vector.matrix.android.internal.di.MatrixScope
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -28,7 +27,7 @@ import javax.inject.Inject
|
|||
* No op interceptor
|
||||
*/
|
||||
@MatrixScope
|
||||
internal class CurlLoggingInterceptor @Inject constructor(private val logger: HttpLoggingInterceptor.Logger)
|
||||
internal class CurlLoggingInterceptor @Inject constructor()
|
||||
: Interceptor {
|
||||
|
||||
@Throws(IOException::class)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.matrix.android.test.shared
|
||||
|
||||
import net.lachlanmckee.timberjunit.TimberTestRule
|
||||
|
||||
fun createTimberTestRule(): TimberTestRule {
|
||||
return TimberTestRule.builder()
|
||||
.showThread(false)
|
||||
.showTimestamp(false)
|
||||
.onlyLogWhenTestFails(false)
|
||||
.build()
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.matrix.android
|
||||
|
||||
import im.vector.matrix.android.test.shared.createTimberTestRule
|
||||
import org.junit.Rule
|
||||
|
||||
interface MatrixTest {
|
||||
|
||||
@Rule
|
||||
fun timberTestRule() = createTimberTestRule()
|
||||
}
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package im.vector.matrix.android.api.pushrules
|
||||
|
||||
import im.vector.matrix.android.MatrixTest
|
||||
import im.vector.matrix.android.api.pushrules.rest.PushRule
|
||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||
import org.junit.Assert.assertEquals
|
||||
|
@ -23,7 +24,7 @@ import org.junit.Assert.assertNotNull
|
|||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class PushRuleActionsTest {
|
||||
class PushRuleActionsTest: MatrixTest {
|
||||
|
||||
@Test
|
||||
fun test_action_parsing() {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package im.vector.matrix.android.api.pushrules
|
||||
|
||||
import im.vector.matrix.android.MatrixTest
|
||||
import im.vector.matrix.android.api.session.events.model.Event
|
||||
import im.vector.matrix.android.api.session.events.model.toContent
|
||||
import im.vector.matrix.android.api.session.room.Room
|
||||
|
@ -30,7 +31,7 @@ import org.junit.Assert.assertFalse
|
|||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class PushrulesConditionTest {
|
||||
class PushrulesConditionTest: MatrixTest {
|
||||
|
||||
/* ==========================================================================================
|
||||
* Test EventMatchCondition
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package im.vector.matrix.android.internal.crypto.keysbackup.util
|
||||
|
||||
import im.vector.matrix.android.MatrixTest
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.FixMethodOrder
|
||||
|
@ -23,7 +24,7 @@ import org.junit.Test
|
|||
import org.junit.runners.MethodSorters
|
||||
|
||||
@FixMethodOrder(MethodSorters.JVM)
|
||||
class Base58Test {
|
||||
class Base58Test: MatrixTest {
|
||||
|
||||
@Test
|
||||
fun encode() {
|
||||
|
|
|
@ -16,13 +16,15 @@
|
|||
|
||||
package im.vector.matrix.android.internal.crypto.keysbackup.util
|
||||
|
||||
import im.vector.matrix.android.MatrixTest
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class RecoveryKeyTest {
|
||||
class RecoveryKeyTest: MatrixTest {
|
||||
|
||||
private val curve25519Key = byteArrayOf(
|
||||
0x77.toByte(), 0x07.toByte(), 0x6D.toByte(), 0x0A.toByte(), 0x73.toByte(), 0x18.toByte(), 0xA5.toByte(), 0x7D.toByte(),
|
||||
0x3C.toByte(), 0x16.toByte(), 0xC1.toByte(), 0x72.toByte(), 0x51.toByte(), 0xB2.toByte(), 0x66.toByte(), 0x45.toByte(),
|
||||
|
|
|
@ -16,11 +16,12 @@
|
|||
|
||||
package im.vector.matrix.android.internal.crypto.store.db
|
||||
|
||||
import im.vector.matrix.android.MatrixTest
|
||||
import im.vector.matrix.android.internal.util.md5
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class HelperTest {
|
||||
class HelperTest: MatrixTest {
|
||||
|
||||
@Test
|
||||
fun testHash_ok() {
|
||||
|
|
|
@ -16,13 +16,14 @@
|
|||
|
||||
package im.vector.matrix.android.internal.crypto.verification.qrcode
|
||||
|
||||
import im.vector.matrix.android.MatrixTest
|
||||
import org.amshove.kluent.shouldEqualTo
|
||||
import org.junit.FixMethodOrder
|
||||
import org.junit.Test
|
||||
import org.junit.runners.MethodSorters
|
||||
|
||||
@FixMethodOrder(MethodSorters.JVM)
|
||||
class BinaryStringTest {
|
||||
class BinaryStringTest: MatrixTest {
|
||||
|
||||
/**
|
||||
* I want to put bytes to a String, and vice versa
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package im.vector.matrix.android.internal.task
|
||||
|
||||
import im.vector.matrix.android.MatrixTest
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import kotlinx.coroutines.delay
|
||||
|
@ -26,7 +27,7 @@ import org.junit.Assert.assertEquals
|
|||
import org.junit.Test
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class CoroutineSequencersTest {
|
||||
class CoroutineSequencersTest: MatrixTest {
|
||||
|
||||
private val dispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
||||
|
||||
|
|
Loading…
Reference in New Issue