Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit 7df8c2c

Browse files
author
Fran Montiel
committed
Merge branch 'master' into feature/error-management-improvements
2 parents 7d7899b + 94570de commit 7df8c2c

File tree

19 files changed

+478
-54
lines changed

19 files changed

+478
-54
lines changed

gradle.properties

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ android.enableJetifier=true
2020

2121
# fixing issue with not be able to load the project within Intellij IDEA because an issue with Android Studio
2222
android.injected.studio.version.check=false
23+
24+
kotlin.mpp.enableGranularSourceSetsMetadata=true
25+
kotlin.native.enableDependencyPropagation=false

harmony-kotlin/build.gradle

+21-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ android {
2929
defaultConfig {
3030
minSdkVersion android_min_sdk_version
3131
compileSdkVersion android_compile_sdk_version
32-
33-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
32+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3433
}
3534

3635
sourceSets {
@@ -41,14 +40,20 @@ android {
4140
res.srcDirs = ['src/androidMain/res']
4241
}
4342
test {
43+
manifest.srcFile 'src/androidMain/AndroidManifest.xml'
4444
java.srcDirs = ['src/androidTest/kotlin']
45+
resources.srcDirs = ['src/androidTest/kotlin']
4546
}
4647
}
4748

4849
compileOptions {
4950
sourceCompatibility JavaVersion.VERSION_1_8
5051
targetCompatibility JavaVersion.VERSION_1_8
5152
}
53+
54+
testOptions {
55+
unitTests.includeAndroidResources = true
56+
}
5257
}
5358

5459
kotlin {
@@ -68,6 +73,14 @@ kotlin {
6873
jvm()
6974

7075
sourceSets {
76+
77+
all {
78+
languageSettings {
79+
optIn("kotlin.RequiresOptIn")
80+
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
81+
}
82+
}
83+
7184
commonMain {
7285
dependencies {
7386

@@ -153,15 +166,17 @@ kotlin {
153166

154167
androidTest {
155168
dependencies {
169+
implementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
156170
implementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
157171

158172
implementation "io.ktor:ktor-client-mock-jvm:$ktor_version"
159173

160174
// Instrumentation tests
161-
implementation 'androidx.test.ext:junit:1.1.3'
162-
implementation 'androidx.test:runner:1.4.0'
163-
implementation 'androidx.test:rules:1.4.0'
164-
implementation 'org.robolectric:robolectric:4.6.1'
175+
implementation("androidx.test:core:1.4.0")
176+
implementation("androidx.test:runner:1.4.0")
177+
implementation("androidx.test:rules:1.4.0")
178+
implementation 'androidx.test.ext:junit-ktx:1.1.3'
179+
implementation("org.robolectric:robolectric:4.7.1")
165180
}
166181
}
167182

harmony-kotlin/src/androidMain/kotlin/com/harmony/kotlin/common/Coroutines.kt

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.harmony.kotlin.common
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import kotlinx.coroutines.CoroutineScope
5+
import kotlinx.coroutines.ExperimentalCoroutinesApi
6+
import kotlinx.coroutines.test.runBlockingTest
7+
import org.junit.runner.RunWith
8+
import org.robolectric.annotation.Config
9+
10+
@RunWith(AndroidJUnit4::class)
11+
@Config(manifest = Config.NONE)
12+
actual abstract class BaseTest {
13+
14+
@OptIn(ExperimentalCoroutinesApi::class)
15+
actual fun <T> runTest(block: suspend CoroutineScope.() -> T) {
16+
runBlockingTest { block() }
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.harmony.kotlin.data.datasource.cache
2+
3+
import android.app.Application
4+
import androidx.test.core.app.ApplicationProvider
5+
import com.harmony.kotlin.data.datasource.database.CacheDatabase
6+
import com.squareup.sqldelight.android.AndroidSqliteDriver
7+
8+
actual fun cacheDatabaseTests(): CacheDatabase {
9+
val app = ApplicationProvider.getApplicationContext<Application>()
10+
val driver = AndroidSqliteDriver(CacheDatabase.Schema, app, "tests")
11+
return CacheDatabase(driver)
12+
}

harmony-kotlin/src/commonMain/kotlin/com.harmony.kotlin/common/Coroutines.kt

-3
This file was deleted.

harmony-kotlin/src/commonMain/kotlin/com.harmony.kotlin/data/datasource/cache/CacheSQLStorageDataSource.kt

+10-5
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ class CacheSQLStorageDataSource(private val database: CacheDatabase) : GetDataSo
3030
database.cacheQueries.selectAll().executeAsList()
3131
}
3232
is KeyQuery -> {
33-
val sql = "${query.key}-%"
34-
database.cacheQueries.value(sql).executeAsList()
33+
database.cacheQueries.value(listSQLQuery(query)).executeAsList()
3534
}
3635
else -> notSupportedQuery()
3736
}
@@ -53,16 +52,18 @@ class CacheSQLStorageDataSource(private val database: CacheDatabase) : GetDataSo
5352
}
5453

5554
override suspend fun putAll(query: Query, value: List<ByteArray>?): List<ByteArray> {
56-
return when (query) {
55+
when (query) {
5756
is KeyQuery -> {
5857
value?.let {
5958
database.transaction {
59+
// delete the current content, because we can't update it as we store it by indexes instead of the whole context
60+
database.cacheQueries.delete(listSQLQuery(query))
6061
it.forEachIndexed { idx, raw ->
61-
database.cacheQueries.insertOrUpdate("${query.key}-$idx", raw)
62+
database.cacheQueries.insertOrUpdate(listSQLKey(query, idx), raw)
6263
}
6364
}
6465
return it
65-
} ?: emptyList<ByteArray>()
66+
} ?: throw IllegalArgumentException("values != null")
6667
}
6768
else -> notSupportedQuery()
6869
}
@@ -74,9 +75,13 @@ class CacheSQLStorageDataSource(private val database: CacheDatabase) : GetDataSo
7475
database.cacheQueries.deleteAll()
7576
}
7677
is KeyQuery -> {
78+
database.cacheQueries.delete(listSQLQuery(query))
7779
database.cacheQueries.delete(query.key)
7880
}
7981
else -> notSupportedQuery()
8082
}
8183
}
84+
85+
private fun listSQLQuery(query: KeyQuery) = "harmony-generated-${query.key}-%"
86+
private fun listSQLKey(query: KeyQuery, idx: Int) = "harmony-generated-${query.key}-$idx"
8287
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.harmony.kotlin.common
2+
3+
import kotlinx.coroutines.CoroutineScope
4+
5+
expect abstract class BaseTest() {
6+
fun <T> runTest(block: suspend CoroutineScope.() -> T)
7+
}

0 commit comments

Comments
 (0)