Add Android test for EmojiDataSource
This commit is contained in:
parent
b4247c89e4
commit
9c8ff7de7f
|
@ -235,6 +235,15 @@ android {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = "1.8"
|
jvmTarget = "1.8"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
androidTest {
|
||||||
|
java.srcDirs += "src/sharedTest/java"
|
||||||
|
}
|
||||||
|
test {
|
||||||
|
java.srcDirs += "src/sharedTest/java"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -250,6 +259,7 @@ dependencies {
|
||||||
def daggerVersion = '2.25.4'
|
def daggerVersion = '2.25.4'
|
||||||
def autofill_version = "1.0.0"
|
def autofill_version = "1.0.0"
|
||||||
def work_version = '2.3.3'
|
def work_version = '2.3.3'
|
||||||
|
def arch_version = '2.1.0'
|
||||||
|
|
||||||
implementation project(":matrix-sdk-android")
|
implementation project(":matrix-sdk-android")
|
||||||
implementation project(":matrix-sdk-android-rx")
|
implementation project(":matrix-sdk-android-rx")
|
||||||
|
@ -378,10 +388,18 @@ dependencies {
|
||||||
// TESTS
|
// TESTS
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
testImplementation 'org.amshove.kluent:kluent-android:1.44'
|
testImplementation 'org.amshove.kluent:kluent-android:1.44'
|
||||||
|
// 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'
|
androidTestImplementation 'androidx.test:runner:1.2.0'
|
||||||
|
androidTestImplementation 'androidx.test:rules:1.2.0'
|
||||||
|
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||||
androidTestImplementation 'org.amshove.kluent:kluent-android:1.44'
|
androidTestImplementation 'org.amshove.kluent:kluent-android:1.44'
|
||||||
|
androidTestImplementation "androidx.arch.core:core-testing:$arch_version"
|
||||||
|
// Plant Timber tree for test
|
||||||
|
androidTestImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Gplay")) {
|
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Gplay")) {
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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.riotx
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import im.vector.riotx.test.shared.createTimberTestRule
|
||||||
|
import org.junit.Rule
|
||||||
|
|
||||||
|
interface InstrumentedTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
fun timberTestRule() = createTimberTestRule()
|
||||||
|
|
||||||
|
fun context(): Context {
|
||||||
|
return ApplicationProvider.getApplicationContext()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* 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.riotx.features.reactions.data
|
||||||
|
|
||||||
|
import im.vector.riotx.InstrumentedTest
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.FixMethodOrder
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.junit.runners.JUnit4
|
||||||
|
import org.junit.runners.MethodSorters
|
||||||
|
import kotlin.system.measureTimeMillis
|
||||||
|
|
||||||
|
@RunWith(JUnit4::class)
|
||||||
|
@FixMethodOrder(MethodSorters.JVM)
|
||||||
|
class EmojiDataSourceTest : InstrumentedTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun checkParsingTime() {
|
||||||
|
val time = measureTimeMillis {
|
||||||
|
EmojiDataSource(context().resources)
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue("Too long to parse", time < 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun checkNumberOfResult() {
|
||||||
|
val emojiDataSource = EmojiDataSource(context().resources)
|
||||||
|
|
||||||
|
assertEquals("Wrong number of emojis", 1545, emojiDataSource.rawData.emojis.size)
|
||||||
|
assertEquals("Wrong number of categories", 8, emojiDataSource.rawData.categories.size)
|
||||||
|
assertEquals("Wrong number of aliases", 57, emojiDataSource.rawData.aliases.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun searchTestEmptySearch() {
|
||||||
|
val emojiDataSource = EmojiDataSource(context().resources)
|
||||||
|
|
||||||
|
assertEquals("Empty search should return 1545 results", 1545, emojiDataSource.filterWith("").size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun searchTestNoResult() {
|
||||||
|
val emojiDataSource = EmojiDataSource(context().resources)
|
||||||
|
|
||||||
|
assertTrue("Should not have result", emojiDataSource.filterWith("noresult").isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun searchTestOneResult() {
|
||||||
|
val emojiDataSource = EmojiDataSource(context().resources)
|
||||||
|
|
||||||
|
assertEquals("Should have 1 result", 1, emojiDataSource.filterWith("france").size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun searchTestManyResult() {
|
||||||
|
val emojiDataSource = EmojiDataSource(context().resources)
|
||||||
|
|
||||||
|
assertTrue("Should have many result", emojiDataSource.filterWith("fra").size > 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testQuickReaction() {
|
||||||
|
val emojiDataSource = EmojiDataSource(context().resources)
|
||||||
|
|
||||||
|
assertEquals("Should have 8 quick reactions", 8, emojiDataSource.getQuickReactions().size)
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.riotx.test.shared
|
||||||
|
|
||||||
|
import net.lachlanmckee.timberjunit.TimberTestRule
|
||||||
|
|
||||||
|
fun createTimberTestRule(): TimberTestRule {
|
||||||
|
return TimberTestRule.builder()
|
||||||
|
.showThread(false)
|
||||||
|
.showTimestamp(false)
|
||||||
|
.onlyLogWhenTestFails(false)
|
||||||
|
.build()
|
||||||
|
}
|
Loading…
Reference in New Issue