Loading modules/src/androidTest/java/app/lounge/PersistentStorageTest.kt +39 −2 Original line number Original line Diff line number Diff line Loading @@ -4,6 +4,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry import app.lounge.storage.cache.PersistedConfiguration import app.lounge.storage.cache.PersistedConfiguration import app.lounge.storage.cache.PersistenceKey import app.lounge.storage.cache.PersistenceKey import app.lounge.storage.cache.configurations import org.junit.Assert import org.junit.Assert import org.junit.Before import org.junit.Before import org.junit.Test import org.junit.Test Loading @@ -18,7 +19,7 @@ class PersistentStorageTest { @Before @Before fun setupPersistentConfiguration(){ fun setupPersistentConfiguration(){ val appContext = InstrumentationRegistry.getInstrumentation().targetContext val appContext = InstrumentationRegistry.getInstrumentation().targetContext testConfiguration = PersistedConfiguration(appContext) testConfiguration = appContext.configurations } } @Test @Test Loading @@ -35,9 +36,35 @@ class PersistentStorageTest { } } } } } } @Test fun testOnSetPersistentKeyReturnsSameExpectedValue() { PersistenceKey.values().toList().forEach { persistentKey -> val returnType: KClassifier? = testConfiguration.getPropertyReturnType(persistentKey.name) when(persistentKey) { PersistenceKey.updateInstallAuto -> testConfiguration.updateInstallAuto = testBooleanValue PersistenceKey.updateCheckIntervals -> testConfiguration.updateCheckIntervals = testIntValue PersistenceKey.updateAppsFromOtherStores -> testConfiguration.updateAppsFromOtherStores = testBooleanValue PersistenceKey.showAllApplications -> testConfiguration.showAllApplications = testBooleanValue PersistenceKey.showPWAApplications -> testConfiguration.showPWAApplications = testBooleanValue PersistenceKey.showFOSSApplications -> testConfiguration.showFOSSApplications = testBooleanValue PersistenceKey.authData -> testConfiguration.authData = testStringValue PersistenceKey.email -> testConfiguration.email = testStringValue PersistenceKey.oauthtoken -> testConfiguration.oauthtoken = testStringValue PersistenceKey.userType -> testConfiguration.userType = testStringValue PersistenceKey.tocStatus -> testConfiguration.tocStatus = testBooleanValue PersistenceKey.tosversion -> testConfiguration.tosversion = testStringValue } testConfiguration.evaluateValue(classifier = returnType, key = persistentKey) } } } } // Utils function for `Persistence` Testcase only // 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? = private inline fun <reified T> T.callMethod(name: String, vararg args: Any?): Any? = T::class T::class .members .members Loading @@ -50,3 +77,13 @@ private inline fun <reified T : Any> T.getPropertyReturnType(name: String): KCla .firstOrNull { it.name == name } .firstOrNull { it.name == name } ?.returnType ?.returnType ?.classifier ?.classifier private fun PersistedConfiguration.evaluateValue(classifier: KClassifier?, key: PersistenceKey) { when(classifier){ Int::class -> Assert.assertEquals( "Expected to be `$testIntValue`", testIntValue, this.callMethod(key.name) as Int) String::class -> Assert.assertEquals( "Expected to be `$testStringValue`", testStringValue, this.callMethod(key.name) as String) Boolean::class -> Assert.assertTrue( "Expected to be `$testBooleanValue`", this.callMethod(key.name) as Boolean) } } No newline at end of file modules/src/main/java/app/lounge/storage/cache/Persistence.kt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -12,7 +12,7 @@ val Context.configurations: PersistedConfiguration get() = PersistedConfiguratio // region - Persistence Configuration // region - Persistence Configuration enum class PersistenceKey { internal enum class PersistenceKey { updateInstallAuto, updateInstallAuto, updateCheckIntervals, updateCheckIntervals, updateAppsFromOtherStores, updateAppsFromOtherStores, Loading Loading
modules/src/androidTest/java/app/lounge/PersistentStorageTest.kt +39 −2 Original line number Original line Diff line number Diff line Loading @@ -4,6 +4,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry import app.lounge.storage.cache.PersistedConfiguration import app.lounge.storage.cache.PersistedConfiguration import app.lounge.storage.cache.PersistenceKey import app.lounge.storage.cache.PersistenceKey import app.lounge.storage.cache.configurations import org.junit.Assert import org.junit.Assert import org.junit.Before import org.junit.Before import org.junit.Test import org.junit.Test Loading @@ -18,7 +19,7 @@ class PersistentStorageTest { @Before @Before fun setupPersistentConfiguration(){ fun setupPersistentConfiguration(){ val appContext = InstrumentationRegistry.getInstrumentation().targetContext val appContext = InstrumentationRegistry.getInstrumentation().targetContext testConfiguration = PersistedConfiguration(appContext) testConfiguration = appContext.configurations } } @Test @Test Loading @@ -35,9 +36,35 @@ class PersistentStorageTest { } } } } } } @Test fun testOnSetPersistentKeyReturnsSameExpectedValue() { PersistenceKey.values().toList().forEach { persistentKey -> val returnType: KClassifier? = testConfiguration.getPropertyReturnType(persistentKey.name) when(persistentKey) { PersistenceKey.updateInstallAuto -> testConfiguration.updateInstallAuto = testBooleanValue PersistenceKey.updateCheckIntervals -> testConfiguration.updateCheckIntervals = testIntValue PersistenceKey.updateAppsFromOtherStores -> testConfiguration.updateAppsFromOtherStores = testBooleanValue PersistenceKey.showAllApplications -> testConfiguration.showAllApplications = testBooleanValue PersistenceKey.showPWAApplications -> testConfiguration.showPWAApplications = testBooleanValue PersistenceKey.showFOSSApplications -> testConfiguration.showFOSSApplications = testBooleanValue PersistenceKey.authData -> testConfiguration.authData = testStringValue PersistenceKey.email -> testConfiguration.email = testStringValue PersistenceKey.oauthtoken -> testConfiguration.oauthtoken = testStringValue PersistenceKey.userType -> testConfiguration.userType = testStringValue PersistenceKey.tocStatus -> testConfiguration.tocStatus = testBooleanValue PersistenceKey.tosversion -> testConfiguration.tosversion = testStringValue } testConfiguration.evaluateValue(classifier = returnType, key = persistentKey) } } } } // Utils function for `Persistence` Testcase only // 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? = private inline fun <reified T> T.callMethod(name: String, vararg args: Any?): Any? = T::class T::class .members .members Loading @@ -50,3 +77,13 @@ private inline fun <reified T : Any> T.getPropertyReturnType(name: String): KCla .firstOrNull { it.name == name } .firstOrNull { it.name == name } ?.returnType ?.returnType ?.classifier ?.classifier private fun PersistedConfiguration.evaluateValue(classifier: KClassifier?, key: PersistenceKey) { when(classifier){ Int::class -> Assert.assertEquals( "Expected to be `$testIntValue`", testIntValue, this.callMethod(key.name) as Int) String::class -> Assert.assertEquals( "Expected to be `$testStringValue`", testStringValue, this.callMethod(key.name) as String) Boolean::class -> Assert.assertTrue( "Expected to be `$testBooleanValue`", this.callMethod(key.name) as Boolean) } } No newline at end of file
modules/src/main/java/app/lounge/storage/cache/Persistence.kt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -12,7 +12,7 @@ val Context.configurations: PersistedConfiguration get() = PersistedConfiguratio // region - Persistence Configuration // region - Persistence Configuration enum class PersistenceKey { internal enum class PersistenceKey { updateInstallAuto, updateInstallAuto, updateCheckIntervals, updateCheckIntervals, updateAppsFromOtherStores, updateAppsFromOtherStores, Loading