Loading modules/build.gradle +4 −2 Original line number Diff line number Diff line Loading @@ -7,6 +7,8 @@ ext { android_compile_sdk_version = 33 android_target_sdk_version = 33 core_version = '1.10.1' gson_version = '2.9.0' kotlin_reflection = '1.8.10' } android { Loading Loading @@ -39,10 +41,10 @@ android { dependencies { implementation "androidx.core:core-ktx:$core_version" implementation 'androidx.appcompat:appcompat:1.6.1' implementation "com.google.code.gson:gson:$gson_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_reflection" testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' implementation "org.jetbrains.kotlin:kotlin-reflect:1.8.10" } No newline at end of file modules/src/androidTest/java/app/lounge/PersistentStorageTest.kt +31 −4 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ import androidx.test.platform.app.InstrumentationRegistry import app.lounge.storage.cache.PersistedConfiguration import app.lounge.storage.cache.PersistenceKey import app.lounge.storage.cache.configurations import com.google.gson.Gson import org.junit.Assert import org.junit.Before import org.junit.Test Loading Loading @@ -58,12 +59,26 @@ class PersistentStorageTest { testConfiguration.evaluateValue(classifier = returnType, key = persistentKey) } } @Test fun testSetStringJsonReturnSerializedObject() { testConfiguration.authData = sampleTokensJson val result: String = testConfiguration.callMethod("authData") as String val expectedTokens = Tokens( aasToken = "ya29.a0AWY7Cknq6ueSCNVN6F7jB", ac2dmToken = "ABFEt1X6tnDsra6QUsjVsjIWz0T5F", authToken = "gXKyx_qC5EO64ECheZFonpJOtxbY") Assert.assertEquals( "Tokens should match with $expectedTokens", expectedTokens, result.toTokens() ) } } // Utils function for `Persistence` Testcase only private val testIntValue : Int = (1..10).random() private const val testStringValue: String = "quick brown fox jump over the lazy dog" private const val testBooleanValue: Boolean = true private inline fun <reified T> T.callMethod(name: String, vararg args: Any?): Any? = T::class Loading @@ -87,3 +102,15 @@ private fun PersistedConfiguration.evaluateValue(classifier: KClassifier?, key: "Expected to be `$testBooleanValue`", this.callMethod(key.name) as Boolean) } } // region test sample data for shared preference verification private val testIntValue : Int = (1..10).random() private const val testStringValue: String = "quick brown fox jump over the lazy dog" private const val testBooleanValue: Boolean = true private const val sampleTokensJson = "{\"aasToken\": \"ya29.a0AWY7Cknq6ueSCNVN6F7jB\"," + "\"ac2dmToken\": \"ABFEt1X6tnDsra6QUsjVsjIWz0T5F\"," + "\"authToken\": \"gXKyx_qC5EO64ECheZFonpJOtxbY\"}" data class Tokens(val aasToken: String, val ac2dmToken: String, val authToken: String) fun String.toTokens() = Gson().fromJson(this, Tokens::class.java) // endregion No newline at end of file Loading
modules/build.gradle +4 −2 Original line number Diff line number Diff line Loading @@ -7,6 +7,8 @@ ext { android_compile_sdk_version = 33 android_target_sdk_version = 33 core_version = '1.10.1' gson_version = '2.9.0' kotlin_reflection = '1.8.10' } android { Loading Loading @@ -39,10 +41,10 @@ android { dependencies { implementation "androidx.core:core-ktx:$core_version" implementation 'androidx.appcompat:appcompat:1.6.1' implementation "com.google.code.gson:gson:$gson_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_reflection" testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' implementation "org.jetbrains.kotlin:kotlin-reflect:1.8.10" } No newline at end of file
modules/src/androidTest/java/app/lounge/PersistentStorageTest.kt +31 −4 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ import androidx.test.platform.app.InstrumentationRegistry import app.lounge.storage.cache.PersistedConfiguration import app.lounge.storage.cache.PersistenceKey import app.lounge.storage.cache.configurations import com.google.gson.Gson import org.junit.Assert import org.junit.Before import org.junit.Test Loading Loading @@ -58,12 +59,26 @@ class PersistentStorageTest { testConfiguration.evaluateValue(classifier = returnType, key = persistentKey) } } @Test fun testSetStringJsonReturnSerializedObject() { testConfiguration.authData = sampleTokensJson val result: String = testConfiguration.callMethod("authData") as String val expectedTokens = Tokens( aasToken = "ya29.a0AWY7Cknq6ueSCNVN6F7jB", ac2dmToken = "ABFEt1X6tnDsra6QUsjVsjIWz0T5F", authToken = "gXKyx_qC5EO64ECheZFonpJOtxbY") Assert.assertEquals( "Tokens should match with $expectedTokens", expectedTokens, result.toTokens() ) } } // Utils function for `Persistence` Testcase only private val testIntValue : Int = (1..10).random() private const val testStringValue: String = "quick brown fox jump over the lazy dog" private const val testBooleanValue: Boolean = true private inline fun <reified T> T.callMethod(name: String, vararg args: Any?): Any? = T::class Loading @@ -87,3 +102,15 @@ private fun PersistedConfiguration.evaluateValue(classifier: KClassifier?, key: "Expected to be `$testBooleanValue`", this.callMethod(key.name) as Boolean) } } // region test sample data for shared preference verification private val testIntValue : Int = (1..10).random() private const val testStringValue: String = "quick brown fox jump over the lazy dog" private const val testBooleanValue: Boolean = true private const val sampleTokensJson = "{\"aasToken\": \"ya29.a0AWY7Cknq6ueSCNVN6F7jB\"," + "\"ac2dmToken\": \"ABFEt1X6tnDsra6QUsjVsjIWz0T5F\"," + "\"authToken\": \"gXKyx_qC5EO64ECheZFonpJOtxbY\"}" data class Tokens(val aasToken: String, val ac2dmToken: String, val authToken: String) fun String.toTokens() = Gson().fromJson(this, Tokens::class.java) // endregion No newline at end of file