Skip to content

Commit 3a5292e

Browse files
refactor: Migrate Internal Config class to kotlin
1 parent 38adc3c commit 3a5292e

File tree

8 files changed

+1539
-1488
lines changed

8 files changed

+1539
-1488
lines changed

android-core/src/androidTest/kotlin/com.mparticle/MParticleTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,19 @@ class MParticleTest : BaseCleanStartedEachTest() {
229229
startMParticle()
230230
MParticle.getInstance()!!.Messaging().enablePushNotifications(senderId)
231231
var fetchedSenderId: String? =
232-
MParticle.getInstance()!!.mInternal.getConfigManager().getPushSenderId()
232+
MParticle.getInstance()!!.mInternal.getConfigManager().pushSenderId
233233
Assert.assertTrue(
234-
MParticle.getInstance()!!.mInternal.getConfigManager().isPushEnabled() ?: false
234+
MParticle.getInstance()!!.mInternal.getConfigManager().isPushEnabled ?: false
235235
)
236236
Assert.assertEquals(senderId, fetchedSenderId)
237237
val otherSenderId = "senderIdLogPushRegistration"
238238
MParticle.getInstance()!!.logPushRegistration("instanceId", otherSenderId)
239-
fetchedSenderId = MParticle.getInstance()!!.mInternal.getConfigManager().getPushSenderId()
239+
fetchedSenderId = MParticle.getInstance()!!.mInternal.getConfigManager().pushSenderId
240240
Assert.assertEquals(otherSenderId, fetchedSenderId)
241241
MParticle.getInstance()!!.Messaging().disablePushNotifications()
242-
fetchedSenderId = MParticle.getInstance()!!.mInternal.getConfigManager().getPushSenderId()
242+
fetchedSenderId = MParticle.getInstance()!!.mInternal.getConfigManager().pushSenderId
243243
Assert.assertFalse(
244-
MParticle.getInstance()!!.mInternal.getConfigManager().isPushEnabled() ?: false
244+
MParticle.getInstance()!!.mInternal.getConfigManager().isPushEnabled ?: false
245245
)
246246
Assert.assertNull(fetchedSenderId)
247247
}
@@ -342,7 +342,7 @@ class MParticleTest : BaseCleanStartedEachTest() {
342342
Assert.assertTrue(databaseJson.getJSONArray("messages").length() > 0)
343343
Assert.assertEquals(6, allTables.size.toLong())
344344
Assert.assertTrue(
345-
10 < (MParticle.getInstance()!!.mInternal.getConfigManager().getMpids()?.size ?: 0)
345+
10 < (MParticle.getInstance()!!.mInternal.getConfigManager().mpids?.size ?: 0)
346346
)
347347

348348
// Set strict mode, so if we get any warning or error messages during the reset/restart phase,

android-core/src/androidTest/kotlin/com.mparticle/internal/ConfigManagerInstrumentedTest.kt

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,38 @@ class ConfigManagerInstrumentedTest : BaseAbstractTest() {
131131
val loadedKitLocal = AndroidUtils.Mutable(false)
132132
setCachedConfig(simpleConfigWithKits)
133133
mServer.setupConfigDeferred()
134-
val configLoadedListener = ConfigLoadedListener { configType, isNew ->
135-
if (!isNew) {
136-
when (configType) {
137-
ConfigType.CORE -> {
138-
if (loadedCoreLocal.value) {
139-
Assert.fail("core config already loaded")
140-
} else {
141-
Logger.error("LOADED CACHED Core")
142-
loadedCoreLocal.value = true
134+
val configLoadedListener = object : ConfigLoadedListener {
135+
override fun onConfigUpdated(configType: ConfigType, isNew: Boolean) {
136+
if (!isNew) {
137+
when (configType) {
138+
ConfigType.CORE -> {
139+
if (loadedCoreLocal.value) {
140+
Assert.fail("core config already loaded")
141+
} else {
142+
Logger.error("LOADED CACHED Core")
143+
loadedCoreLocal.value = true
144+
}
145+
if (loadedKitLocal.value) {
146+
Assert.fail("kit config already loaded")
147+
} else {
148+
Logger.error("LOADED CACHED Kit")
149+
loadedKitLocal.value = true
150+
}
143151
}
144-
if (loadedKitLocal.value) {
152+
153+
ConfigType.KIT -> if (loadedKitLocal.value) {
145154
Assert.fail("kit config already loaded")
146155
} else {
147156
Logger.error("LOADED CACHED Kit")
148157
loadedKitLocal.value = true
149158
}
150159
}
151-
ConfigType.KIT -> if (loadedKitLocal.value) {
152-
Assert.fail("kit config already loaded")
153-
} else {
154-
Logger.error("LOADED CACHED Kit")
155-
loadedKitLocal.value = true
156-
}
157160
}
161+
if (loadedCoreLocal.value && loadedKitLocal.value) {
162+
latch.countDown()
163+
}
164+
Logger.error("KIT = " + loadedKitLocal.value + " Core: " + loadedCoreLocal.value)
158165
}
159-
if (loadedCoreLocal.value && loadedKitLocal.value) {
160-
latch.countDown()
161-
}
162-
Logger.error("KIT = " + loadedKitLocal.value + " Core: " + loadedCoreLocal.value)
163166
}
164167
val options = MParticleOptions.builder(mContext)
165168
.credentials("key", "secret")

android-core/src/androidTest/kotlin/com.mparticle/internal/ConfigMigrationTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ class ConfigMigrationTest : BaseCleanInstallEachTest() {
124124
}
125125

126126
private fun setOldConfigState(config: JSONObject) {
127-
ConfigManager.getInstance(mContext).getKitConfigPreferences().edit()
128-
.remove(ConfigManager.KIT_CONFIG_KEY)
127+
ConfigManager.getInstance(mContext).kitConfigPreferences?.edit()
128+
?.remove(ConfigManager.KIT_CONFIG_KEY)
129129
ConfigManager.getPreferences(mContext).edit()
130130
.putString(oldConfigSharedprefsKey, config.toString()).apply()
131131
}
@@ -144,7 +144,7 @@ class ConfigMigrationTest : BaseCleanInstallEachTest() {
144144
assertNull(JSONObject(configString).optJSONArray(ConfigManager.KEY_EMBEDDED_KITS))
145145
assertEquals(
146146
config.optString(ConfigManager.KEY_EMBEDDED_KITS, JSONArray().toString()),
147-
ConfigManager.getInstance(mContext).kitConfigPreferences.getString(
147+
ConfigManager.getInstance(mContext).kitConfigPreferences?.getString(
148148
ConfigManager.KIT_CONFIG_KEY,
149149
JSONArray().toString()
150150
)

android-core/src/androidTest/kotlin/com.mparticle/internal/ConfigStalenessCheckTest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@ class ConfigStalenessCheckTest : BaseCleanInstallEachTest() {
189189
fun MParticleOptions.Builder.addCredentials() = this.credentials("apiKey", "apiSecret")
190190

191191
fun ConfigManager.onNewConfig(callback: () -> Unit) {
192-
addConfigUpdatedListener { configType, isNew ->
193-
if (isNew && configType == ConfigManager.ConfigType.CORE) {
194-
callback()
192+
addConfigUpdatedListener(object : ConfigManager.ConfigLoadedListener {
193+
override fun onConfigUpdated(configType: ConfigManager.ConfigType, isNew: Boolean) {
194+
if (isNew && configType == ConfigManager.ConfigType.CORE) {
195+
callback()
196+
}
195197
}
196-
}
198+
})
197199
}
198200
}

0 commit comments

Comments
 (0)