From 8653c29af03b81a64d2eed832c6ac95b450fd591 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 21 Nov 2025 16:32:06 -0500 Subject: [PATCH 01/14] feat: Update Android Gradle plugin to 8.0.2 --- build.gradle | 19 ++++++++++++------- gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/AndroidManifest.xml | 3 +-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index c7cdce7..0259704 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ buildscript { - if (!project.hasProperty('version') || project.version == 'unspecified') { + ext.kotlin_version = '2.0.20' + if (!project.hasProperty('version') || project.version.equals('unspecified')) { project.version = '+' } @@ -9,15 +10,15 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.4.1' + classpath 'com.android.tools.build:gradle:8.1.4' classpath 'com.mparticle:android-kit-plugin:' + project.version - classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } plugins { id "org.sonarqube" version "3.5.0.2730" - id "org.jlleitschuh.gradle.ktlint" version "11.2.0" + id "org.jlleitschuh.gradle.ktlint" version "13.0.0" } sonarqube { @@ -29,16 +30,20 @@ sonarqube { } apply plugin: 'org.jlleitschuh.gradle.ktlint' -apply plugin: "kotlin-android" +apply plugin: 'kotlin-android' apply plugin: 'com.mparticle.kit' android { + namespace 'com.mparticle.kits.appboy' defaultConfig { minSdkVersion 21 } compileOptions { - sourceCompatibility 1.8 - targetCompatibility 1.8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + kotlinOptions { + jvmTarget = '17' } testOptions { unitTests.all { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661..e1bef7e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 2afcbba..c4e6c98 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -1,2 +1 @@ - + From c9fd7a4b81dfb33dc5b69512b8089bd3ff5eb755 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 12:03:51 -0500 Subject: [PATCH 02/14] Fix the lint issue --- build.gradle | 6 + .../kotlin/com/mparticle/kits/AppboyKit.kt | 296 +++++++--------- src/test/kotlin/com/braze/Braze.kt | 10 +- src/test/kotlin/com/braze/BrazeUser.kt | 24 +- .../{AppboyKitTest.kt => AppboyKitTests.kt} | 131 ++++---- .../com/mparticle/kits/BrazePurchase.kt | 4 +- .../com/mparticle/kits/TypeDetectionTests.kt | 23 +- .../com/mparticle/kits/mocks/MockAppboyKit.kt | 10 +- .../mparticle/kits/mocks/MockApplication.kt | 28 +- .../com/mparticle/kits/mocks/MockContext.kt | 318 ++++++------------ .../kits/mocks/MockContextApplication.kt | 14 +- .../mparticle/kits/mocks/MockCoreCallbacks.kt | 70 ++-- .../kits/mocks/MockKitConfiguration.kt | 24 +- .../kits/mocks/MockKitManagerImpl.kt | 35 +- .../com/mparticle/kits/mocks/MockResources.kt | 14 +- .../kits/mocks/MockSharedPreferences.kt | 6 +- .../com/mparticle/kits/mocks/MockUser.kt | 10 +- 17 files changed, 407 insertions(+), 616 deletions(-) rename src/test/kotlin/com/mparticle/kits/{AppboyKitTest.kt => AppboyKitTests.kt} (95%) diff --git a/build.gradle b/build.gradle index 0259704..2b2dbe7 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,9 @@ android { defaultConfig { minSdkVersion 21 } + buildFeatures { + buildConfig = true + } compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 @@ -45,6 +48,9 @@ android { kotlinOptions { jvmTarget = '17' } + lint { + abortOnError = false + } testOptions { unitTests.all { jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] diff --git a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt index 70ce4e2..1a53691 100644 --- a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt @@ -5,12 +5,15 @@ import android.app.Application.ActivityLifecycleCallbacks import android.content.Context import android.content.Intent import android.os.Handler -import android.util.Log import com.braze.Braze import com.braze.BrazeActivityLifecycleCallbackListener import com.braze.BrazeUser import com.braze.configuration.BrazeConfig -import com.braze.enums.* +import com.braze.enums.BrazeSdkMetadata +import com.braze.enums.Gender +import com.braze.enums.Month +import com.braze.enums.NotificationSubscriptionType +import com.braze.enums.SdkFlavor import com.braze.events.IValueCallback import com.braze.models.outgoing.BrazeProperties import com.braze.push.BrazeFirebaseMessagingService @@ -28,7 +31,12 @@ import com.mparticle.consent.ConsentState import com.mparticle.identity.MParticleUser import com.mparticle.internal.Logger import com.mparticle.kits.CommerceEventUtils.OnAttributeExtracted -import com.mparticle.kits.KitIntegration.* +import com.mparticle.kits.KitIntegration.AttributeListener +import com.mparticle.kits.KitIntegration.CommerceListener +import com.mparticle.kits.KitIntegration.EventListener +import com.mparticle.kits.KitIntegration.IdentityListener +import com.mparticle.kits.KitIntegration.PushListener +import com.mparticle.kits.KitIntegration.UserAttributeListener import org.json.JSONArray import org.json.JSONException import org.json.JSONObject @@ -40,8 +48,14 @@ import kotlin.collections.HashMap /** * mParticle client-side Appboy integration */ -open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, - KitIntegration.EventListener, PushListener, IdentityListener, KitIntegration.UserAttributeListener { +open class AppboyKit : + KitIntegration(), + AttributeListener, + CommerceListener, + KitIntegration.EventListener, + PushListener, + IdentityListener, + KitIntegration.UserAttributeListener { var enableTypeDetection = false var bundleCommerceEvents = false @@ -53,18 +67,13 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, private var forwardScreenViews = false private lateinit var updatedInstanceId: String - override fun getName() = NAME - - public override fun onKitCreate( - settings: Map, - context: Context - ): List? { + public override fun onKitCreate(settings: Map, context: Context): List? { val key = settings[APPBOY_KEY] require(!KitUtils.isEmpty(key)) { "Braze key is empty." } - //try to get endpoint from the host setting + // try to get endpoint from the host setting val authority = settings[HOST] if (!KitUtils.isEmpty(authority)) { setAuthority(authority) @@ -104,7 +113,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, queueDataFlush() if (setDefaultAppboyLifecycleCallbackListener) { (context.applicationContext as Application).registerActivityLifecycleCallbacks( - BrazeActivityLifecycleCallbackListener() as ActivityLifecycleCallbacks + BrazeActivityLifecycleCallbackListener() as ActivityLifecycleCallbacks, ) } setIdentityType(settings) @@ -135,16 +144,9 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, override fun leaveBreadcrumb(breadcrumb: String): List = emptyList() - override fun logError( - message: String, - errorAttributes: Map - ): List = emptyList() + override fun logError(message: String, errorAttributes: Map): List = emptyList() - override fun logException( - exception: Exception, - exceptionAttributes: Map, - message: String - ): List = emptyList() + override fun logException(exception: Exception, exceptionAttributes: Map, message: String): List = emptyList() override fun logEvent(event: MPEvent): List { val newAttributes: MutableMap = HashMap() @@ -189,42 +191,37 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, return listOf(ReportingMessage.fromEvent(this, event).setAttributes(newAttributes)) } - override fun logScreen( - screenName: String, - screenAttributes: Map? - ): List { - return if (forwardScreenViews) { - if (screenAttributes == null) { - Braze.getInstance(context).logCustomEvent(screenName) - } else { - val properties = BrazeProperties() - val propertyParser = BrazePropertiesSetter(properties, enableTypeDetection) - for ((key, value) in screenAttributes) { - propertyParser.parseValue(key, value) - } - Braze.getInstance(context).logCustomEvent(screenName, properties) - } - queueDataFlush() - val messages: MutableList = LinkedList() - messages.add( - ReportingMessage( - this, - ReportingMessage.MessageType.SCREEN_VIEW, - System.currentTimeMillis(), - screenAttributes - ) - ) - messages + override fun logScreen(screenName: String, screenAttributes: Map?): List = if (forwardScreenViews) { + if (screenAttributes == null) { + Braze.getInstance(context).logCustomEvent(screenName) } else { - emptyList() + val properties = BrazeProperties() + val propertyParser = BrazePropertiesSetter(properties, enableTypeDetection) + for ((key, value) in screenAttributes) { + propertyParser.parseValue(key, value) + } + Braze.getInstance(context).logCustomEvent(screenName, properties) } + queueDataFlush() + val messages: MutableList = LinkedList() + messages.add( + ReportingMessage( + this, + ReportingMessage.MessageType.SCREEN_VIEW, + System.currentTimeMillis(), + screenAttributes, + ), + ) + messages + } else { + emptyList() } override fun logLtvIncrease( valueIncreased: BigDecimal, valueTotal: BigDecimal, eventName: String, - contextInfo: Map + contextInfo: Map, ): List = emptyList() override fun logEvent(event: CommerceEvent): List { @@ -232,8 +229,9 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, if (!KitUtils.isEmpty(event.productAction) && event.productAction.equals( Product.PURCHASE, - true - ) && !event.products.isNullOrEmpty() + true, + ) && + !event.products.isNullOrEmpty() ) { if (bundleCommerceEvents) { logOrderLevelTransaction(event) @@ -318,8 +316,11 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, } DOB -> useDobString(attributeValue, value) UserAttributes.GENDER -> { - if (attributeValue.contains("fe")) value.setGender(Gender.FEMALE) - else value.setGender(Gender.MALE) + if (attributeValue.contains("fe")) { + value.setGender(Gender.FEMALE) + } else { + value.setGender(Gender.MALE) + } } else -> { if (subscriptionGroupIds?.containsKey(key) == true) { @@ -335,7 +336,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, else -> { Logger.warning( - "Unable to set Subscription Group ID for user attribute: $key due to invalid value data type. Expected Boolean." + "Unable to set Subscription Group ID for user attribute: $key due to invalid value data type. Expected Boolean.", ) } } @@ -364,7 +365,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, calendar.time = dateFormat.parse(value) as Date val year = calendar[Calendar.YEAR] val monthNum = calendar[Calendar.MONTH] - val month = Month.values()[monthNum]// + val month = Month.values()[monthNum] // val day = calendar[Calendar.DAY_OF_MONTH] user.setDateOfBirth(year, month, day) } catch (e: Exception) { @@ -386,12 +387,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, }) } - override fun onIncrementUserAttribute( - key: String?, - incrementedBy: Number?, - value: String?, - user: FilteredMParticleUser? - ) { + override fun onIncrementUserAttribute(key: String?, incrementedBy: Number?, value: String?, user: FilteredMParticleUser?) { } override fun onRemoveUserAttribute(key: String?, user: FilteredMParticleUser?) { @@ -403,33 +399,25 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, override fun onSetUserTag(key: String?, user: FilteredMParticleUser?) { } - override fun onSetUserAttributeList( - attributeKey: String?, - attributeValueList: MutableList?, - user: FilteredMParticleUser? - ) { + override fun onSetUserAttributeList(attributeKey: String?, attributeValueList: MutableList?, user: FilteredMParticleUser?) { } override fun onSetAllUserAttributes( userAttributes: MutableMap?, userAttributeLists: MutableMap>?, - user: FilteredMParticleUser? + user: FilteredMParticleUser?, ) { } override fun supportsAttributeLists(): Boolean = true - override fun onConsentStateUpdated( - oldState: ConsentState, - newState: ConsentState, - user: FilteredMParticleUser - ) { + override fun onConsentStateUpdated(oldState: ConsentState, newState: ConsentState, user: FilteredMParticleUser) { setConsent(newState) } private fun setConsent(consentState: ConsentState) { val clientConsentSettings = parseToNestedMap(consentState.toString()) - parseConsentMapping(settings[consentMappingSDK]).iterator().forEach { currentConsent -> + parseConsentMapping(settings[CONSENT_MAPPING_SDK]).iterator().forEach { currentConsent -> val isConsentAvailable = searchKeyInNestedMap(clientConsentSettings, key = currentConsent.key) @@ -439,13 +427,14 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, when (currentConsent.value) { "google_ad_user_data" -> setConsentValueToBraze( - KEY_GOOGLE_AD_USER_DATA, isConsentGranted + KEY_GOOGLE_AD_USER_DATA, + isConsentGranted, ) "google_ad_personalization" -> setConsentValueToBraze( - KEY_GOOGLE_AD_PERSONALIZATION, isConsentGranted + KEY_GOOGLE_AD_PERSONALIZATION, + isConsentGranted, ) - } } } @@ -481,7 +470,10 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, } } } catch (jse: JSONException) { - Logger.warning(jse, "The Braze kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status.") + Logger.warning( + jse, + "The Braze kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status.", + ) emptyMap() } } @@ -522,7 +514,10 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, } } } catch (e: Exception) { - Logger.error(e, "The Braze kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status.") + Logger.error( + e, + "The Braze kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status.", + ) } return null } @@ -535,10 +530,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, /** * This is called when the Kit is added to the mParticle SDK, typically on app-startup. */ - override fun setAllUserAttributes( - attributes: Map, - attributeLists: Map> - ) { + override fun setAllUserAttributes(attributes: Map, attributeLists: Map>) { if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) { for ((key, value) in attributes) { setUserAttribute(key, value) @@ -560,7 +552,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, value.setCountry(null) } else if (UserAttributes.FIRSTNAME == key) { value.setFirstName(null) - } //else if (UserAttributes.GENDER == key) { //Braze SDK wont allow for gender parameter to be null. + } // else if (UserAttributes.GENDER == key) { //Braze SDK wont allow for gender parameter to be null. // user.setGender(null)} else if (UserAttributes.LASTNAME == key) { value.setLastName(null) @@ -615,13 +607,11 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, } } - private fun checkCurrency(key: String, value: Any?): Boolean { - return if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { - currency[0] = value?.toString() - true - } else { - false - } + private fun checkCurrency(key: String, value: Any?): Boolean = if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { + currency[0] = value?.toString() + true + } else { + false } } CommerceEventUtils.extractActionAttributes(event, onAttributeExtracted) @@ -639,7 +629,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, product.couponCode?.let { purchaseProperties.addProperty( CommerceEventUtils.Constants.ATT_PRODUCT_COUPON_CODE, - it + it, ) } product.brand?.let { @@ -670,7 +660,6 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, } } catch (e: Exception) { Logger.error(e, "The Braze kit threw an exception while searching for forward sku as product name flag.") - } Braze.Companion.getInstance(context).logPurchase( @@ -678,7 +667,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, currencyValue, BigDecimal(product.unitPrice), product.quantity.toInt(), - purchaseProperties + purchaseProperties, ) } @@ -712,13 +701,11 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, } } - private fun checkCurrency(key: String, value: Any?): Boolean { - return if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { - currency[0] = value?.toString() - true - } else { - false - } + private fun checkCurrency(key: String, value: Any?): Boolean = if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { + currency[0] = value?.toString() + true + } else { + false } } CommerceEventUtils.extractActionAttributes(event, onAttributeExtracted) @@ -758,7 +745,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, currencyValue, event?.transactionAttributes?.revenue?.let { BigDecimal(it) } ?: BigDecimal(0), 1, - properties + properties, ) } else { if (!KitUtils.isEmpty(event?.productAction)) { @@ -774,30 +761,28 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, } } - override fun willHandlePushMessage(intent: Intent): Boolean { - return if (!(settings[PUSH_ENABLED].toBoolean())) { - false - } else intent.isBrazePushMessage() + override fun willHandlePushMessage(intent: Intent): Boolean = if (!(settings[PUSH_ENABLED].toBoolean())) { + false + } else { + intent.isBrazePushMessage() } override fun onPushMessageReceived(context: Context, pushIntent: Intent) { if (settings[PUSH_ENABLED].toBoolean()) { BrazeFirebaseMessagingService.handleBrazeRemoteMessage( context, - RemoteMessage(pushIntent.extras) + RemoteMessage(pushIntent.extras), ) } } - override fun onPushRegistration(instanceId: String, senderId: String): Boolean { - return if (settings[PUSH_ENABLED].toBoolean()) { - updatedInstanceId = instanceId - Braze.getInstance(context).registeredPushToken = instanceId - queueDataFlush() - true - } else { - false - } + override fun onPushRegistration(instanceId: String, senderId: String): Boolean = if (settings[PUSH_ENABLED].toBoolean()) { + updatedInstanceId = instanceId + Braze.getInstance(context).registeredPushToken = instanceId + queueDataFlush() + true + } else { + false } protected open fun setAuthority(authority: String?) { @@ -807,31 +792,19 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, } } - override fun onIdentifyCompleted( - mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest? - ) { + override fun onIdentifyCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { updateUser(mParticleUser) } - override fun onLoginCompleted( - mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest? - ) { + override fun onLoginCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { updateUser(mParticleUser) } - override fun onLogoutCompleted( - mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest? - ) { + override fun onLogoutCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { updateUser(mParticleUser) } - override fun onModifyCompleted( - mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest? - ) { + override fun onModifyCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { updateUser(mParticleUser) } @@ -842,15 +815,10 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, email?.let { setEmail(it) } } - fun getIdentity( - isMpidIdentityType: Boolean, - identityType: IdentityType?, - mParticleUser: MParticleUser? - ): String? { + fun getIdentity(isMpidIdentityType: Boolean, identityType: IdentityType?, mParticleUser: MParticleUser?): String? { var identity: String? = null if (isMpidIdentityType && mParticleUser != null) { identity = mParticleUser.id.toString() - } else if (identityType != null && mParticleUser != null) { identity = mParticleUser.userIdentities[identityType] } @@ -896,9 +864,10 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, fun addToProperties(properties: BrazeProperties, key: String, value: String) { try { - if ("true".equals(value, true) || "false".equals( + if ("true".equals(value, true) || + "false".equals( value, - true + true, ) ) { properties.addProperty(key, (value).toBoolean()) @@ -929,14 +898,12 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, return null } - fun getCalendarMinusYears(years: Int): Calendar? { - return if (years >= 0) { - val calendar = Calendar.getInstance() - calendar[Calendar.YEAR] = calendar[Calendar.YEAR] - years - calendar - } else { - null - } + fun getCalendarMinusYears(years: Int): Calendar? = if (years >= 0) { + val calendar = Calendar.getInstance() + calendar[Calendar.YEAR] = calendar[Calendar.YEAR] - years + calendar + } else { + null } fun getProductListParameters(productList: List): JSONArray { @@ -950,7 +917,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, product.couponCode?.let { productProperties.put( CommerceEventUtils.Constants.ATT_PRODUCT_COUPON_CODE, - it + it, ) } product.brand?.let { @@ -973,15 +940,15 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, } productProperties.put( CommerceEventUtils.Constants.ATT_PRODUCT_PRICE, - product.unitPrice + product.unitPrice, ) productProperties.put( CommerceEventUtils.Constants.ATT_PRODUCT_QUANTITY, - product.quantity + product.quantity, ) productProperties.put( CommerceEventUtils.Constants.ATT_PRODUCT_TOTAL_AMOUNT, - product.totalAmount + product.totalAmount, ) productArray.put(productProperties) @@ -996,7 +963,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, promotion.creative?.let { promotionProperties.put( CommerceEventUtils.Constants.ATT_PROMOTION_CREATIVE, - it + it, ) } promotion.id?.let { @@ -1008,7 +975,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, promotion.position?.let { promotionProperties.put( CommerceEventUtils.Constants.ATT_PROMOTION_POSITION, - it + it, ) } promotionArray.put(promotionProperties) @@ -1061,9 +1028,10 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, toString(key, value) return value } - return if (true.toString().equals(value, true) || false.toString().equals( + return if (true.toString().equals(value, true) || + false.toString().equals( value, - true + true, ) ) { val newBool = (value).toBoolean() @@ -1100,10 +1068,8 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, abstract fun toString(key: String, value: String) } - internal inner class BrazePropertiesSetter( - private var properties: BrazeProperties, - enableTypeDetection: Boolean - ) : StringTypeParser(enableTypeDetection) { + internal inner class BrazePropertiesSetter(private var properties: BrazeProperties, enableTypeDetection: Boolean) : + StringTypeParser(enableTypeDetection) { override fun toInt(key: String, value: Int) { properties.addProperty(key, value) } @@ -1125,10 +1091,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, } } - internal inner class UserAttributeSetter( - private var brazeUser: BrazeUser, - enableTypeDetection: Boolean - ) : StringTypeParser(enableTypeDetection) { + internal inner class UserAttributeSetter(private var brazeUser: BrazeUser, enableTypeDetection: Boolean) : StringTypeParser(enableTypeDetection) { override fun toInt(key: String, value: Int) { brazeUser.setCustomUserAttribute(key, value) } @@ -1160,6 +1123,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, const val HOST = "host" const val PUSH_ENABLED = "push_enabled" const val NAME = "Appboy" + // if this flag is true, kit will send Product name as sku const val REPLACE_SKU_AS_PRODUCT_NAME = "replaceSkuWithProductName" private const val PREF_KEY_HAS_SYNCED_ATTRIBUTES = "appboy::has_synced_attributes" @@ -1175,8 +1139,8 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, private const val UNSUBSCRIBED = "unsubscribed" private const val SUBSCRIBED = "subscribed" - //Constants for Read Consent - private const val consentMappingSDK = "consentMappingSDK" + // Constants for Read Consent + private const val CONSENT_MAPPING_SDK = "consentMappingSDK" private const val KEY_GOOGLE_AD_USER_DATA = "\$google_ad_user_data" private const val KEY_GOOGLE_AD_PERSONALIZATION = "\$google_ad_personalization" diff --git a/src/test/kotlin/com/braze/Braze.kt b/src/test/kotlin/com/braze/Braze.kt index e6fc4ed..4b2268b 100644 --- a/src/test/kotlin/com/braze/Braze.kt +++ b/src/test/kotlin/com/braze/Braze.kt @@ -9,13 +9,9 @@ import java.math.BigDecimal class Braze { - fun getCurrentUser(): BrazeUser { - return Companion.currentUser - } + fun getCurrentUser(): BrazeUser = Companion.currentUser - fun getCustomAttributeArray(): java.util.HashMap> { - return Companion.currentUser.getCustomAttribute() - } + fun getCustomAttributeArray(): java.util.HashMap> = Companion.currentUser.getCustomAttribute() fun getCurrentUser(callback: IValueCallback) { callback.onSuccess(currentUser) @@ -34,7 +30,7 @@ class Braze { currency: String, unitPrice: BigDecimal, quantity: Int, - purchaseProperties: BrazeProperties + purchaseProperties: BrazeProperties, ) { purchases.add(BrazePurchase(sku, currency, unitPrice, quantity, purchaseProperties)) } diff --git a/src/test/kotlin/com/braze/BrazeUser.kt b/src/test/kotlin/com/braze/BrazeUser.kt index 97be7cf..881a1d0 100644 --- a/src/test/kotlin/com/braze/BrazeUser.kt +++ b/src/test/kotlin/com/braze/BrazeUser.kt @@ -14,7 +14,7 @@ class BrazeUser { return true } - val customAttributeArray = HashMap >() + val customAttributeArray = HashMap>() val customUserAttributes = HashMap() fun addToCustomAttributeArray(key: String, value: String): Boolean { @@ -27,15 +27,13 @@ class BrazeUser { return true } - fun removeFromCustomAttributeArray(key: String, value: String): Boolean { - return try { - if (customAttributeArray.containsKey(key)) { - customAttributeArray.remove(key) - } - true - } catch (npe: NullPointerException) { - false + fun removeFromCustomAttributeArray(key: String, value: String): Boolean = try { + if (customAttributeArray.containsKey(key)) { + customAttributeArray.remove(key) } + true + } catch (npe: NullPointerException) { + false } fun setCustomUserAttribute(key: String, value: String): Boolean { @@ -68,11 +66,7 @@ class BrazeUser { return true } - fun getCustomAttribute(): HashMap> { - return customAttributeArray - } + fun getCustomAttribute(): HashMap> = customAttributeArray - fun getCustomUserAttribute(): HashMap { - return customUserAttributes - } + fun getCustomUserAttribute(): HashMap = customUserAttributes } diff --git a/src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt b/src/test/kotlin/com/mparticle/kits/AppboyKitTests.kt similarity index 95% rename from src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt rename to src/test/kotlin/com/mparticle/kits/AppboyKitTests.kt index 4df38c7..af0bf86 100644 --- a/src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt +++ b/src/test/kotlin/com/mparticle/kits/AppboyKitTests.kt @@ -61,11 +61,10 @@ class AppboyKitTests { MParticle.setInstance(Mockito.mock(MParticle::class.java)) Mockito.`when`(MParticle.getInstance()!!.Identity()).thenReturn( Mockito.mock( - IdentityApi::class.java - ) + IdentityApi::class.java, + ), ) braze = Braze - } @Test @@ -124,7 +123,7 @@ class AppboyKitTests { @Test @Throws(Exception::class) fun testHostSettingNull() { - //test that the key is set when it is passed in by the settings map + // test that the key is set when it is passed in by the settings map val missingSettings = HashMap() missingSettings[AppboyKit.APPBOY_KEY] = "key" val kit = MockAppboyKit() @@ -160,7 +159,7 @@ class AppboyKitTests { @Test fun testOnModify() { - //make sure it doesn't crash if there is no email or customerId + // make sure it doesn't crash if there is no email or customerId var e: Exception? = null try { AppboyKit().onModifyCompleted(MockUser(HashMap()), null) @@ -233,7 +232,7 @@ class AppboyKitTests { calendar?.get(Calendar.YEAR) ?.let { Assert.assertEquals((currentYear - 5).toLong(), it.toLong()) } - //invalid ages (negative, non numeric), don't get set + // invalid ages (negative, non numeric), don't get set Assert.assertNull(kit.getCalendarMinusYears("asdv")) Assert.assertNull(kit.getCalendarMinusYears(-1)) } @@ -244,16 +243,16 @@ class AppboyKitTests { settings[AppboyKit.APPBOY_KEY] = "key" settings[AppboyKit.HOST] = hostName settings["subscriptionGroupMapping"] = "" + - "[{\"jsmap\":null,\"map\":\"test1\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"00000000-0000-0000-0000-000000000000\"}," + - "{\"jsmap\":null,\"map\":\"test2\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"00000000-0000-0000-0000-000000000001\"}," + - "{\"jsmap\":null,\"map\":\"test3\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"00000000-0000-0000-0000-000000000002\"}]" + "[{\"jsmap\":null,\"map\":\"test1\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"00000000-0000-0000-0000-000000000000\"}," + + "{\"jsmap\":null,\"map\":\"test2\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"00000000-0000-0000-0000-000000000001\"}," + + "{\"jsmap\":null,\"map\":\"test3\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"00000000-0000-0000-0000-000000000002\"}]" val kit = MockAppboyKit() val currentUser = braze.currentUser kit.onKitCreate(settings, MockContextApplication()) - kit.setUserAttribute("test1", "true"); - kit.setUserAttribute("test2", "false"); - kit.setUserAttribute("test3", "notABoolean"); + kit.setUserAttribute("test1", "true") + kit.setUserAttribute("test2", "false") + kit.setUserAttribute("test3", "notABoolean") Assert.assertEquals(2, currentUser.getCustomUserAttribute().size.toLong()) } @@ -318,7 +317,7 @@ class AppboyKitTests { val possibleValues = arrayOf( "Other", "CustomerId", "Facebook", "Twitter", "Google", "Microsoft", - "Yahoo", "Email", "Alias" + "Yahoo", "Email", "Alias", ) val mpid = "MPID" for (`val` in possibleValues) { @@ -329,7 +328,7 @@ class AppboyKitTests { Assert.assertNotNull(kit.identityType) Assert.assertEquals( `val`.lowercase(Locale.getDefault()), - kit.identityType?.name?.lowercase(Locale.getDefault()) + kit.identityType?.name?.lowercase(Locale.getDefault()), ) Assert.assertFalse(kit.isMpidIdentityType) } @@ -479,52 +478,52 @@ class AppboyKitTests { Assert.assertEquals(properties.remove(CommerceEventUtils.Constants.ATT_SHIPPING), 12.0) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_ACTION_PRODUCT_LIST_SOURCE), - "the source" + "the source", ) Assert.assertEquals(properties.remove(CommerceEventUtils.Constants.ATT_TAX), 100.0) Assert.assertEquals(properties.remove(CommerceEventUtils.Constants.ATT_TOTAL), 99.0) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_ACTION_PRODUCT_ACTION_LIST), - "product list name" + "product list name", ) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_COUPON_CODE), - "coupon code" + "coupon code", ) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_TRANSACTION_ID), - "the id" + "the id", ) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_AFFILIATION), - "the affiliation" + "the affiliation", ) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_NAME), - "product name" + "product name", ) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_CATEGORY), - "testCategory" + "testCategory", ) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_BRAND), - "testBrand" + "testBrand", ) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_POSITION), - 1 + 1, ) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_VARIANT), - "testVariant" + "testVariant", ) - //Custom Attributes + // Custom Attributes Assert.assertEquals(properties.remove("key1"), "value1") Assert.assertEquals(properties.remove("key #2"), "value #3") - //Product Custom Attributes + // Product Custom Attributes Assert.assertEquals(properties.remove("productKey1"), "value1") Assert.assertEquals(properties.remove("productKey2"), "value2") @@ -575,23 +574,23 @@ class AppboyKitTests { val productProperties = productBrazeProperties.properties Assert.assertEquals( productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_TOTAL_AMOUNT), - 22.5 + 22.5, ) Assert.assertEquals( productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_PRICE), - 4.5 + 4.5, ) Assert.assertEquals( productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_QUANTITY), - 5.0 + 5.0, ) Assert.assertEquals( productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_ID), - "sku1" + "sku1", ) Assert.assertEquals( productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_NAME), - "product name" + "product name", ) Assert.assertEquals(emptyAttributes, productProperties) } @@ -600,24 +599,24 @@ class AppboyKitTests { Assert.assertEquals(properties.remove(CommerceEventUtils.Constants.ATT_TAX), 100.0) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_COUPON_CODE), - "coupon code" + "coupon code", ) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_AFFILIATION), - "the affiliation" + "the affiliation", ) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_ACTION_PRODUCT_LIST_SOURCE), - "the source" + "the source", ) Assert.assertEquals(properties.remove(CommerceEventUtils.Constants.ATT_TOTAL), 99.0) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_ACTION_PRODUCT_ACTION_LIST), - "product list name" + "product list name", ) Assert.assertEquals( properties.remove(CommerceEventUtils.Constants.ATT_TRANSACTION_ID), - "the id" + "the id", ) val brazeCustomAttributesDictionary = properties.remove(AppboyKit.CUSTOM_ATTRIBUTES_KEY) @@ -700,19 +699,19 @@ class AppboyKitTests { val promotionProperties = promotionBrazeProperties.properties Assert.assertEquals( promotionProperties.remove(CommerceEventUtils.Constants.ATT_PROMOTION_ID), - "my_promo_1" + "my_promo_1", ) Assert.assertEquals( promotionProperties.remove(CommerceEventUtils.Constants.ATT_PROMOTION_NAME), - "App-wide 50% off sale" + "App-wide 50% off sale", ) Assert.assertEquals( promotionProperties.remove(CommerceEventUtils.Constants.ATT_PROMOTION_POSITION), - "dashboard_bottom" + "dashboard_bottom", ) Assert.assertEquals( promotionProperties.remove(CommerceEventUtils.Constants.ATT_PROMOTION_CREATIVE), - "sale_banner_1" + "sale_banner_1", ) Assert.assertEquals(emptyAttributes, promotionProperties) } @@ -805,7 +804,7 @@ class AppboyKitTests { val impressionProperties = impressionBrazeProperties.properties Assert.assertEquals( impressionProperties.remove("Product Impression List"), - "Suggested Products List" + "Suggested Products List", ) val productArray = impressionProperties.remove(AppboyKit.PRODUCT_KEY) Assert.assertTrue(productArray is Array<*>) @@ -816,23 +815,23 @@ class AppboyKitTests { val productProperties = productBrazeProperties.properties Assert.assertEquals( productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_TOTAL_AMOUNT), - 22.5 + 22.5, ) Assert.assertEquals( productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_NAME), - "product name" + "product name", ) Assert.assertEquals( productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_QUANTITY), - 5.0 + 5.0, ) Assert.assertEquals( productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_ID), - "sku1" + "sku1", ) Assert.assertEquals( productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_PRICE), - 4.5 + 4.5, ) val brazeProductCustomAttributesDictionary = productProperties.remove(AppboyKit.CUSTOM_ATTRIBUTES_KEY) @@ -841,11 +840,11 @@ class AppboyKitTests { brazeProductCustomAttributesDictionary.properties Assert.assertEquals( customProductAttributesDictionary.remove("key1"), - "value1" + "value1", ) Assert.assertEquals( customProductAttributesDictionary.remove("key #2"), - "value #3" + "value #3", ) Assert.assertEquals(emptyAttributes, customProductAttributesDictionary) } @@ -1009,7 +1008,7 @@ class AppboyKitTests { val jsonObject = JSONObject() val mapValue = JSONObject() - //this is hash for event attribute i.e combination of eventType + eventName + attribute key + // this is hash for event attribute i.e combination of eventType + eventName + attribute key mapValue.put("888169310", "testEvent") val eaaObject = JSONObject() eaaObject.put("eaa", mapValue) @@ -1046,7 +1045,7 @@ class AppboyKitTests { val jsonObject = JSONObject() val mapValue = JSONObject() - //this is hash for event attribute i.e combination of eventType + eventName + attribute key + // this is hash for event attribute i.e combination of eventType + eventName + attribute key mapValue.put("888169310", "testEvent") val eaaObject = JSONObject() eaaObject.put("eaa", mapValue) @@ -1078,7 +1077,7 @@ class AppboyKitTests { val jsonObject = JSONObject() val mapValue = JSONObject() - //this is hash for event attribute i.e combination of eventType + eventName + attribute key + // this is hash for event attribute i.e combination of eventType + eventName + attribute key mapValue.put("888169310", "testEvent") val eaaObject = JSONObject() eaaObject.put("eas", mapValue) @@ -1114,7 +1113,7 @@ class AppboyKitTests { val method: Method = AppboyKit::class.java.getDeclaredMethod( "parseToNestedMap", - String::class.java + String::class.java, ) method.isAccessible = true val result = method.invoke(kit, jsonInput) @@ -1128,7 +1127,7 @@ class AppboyKitTests { val method: Method = AppboyKit::class.java.getDeclaredMethod( "parseToNestedMap", - String::class.java + String::class.java, ) method.isAccessible = true val result = method.invoke(kit, jsonInput) @@ -1145,13 +1144,14 @@ class AppboyKitTests { "notifications" to mapOf( "email" to false, "push" to true, - "lastUpdated" to 1633046400000L - ) - ) + "lastUpdated" to 1633046400000L, + ), + ), ) val method: Method = AppboyKit::class.java.getDeclaredMethod( - "searchKeyInNestedMap", Map::class.java, - Any::class.java + "searchKeyInNestedMap", + Map::class.java, + Any::class.java, ) method.isAccessible = true val result = method.invoke(kit, map, "") @@ -1163,8 +1163,9 @@ class AppboyKitTests { val kit = MockAppboyKit() val emptyMap: Map = emptyMap() val method: Method = AppboyKit::class.java.getDeclaredMethod( - "searchKeyInNestedMap", Map::class.java, - Any::class.java + "searchKeyInNestedMap", + Map::class.java, + Any::class.java, ) method.isAccessible = true val result = method.invoke(kit, emptyMap, "1") @@ -1177,7 +1178,7 @@ class AppboyKitTests { val emptyJson = "" val method: Method = AppboyKit::class.java.getDeclaredMethod( "parseConsentMapping", - String::class.java + String::class.java, ) method.isAccessible = true val result = method.invoke(kit, emptyJson) @@ -1191,7 +1192,7 @@ class AppboyKitTests { "{'GDPR':{'marketing':'{:false,'timestamp':1711038269644:'Test consent','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}','performance':'{'consented':true,'timestamp':1711038269644,'document':'parental_consent_agreement_v2','location':'17 Cherry Tree Lan 3','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'},'CCPA':'{'consented':true,'timestamp':1711038269644,'document':'ccpa_consent_agreement_v3','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'}" val method: Method = AppboyKit::class.java.getDeclaredMethod( "parseConsentMapping", - String::class.java + String::class.java, ) method.isAccessible = true val result = method.invoke(kit, jsonInput) @@ -1203,7 +1204,7 @@ class AppboyKitTests { val kit = MockAppboyKit() val method: Method = AppboyKit::class.java.getDeclaredMethod( "parseConsentMapping", - String::class.java + String::class.java, ) method.isAccessible = true val result = method.invoke(kit, null) @@ -1220,7 +1221,6 @@ class AppboyKitTests { map["consentMappingSDK"] = " [{\\\"jsmap\\\":null,\\\"map\\\":\\\"Performance\\\",\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_user_data\\\"},{\\\"jsmap\\\":null,\\\"map\\\":\\\"Marketing\\\",\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_personalization\\\"}]" - var kitConfiguration = MockKitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) kit.configuration = kitConfiguration @@ -1237,7 +1237,6 @@ class AppboyKitTests { kit.onConsentStateUpdated(state, state, filteredMParticleUser) TestCase.assertEquals(false, currentUser.getCustomUserAttribute()["\$google_ad_personalization"]) - } @Test @@ -1250,7 +1249,6 @@ class AppboyKitTests { map["consentMappingSDK"] = " [{\\\"jsmap\\\":null,\\\"map\\\":\\\"Performance\\\",\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_user_data\\\"},{\\\"jsmap\\\":null,\\\"map\\\":\\\"Marketing\\\",\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_personalization\\\"}]" - var kitConfiguration = MockKitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) kit.configuration = kitConfiguration @@ -1339,7 +1337,6 @@ class AppboyKitTests { kit.onConsentStateUpdated(state, state, filteredMParticleUser) TestCase.assertEquals(0, currentUser.getCustomUserAttribute().size) - } @Test diff --git a/src/test/kotlin/com/mparticle/kits/BrazePurchase.kt b/src/test/kotlin/com/mparticle/kits/BrazePurchase.kt index 95c4add..93de4c9 100644 --- a/src/test/kotlin/com/mparticle/kits/BrazePurchase.kt +++ b/src/test/kotlin/com/mparticle/kits/BrazePurchase.kt @@ -8,5 +8,5 @@ data class BrazePurchase( val currency: String, val unitPrice: BigDecimal, val quantity: Int, - val purchaseProperties: BrazeProperties -) \ No newline at end of file + val purchaseProperties: BrazeProperties, +) diff --git a/src/test/kotlin/com/mparticle/kits/TypeDetectionTests.kt b/src/test/kotlin/com/mparticle/kits/TypeDetectionTests.kt index bcafdfd..56bdbfb 100644 --- a/src/test/kotlin/com/mparticle/kits/TypeDetectionTests.kt +++ b/src/test/kotlin/com/mparticle/kits/TypeDetectionTests.kt @@ -15,11 +15,11 @@ class TypeDetectionTests { Assert.assertEquals(Int.MIN_VALUE, parser.parseValue("key", Int.MIN_VALUE.toString())) Assert.assertEquals( Int.MAX_VALUE + 1L, - parser.parseValue("key", (Int.MAX_VALUE + 1L).toString()) + parser.parseValue("key", (Int.MAX_VALUE + 1L).toString()), ) Assert.assertEquals( Int.MIN_VALUE - 1L, - parser.parseValue("key", (Int.MIN_VALUE - 1L).toString()) + parser.parseValue("key", (Int.MIN_VALUE - 1L).toString()), ) Assert.assertEquals(Long.MAX_VALUE, parser.parseValue("key", Long.MAX_VALUE.toString())) Assert.assertEquals(Long.MIN_VALUE, parser.parseValue("key", Long.MIN_VALUE.toString())) @@ -42,7 +42,7 @@ class TypeDetectionTests { Assert.assertEquals("1", parser.parseValue("key", "1")) Assert.assertEquals( (Int.MAX_VALUE + 1L).toString(), - parser.parseValue("key", (Int.MAX_VALUE + 1L).toString()) + parser.parseValue("key", (Int.MAX_VALUE + 1L).toString()), ) Assert.assertEquals("432.2561", parser.parseValue("key", "432.2561")) Assert.assertEquals("true", parser.parseValue("key", "true")) @@ -50,21 +50,26 @@ class TypeDetectionTests { private inner class SomeParser internal constructor(enableTypeDetection: Boolean?) : StringTypeParser( - enableTypeDetection!! + enableTypeDetection!!, ) { - override fun toString(key: String, value: String) { /* do nothing */ + override fun toString(key: String, value: String) { + /* do nothing */ } - override fun toInt(key: String, value: Int) { /* do nothing */ + override fun toInt(key: String, value: Int) { + /* do nothing */ } - override fun toLong(key: String, value: Long) { /* do nothing */ + override fun toLong(key: String, value: Long) { + /* do nothing */ } - override fun toDouble(key: String, value: Double) { /* do nothing */ + override fun toDouble(key: String, value: Double) { + /* do nothing */ } - override fun toBoolean(key: String, value: Boolean) { /* do nothing */ + override fun toBoolean(key: String, value: Boolean) { + /* do nothing */ } } } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockAppboyKit.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockAppboyKit.kt index 99abdbf..386a454 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockAppboyKit.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockAppboyKit.kt @@ -12,14 +12,16 @@ class MockAppboyKit : AppboyKit() { } override fun queueDataFlush() { - //do nothing + // do nothing } init { kitManager = MockKitManagerImpl( - Mockito.mock(Context::class.java), Mockito.mock( - ReportingManager::class.java - ), MockCoreCallbacks() + Mockito.mock(Context::class.java), + Mockito.mock( + ReportingManager::class.java, + ), + MockCoreCallbacks(), ) } } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockApplication.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockApplication.kt index 2454c6e..fc5a818 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockApplication.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockApplication.kt @@ -13,35 +13,21 @@ class MockApplication(var mContext: MockContext) : Application() { mCallbacks = callback } - override fun getApplicationContext(): Context { - return this - } + override fun getApplicationContext(): Context = this fun setSharedPreferences(prefs: SharedPreferences) { mContext.setSharedPreferences(prefs) } - override fun getSystemService(name: String): Any? { - return mContext.getSystemService(name) - } + override fun getSystemService(name: String): Any? = mContext.getSystemService(name) - override fun getSharedPreferences(name: String, mode: Int): SharedPreferences { - return mContext.getSharedPreferences(name, mode) - } + override fun getSharedPreferences(name: String, mode: Int): SharedPreferences = mContext.getSharedPreferences(name, mode) - override fun getPackageManager(): PackageManager { - return mContext.packageManager - } + override fun getPackageManager(): PackageManager = mContext.packageManager - override fun getPackageName(): String { - return mContext.packageName - } + override fun getPackageName(): String = mContext.packageName - override fun getApplicationInfo(): ApplicationInfo { - return mContext.applicationInfo - } + override fun getApplicationInfo(): ApplicationInfo = mContext.applicationInfo - override fun getResources(): Resources? { - return mContext.resources - } + override fun getResources(): Resources? = mContext.resources } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockContext.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockContext.kt index 7a90414..999be6d 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockContext.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockContext.kt @@ -1,7 +1,15 @@ package com.mparticle.kits.mocks -import android.content.* +import android.content.BroadcastReceiver +import android.content.ComponentName +import android.content.ContentResolver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.content.IntentSender import android.content.IntentSender.SendIntentException +import android.content.ServiceConnection +import android.content.SharedPreferences import android.content.pm.ApplicationInfo import android.content.pm.PackageInfo import android.content.pm.PackageManager @@ -24,7 +32,12 @@ import android.telephony.TelephonyManager import android.view.Display import junit.framework.Assert import org.mockito.Mockito -import java.io.* +import java.io.File +import java.io.FileInputStream +import java.io.FileNotFoundException +import java.io.FileOutputStream +import java.io.IOException +import java.io.InputStream class MockContext : Context() { private var sharedPreferences: SharedPreferences = MockSharedPreferences() @@ -41,22 +54,16 @@ class MockContext : Context() { return application as MockApplication } - override fun checkCallingOrSelfPermission(permission: String): Int { - return PackageManager.PERMISSION_GRANTED - } + override fun checkCallingOrSelfPermission(permission: String): Int = PackageManager.PERMISSION_GRANTED - override fun getSharedPreferences(name: String, mode: Int): SharedPreferences { - return sharedPreferences - } + override fun getSharedPreferences(name: String, mode: Int): SharedPreferences = sharedPreferences - override fun getResources(): Resources? { - return resources - } + override fun getResources(): Resources? = resources - override fun getSystemService(name: String): Any? { - return if (name == TELEPHONY_SERVICE) { - Mockito.mock(TelephonyManager::class.java) - } else null + override fun getSystemService(name: String): Any? = if (name == TELEPHONY_SERVICE) { + Mockito.mock(TelephonyManager::class.java) + } else { + null } override fun getPackageManager(): PackageManager { @@ -79,25 +86,17 @@ class MockContext : Context() { return manager } - override fun getPackageName(): String { - return "com.mparticle.test" - } + override fun getPackageName(): String = "com.mparticle.test" - override fun getApplicationInfo(): ApplicationInfo { - return ApplicationInfo() - } + override fun getApplicationInfo(): ApplicationInfo = ApplicationInfo() /** * Stubbed methods */ override fun setTheme(resid: Int) {} - override fun getTheme(): Theme? { - return null - } + override fun getTheme(): Theme? = null - override fun getClassLoader(): ClassLoader? { - return null - } + override fun getClassLoader(): ClassLoader? = null override fun sendBroadcast(intent: Intent) {} override fun sendBroadcast(intent: Intent, receiverPermission: String?) {} @@ -109,7 +108,7 @@ class MockContext : Context() { scheduler: Handler?, initialCode: Int, initialData: String?, - initialExtras: Bundle? + initialExtras: Bundle?, ) { } @@ -117,7 +116,7 @@ class MockContext : Context() { override fun sendBroadcastAsUser( intent: Intent, user: UserHandle, - receiverPermission: String? + receiverPermission: String?, ) { } @@ -129,7 +128,7 @@ class MockContext : Context() { scheduler: Handler?, initialCode: Int, initialData: String?, - initialExtras: Bundle? + initialExtras: Bundle?, ) { } @@ -140,7 +139,7 @@ class MockContext : Context() { scheduler: Handler?, initialCode: Int, initialData: String?, - initialExtras: Bundle? + initialExtras: Bundle?, ) { } @@ -153,71 +152,51 @@ class MockContext : Context() { scheduler: Handler?, initialCode: Int, initialData: String?, - initialExtras: Bundle? + initialExtras: Bundle?, ) { } override fun removeStickyBroadcastAsUser(intent: Intent, user: UserHandle) {} - override fun registerReceiver(receiver: BroadcastReceiver?, filter: IntentFilter): Intent? { - return null - } + override fun registerReceiver(receiver: BroadcastReceiver?, filter: IntentFilter): Intent? = null override fun registerReceiver( receiver: BroadcastReceiver?, filter: IntentFilter, - flags: Int - ): Intent? { - return null - } + flags: Int, + ): Intent? = null override fun registerReceiver( receiver: BroadcastReceiver, filter: IntentFilter, broadcastPermission: String?, - scheduler: Handler? - ): Intent? { - return null - } + scheduler: Handler?, + ): Intent? = null override fun registerReceiver( receiver: BroadcastReceiver, filter: IntentFilter, broadcastPermission: String?, scheduler: Handler?, - flags: Int - ): Intent? { - return null - } + flags: Int, + ): Intent? = null override fun unregisterReceiver(receiver: BroadcastReceiver) {} - override fun startService(service: Intent): ComponentName? { - return null - } + override fun startService(service: Intent): ComponentName? = null - override fun startForegroundService(service: Intent): ComponentName? { - return null - } + override fun startForegroundService(service: Intent): ComponentName? = null - override fun stopService(service: Intent): Boolean { - return false - } + override fun stopService(service: Intent): Boolean = false - override fun bindService(service: Intent, conn: ServiceConnection, flags: Int): Boolean { - return false - } + override fun bindService(service: Intent, conn: ServiceConnection, flags: Int): Boolean = false override fun unbindService(conn: ServiceConnection) {} override fun startInstrumentation( className: ComponentName, profileFile: String?, - arguments: Bundle? - ): Boolean { - return false - } + arguments: Bundle?, + ): Boolean = false - override fun checkSelfPermission(permission: String): Int { - return 0 - } + override fun checkSelfPermission(permission: String): Int = 0 override fun enforcePermission(permission: String, pid: Int, uid: Int, message: String?) {} override fun enforceCallingPermission(permission: String, message: String?) {} @@ -225,17 +204,11 @@ class MockContext : Context() { override fun grantUriPermission(toPackage: String, uri: Uri, modeFlags: Int) {} override fun revokeUriPermission(uri: Uri, modeFlags: Int) {} override fun revokeUriPermission(toPackage: String, uri: Uri, modeFlags: Int) {} - override fun checkUriPermission(uri: Uri, pid: Int, uid: Int, modeFlags: Int): Int { - return 0 - } + override fun checkUriPermission(uri: Uri, pid: Int, uid: Int, modeFlags: Int): Int = 0 - override fun checkCallingUriPermission(uri: Uri, modeFlags: Int): Int { - return 0 - } + override fun checkCallingUriPermission(uri: Uri, modeFlags: Int): Int = 0 - override fun checkCallingOrSelfUriPermission(uri: Uri, modeFlags: Int): Int { - return 0 - } + override fun checkCallingOrSelfUriPermission(uri: Uri, modeFlags: Int): Int = 0 override fun checkUriPermission( uri: Uri?, @@ -243,17 +216,15 @@ class MockContext : Context() { writePermission: String?, pid: Int, uid: Int, - modeFlags: Int - ): Int { - return 0 - } + modeFlags: Int, + ): Int = 0 override fun enforceUriPermission( uri: Uri, pid: Int, uid: Int, modeFlags: Int, - message: String + message: String, ) { } @@ -266,166 +237,94 @@ class MockContext : Context() { pid: Int, uid: Int, modeFlags: Int, - message: String? + message: String?, ) { } @Throws(NameNotFoundException::class) - override fun createPackageContext(packageName: String, flags: Int): Context? { - return null - } + override fun createPackageContext(packageName: String, flags: Int): Context? = null @Throws(NameNotFoundException::class) - override fun createContextForSplit(splitName: String): Context? { - return null - } + override fun createContextForSplit(splitName: String): Context? = null - override fun createConfigurationContext(overrideConfiguration: Configuration): Context? { - return null - } + override fun createConfigurationContext(overrideConfiguration: Configuration): Context? = null - override fun createDisplayContext(display: Display): Context? { - return null - } + override fun createDisplayContext(display: Display): Context? = null - override fun createDeviceProtectedStorageContext(): Context? { - return null - } + override fun createDeviceProtectedStorageContext(): Context? = null - override fun isDeviceProtectedStorage(): Boolean { - return false - } + override fun isDeviceProtectedStorage(): Boolean = false - override fun moveSharedPreferencesFrom(sourceContext: Context, name: String): Boolean { - return false - } + override fun moveSharedPreferencesFrom(sourceContext: Context, name: String): Boolean = false - override fun deleteSharedPreferences(name: String): Boolean { - return false - } + override fun deleteSharedPreferences(name: String): Boolean = false @Throws(FileNotFoundException::class) - override fun openFileInput(name: String): FileInputStream? { - return null - } + override fun openFileInput(name: String): FileInputStream? = null @Throws(FileNotFoundException::class) - override fun openFileOutput(name: String, mode: Int): FileOutputStream? { - return null - } + override fun openFileOutput(name: String, mode: Int): FileOutputStream? = null - override fun deleteFile(name: String): Boolean { - return false - } + override fun deleteFile(name: String): Boolean = false - override fun getFileStreamPath(name: String): File? { - return null - } + override fun getFileStreamPath(name: String): File? = null - override fun getDataDir(): File? { - return null - } + override fun getDataDir(): File? = null - override fun getFilesDir(): File? { - return null - } + override fun getFilesDir(): File? = null - override fun getNoBackupFilesDir(): File? { - return null - } + override fun getNoBackupFilesDir(): File? = null - override fun getExternalFilesDir(type: String?): File? { - return null - } + override fun getExternalFilesDir(type: String?): File? = null - override fun getExternalFilesDirs(type: String): Array { - return arrayOfNulls(0) - } + override fun getExternalFilesDirs(type: String): Array = arrayOfNulls(0) - override fun getObbDir(): File? { - return null - } + override fun getObbDir(): File? = null - override fun getObbDirs(): Array { - return arrayOfNulls(0) - } + override fun getObbDirs(): Array = arrayOfNulls(0) - override fun getCacheDir(): File? { - return null - } + override fun getCacheDir(): File? = null - override fun getCodeCacheDir(): File? { - return null - } + override fun getCodeCacheDir(): File? = null - override fun getExternalCacheDir(): File? { - return null - } + override fun getExternalCacheDir(): File? = null - override fun getExternalCacheDirs(): Array { - return arrayOfNulls(0) - } + override fun getExternalCacheDirs(): Array = arrayOfNulls(0) - override fun getExternalMediaDirs(): Array { - return arrayOfNulls(0) - } + override fun getExternalMediaDirs(): Array = arrayOfNulls(0) - override fun fileList(): Array { - return arrayOfNulls(0) - } + override fun fileList(): Array = arrayOfNulls(0) - override fun getDir(name: String, mode: Int): File? { - return null - } + override fun getDir(name: String, mode: Int): File? = null override fun openOrCreateDatabase( name: String, mode: Int, - factory: CursorFactory - ): SQLiteDatabase? { - return null - } + factory: CursorFactory, + ): SQLiteDatabase? = null override fun openOrCreateDatabase( name: String, mode: Int, factory: CursorFactory, - errorHandler: DatabaseErrorHandler? - ): SQLiteDatabase? { - return null - } + errorHandler: DatabaseErrorHandler?, + ): SQLiteDatabase? = null - override fun moveDatabaseFrom(sourceContext: Context, name: String): Boolean { - return false - } + override fun moveDatabaseFrom(sourceContext: Context, name: String): Boolean = false - override fun deleteDatabase(name: String): Boolean { - return false - } + override fun deleteDatabase(name: String): Boolean = false - override fun getDatabasePath(name: String): File? { - return null - } + override fun getDatabasePath(name: String): File? = null - override fun databaseList(): Array { - return arrayOfNulls(0) - } + override fun databaseList(): Array = arrayOfNulls(0) - override fun getWallpaper(): Drawable? { - return null - } + override fun getWallpaper(): Drawable? = null - override fun peekWallpaper(): Drawable? { - return null - } + override fun peekWallpaper(): Drawable? = null - override fun getWallpaperDesiredMinimumWidth(): Int { - return 0 - } + override fun getWallpaperDesiredMinimumWidth(): Int = 0 - override fun getWallpaperDesiredMinimumHeight(): Int { - return 0 - } + override fun getWallpaperDesiredMinimumHeight(): Int = 0 @Throws(IOException::class) override fun setWallpaper(bitmap: Bitmap) { @@ -443,13 +342,14 @@ class MockContext : Context() { override fun startActivity(intent: Intent, options: Bundle?) {} override fun startActivities(intents: Array) {} override fun startActivities(intents: Array, options: Bundle) {} + @Throws(SendIntentException::class) override fun startIntentSender( intent: IntentSender, fillInIntent: Intent?, flagsMask: Int, flagsValues: Int, - extraFlags: Int + extraFlags: Int, ) { } @@ -460,39 +360,23 @@ class MockContext : Context() { flagsMask: Int, flagsValues: Int, extraFlags: Int, - options: Bundle? + options: Bundle?, ) { } - override fun getSystemServiceName(serviceClass: Class<*>): String? { - return null - } + override fun getSystemServiceName(serviceClass: Class<*>): String? = null - override fun checkPermission(permission: String, pid: Int, uid: Int): Int { - return 0 - } + override fun checkPermission(permission: String, pid: Int, uid: Int): Int = 0 - override fun checkCallingPermission(permission: String): Int { - return 0 - } + override fun checkCallingPermission(permission: String): Int = 0 - override fun getContentResolver(): ContentResolver? { - return null - } + override fun getContentResolver(): ContentResolver? = null - override fun getMainLooper(): Looper? { - return null - } + override fun getMainLooper(): Looper? = null - override fun getPackageResourcePath(): String? { - return null - } + override fun getPackageResourcePath(): String? = null - override fun getPackageCodePath(): String? { - return null - } + override fun getPackageCodePath(): String? = null - override fun getAssets(): AssetManager? { - return null - } + override fun getAssets(): AssetManager? = null } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockContextApplication.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockContextApplication.kt index c49cf04..3d8fec7 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockContextApplication.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockContextApplication.kt @@ -1,21 +1,17 @@ package com.mparticle.kits.mocks import android.app.Application -import android.content.SharedPreferences -import com.mparticle.kits.mocks.MockSharedPreferences import android.app.Application.ActivityLifecycleCallbacks import android.content.Context +import android.content.SharedPreferences +import com.mparticle.kits.mocks.MockSharedPreferences class MockContextApplication : Application() { - override fun getApplicationContext(): Context { - return this - } + override fun getApplicationContext(): Context = this - override fun getSharedPreferences(name: String, mode: Int): SharedPreferences { - return MockSharedPreferences() - } + override fun getSharedPreferences(name: String, mode: Int): SharedPreferences = MockSharedPreferences() override fun registerActivityLifecycleCallbacks(callback: ActivityLifecycleCallbacks) { - //do nothing + // do nothing } } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockCoreCallbacks.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockCoreCallbacks.kt index 758b9f4..0688d05 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockCoreCallbacks.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockCoreCallbacks.kt @@ -1,71 +1,45 @@ package com.mparticle.kits.mocks -import com.mparticle.internal.CoreCallbacks -import java.lang.ref.WeakReference import android.app.Activity -import com.mparticle.MParticleOptions.DataplanOptions import android.net.Uri +import com.mparticle.MParticleOptions.DataplanOptions +import com.mparticle.internal.CoreCallbacks import com.mparticle.internal.CoreCallbacks.KitListener import org.json.JSONArray +import java.lang.ref.WeakReference class MockCoreCallbacks : CoreCallbacks { - override fun isBackgrounded(): Boolean { - return false - } + override fun isBackgrounded(): Boolean = false - override fun getUserBucket(): Int { - return 0 - } + override fun getUserBucket(): Int = 0 - override fun isEnabled(): Boolean { - return false - } + override fun isEnabled(): Boolean = false override fun setIntegrationAttributes(kitId: Int, integrationAttributes: Map) {} - override fun getIntegrationAttributes(kitId: Int): Map? { - return null - } + override fun getIntegrationAttributes(kitId: Int): Map? = null - override fun getCurrentActivity(): WeakReference? { - return null - } + override fun getCurrentActivity(): WeakReference? = null - override fun getLatestKitConfiguration(): JSONArray? { - return null - } + override fun getLatestKitConfiguration(): JSONArray? = null - override fun getDataplanOptions(): DataplanOptions? { - return null - } + override fun getDataplanOptions(): DataplanOptions? = null - override fun isPushEnabled(): Boolean { - return false - } + override fun isPushEnabled(): Boolean = false - override fun getPushSenderId(): String? { - return null - } + override fun getPushSenderId(): String? = null - override fun getPushInstanceId(): String? { - return null - } + override fun getPushInstanceId(): String? = null - override fun getLaunchUri(): Uri? { - return null - } + override fun getLaunchUri(): Uri? = null - override fun getLaunchAction(): String? { - return null - } + override fun getLaunchAction(): String? = null - override fun getKitListener(): KitListener { - return object : KitListener { - override fun kitFound(kitId: Int) {} - override fun kitConfigReceived(kitId: Int, configuration: String?) {} - override fun kitExcluded(kitId: Int, reason: String?) {} - override fun kitStarted(kitId: Int) {} - override fun onKitApiCalled(kitId: Int, used: Boolean?, vararg objects: Any?) {} - override fun onKitApiCalled(methodName: String?, kitId: Int, used: Boolean?, vararg objects: Any?) {} - } + override fun getKitListener(): KitListener = object : KitListener { + override fun kitFound(kitId: Int) {} + override fun kitConfigReceived(kitId: Int, configuration: String?) {} + override fun kitExcluded(kitId: Int, reason: String?) {} + override fun kitStarted(kitId: Int) {} + override fun onKitApiCalled(kitId: Int, used: Boolean?, vararg objects: Any?) {} + override fun onKitApiCalled(methodName: String?, kitId: Int, used: Boolean?, vararg objects: Any?) {} } } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockKitConfiguration.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockKitConfiguration.kt index e2e7d88..7a8a37c 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockKitConfiguration.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockKitConfiguration.kt @@ -1,14 +1,14 @@ package com.mparticle.kits.mocks -import com.mparticle.kits.KitConfiguration -import kotlin.Throws -import com.mparticle.kits.mocks.MockKitConfiguration.MockSparseBooleanArray import android.util.SparseBooleanArray import com.mparticle.internal.Logger -import java.util.HashMap +import com.mparticle.kits.KitConfiguration import com.mparticle.kits.mocks.MockKitConfiguration +import com.mparticle.kits.mocks.MockKitConfiguration.MockSparseBooleanArray import org.json.JSONException import org.json.JSONObject +import java.util.HashMap +import kotlin.Throws open class MockKitConfiguration : KitConfiguration() { @Throws(JSONException::class) @@ -40,9 +40,7 @@ open class MockKitConfiguration : KitConfiguration() { } internal inner class MockSparseBooleanArray : SparseBooleanArray() { - override fun get(key: Int): Boolean { - return get(key, false) - } + override fun get(key: Int): Boolean = get(key, false) override fun get(key: Int, valueIfKeyNotFound: Boolean): Boolean { print("SparseArray getting: $key") @@ -62,20 +60,14 @@ open class MockKitConfiguration : KitConfiguration() { map.clear() } - override fun size(): Int { - return map.size - } + override fun size(): Int = map.size - override fun toString(): String { - return map.toString() - } + override fun toString(): String = map.toString() } companion object { @Throws(JSONException::class) - fun createKitConfiguration(json: JSONObject): KitConfiguration { - return MockKitConfiguration().parseConfiguration(json) - } + fun createKitConfiguration(json: JSONObject): KitConfiguration = MockKitConfiguration().parseConfiguration(json) @Throws(JSONException::class) fun createKitConfiguration(): KitConfiguration { diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockKitManagerImpl.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockKitManagerImpl.kt index 25ba807..b440e6c 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockKitManagerImpl.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockKitManagerImpl.kt @@ -1,34 +1,37 @@ package com.mparticle.kits.mocks import android.content.Context -import com.mparticle.internal.ReportingManager -import com.mparticle.internal.CoreCallbacks -import com.mparticle.kits.KitManagerImpl -import org.mockito.Mockito import com.mparticle.MParticleOptions -import com.mparticle.kits.mocks.MockContext +import com.mparticle.internal.CoreCallbacks import com.mparticle.internal.CoreCallbacks.KitListener -import kotlin.Throws +import com.mparticle.internal.ReportingManager import com.mparticle.kits.KitConfiguration +import com.mparticle.kits.KitManagerImpl +import com.mparticle.kits.mocks.MockContext import com.mparticle.kits.mocks.MockKitConfiguration import org.json.JSONException import org.json.JSONObject +import org.mockito.Mockito +import kotlin.Throws class MockKitManagerImpl( context: Context?, reportingManager: ReportingManager?, - coreCallbacks: CoreCallbacks? + coreCallbacks: CoreCallbacks?, ) : KitManagerImpl( - context, reportingManager, coreCallbacks, Mockito.mock( - MParticleOptions::class.java - ) + context, + reportingManager, + coreCallbacks, + Mockito.mock( + MParticleOptions::class.java, + ), ) { constructor() : this( MockContext(), Mockito.mock(ReportingManager::class.java), Mockito.mock( - CoreCallbacks::class.java - ) + CoreCallbacks::class.java, + ), ) { Mockito.`when`(mCoreCallbacks.getKitListener()).thenReturn(object : KitListener { override fun kitFound(kitId: Int) {} @@ -41,11 +44,7 @@ class MockKitManagerImpl( } @Throws(JSONException::class) - override fun createKitConfiguration(configuration: JSONObject): KitConfiguration { - return MockKitConfiguration.createKitConfiguration(configuration) - } + override fun createKitConfiguration(configuration: JSONObject): KitConfiguration = MockKitConfiguration.createKitConfiguration(configuration) - override fun getUserBucket(): Int { - return 50 - } + override fun getUserBucket(): Int = 50 } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockResources.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockResources.kt index b7c1d99..bb962e3 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockResources.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockResources.kt @@ -1,9 +1,9 @@ package com.mparticle.kits.mocks import android.content.res.Resources -import kotlin.Throws import android.content.res.Resources.NotFoundException import com.mparticle.kits.mocks.MockResources +import kotlin.Throws class MockResources : Resources(null, null, null) { override fun getIdentifier(name: String, defType: String, defPackage: String): Int { @@ -18,19 +18,17 @@ class MockResources : Resources(null, null, null) { @Throws(NotFoundException::class) override fun getString(id: Int): String { when (id) { - 1 -> return TEST_APP_KEY - 2 -> return TEST_APP_SECRET + 1 -> return testAppKey + 2 -> return testAppSecret } return "" } @Throws(NotFoundException::class) - override fun getString(id: Int, vararg formatArgs: Any): String { - return super.getString(id, *formatArgs) - } + override fun getString(id: Int, vararg formatArgs: Any): String = super.getString(id, *formatArgs) companion object { - var TEST_APP_KEY = "the app key" - var TEST_APP_SECRET = "the app secret" + var testAppKey = "the app key" + var testAppSecret = "the app secret" } } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockSharedPreferences.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockSharedPreferences.kt index 55fd669..8b99f8f 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockSharedPreferences.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockSharedPreferences.kt @@ -2,10 +2,12 @@ package com.mparticle.kits.mocks import android.content.SharedPreferences import android.content.SharedPreferences.Editor -import java.util.TreeSet import android.content.SharedPreferences.OnSharedPreferenceChangeListener +import java.util.TreeSet -class MockSharedPreferences : SharedPreferences, Editor { +class MockSharedPreferences : + SharedPreferences, + Editor { override fun getAll(): Map? = null diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockUser.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockUser.kt index ddd7093..b5bebca 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockUser.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockUser.kt @@ -4,8 +4,8 @@ import com.mparticle.MParticle.IdentityType import com.mparticle.UserAttributeListenerType import com.mparticle.audience.AudienceResponse import com.mparticle.audience.AudienceTask -import com.mparticle.identity.MParticleUser import com.mparticle.consent.ConsentState +import com.mparticle.identity.MParticleUser class MockUser(var identities: Map) : MParticleUser { @@ -33,15 +33,11 @@ class MockUser(var identities: Map) : MParticleUser { override fun setConsentState(consentState: ConsentState?) {} - override fun isLoggedIn(): Boolean =false + override fun isLoggedIn(): Boolean = false override fun getFirstSeenTime(): Long = 0 override fun getLastSeenTime(): Long = 0 - override fun getUserAudiences(): AudienceTask { - throw NotImplementedError("getUserAudiences() is not implemented") - } - - + override fun getUserAudiences(): AudienceTask = throw NotImplementedError("getUserAudiences() is not implemented") } From 1278ff2be81374537abe2b82cbfd67e0b6dd508b Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 13:03:30 -0500 Subject: [PATCH 03/14] Fix lint issue --- src/main/kotlin/com/mparticle/kits/AppboyKit.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt index 1a53691..895778e 100644 --- a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt @@ -42,7 +42,10 @@ import org.json.JSONException import org.json.JSONObject import java.math.BigDecimal import java.text.SimpleDateFormat -import java.util.* +import java.util.Calendar +import java.util.Date +import java.util.EnumSet +import java.util.LinkedList import kotlin.collections.HashMap /** @@ -56,7 +59,6 @@ open class AppboyKit : PushListener, IdentityListener, KitIntegration.UserAttributeListener { - var enableTypeDetection = false var bundleCommerceEvents = false var isMpidIdentityType = false From 6b62b9cf7157e87bf9a4c0d95cdc6523f4fe4932 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 13:22:15 -0500 Subject: [PATCH 04/14] Add edittor config file --- .editorconfig | 32 ++++++++++++++++++++++++++++++++ build.gradle | 4 +--- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e322f2f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,32 @@ +# Top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +insert_final_newline = true +charset = utf-8 + +[*.{json,yml,yaml,html,tf}] +indent_size = 2 +ij_json_array_wrapping = normal + +[*.{kt,kts}] +ktlint_code_style = intellij_idea +max_line_length = 150 +ij_kotlin_allow_trailing_comma = true +ij_kotlin_allow_trailing_comma_on_call_site = true + +# IntelliJ/Android Studio specific (ktlint respects these too) +ij_kotlin_continuation_indent_size = 4 +ij_kotlin_align_multiline_parameters = false +ij_kotlin_align_multiline_parameters_in_calls = false +ij_kotlin_call_parameters_new_line_after_left_paren = true +ij_kotlin_call_parameters_right_paren_on_new_line = true + +[**/test/**/*.kt] +max_line_length = off + +[**/androidTest/**/*.kt] +max_line_length = off diff --git a/build.gradle b/build.gradle index 2b2dbe7..dfbad19 100644 --- a/build.gradle +++ b/build.gradle @@ -48,9 +48,7 @@ android { kotlinOptions { jvmTarget = '17' } - lint { - abortOnError = false - } + testOptions { unitTests.all { jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] From 26600477a3f40eea8a9b214ea5a8ba1c6ee7cd36 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 13:53:29 -0500 Subject: [PATCH 05/14] update gradle properties --- gradle.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 0b6a43f..988448b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,5 @@ android.enableJetifier=true android.useAndroidX=true org.gradle.daemon=true -org.gradle.jvmargs=-Xmx2560m +org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g + From 3ba029939e0d94dde2451a835e3fc60bf826b063 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 14:02:00 -0500 Subject: [PATCH 06/14] Removed the editorconfig --- .editorconfig | 32 -------------------------------- build.gradle | 1 - 2 files changed, 33 deletions(-) delete mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index e322f2f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,32 +0,0 @@ -# Top-most EditorConfig file -root = true - -[*] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true -insert_final_newline = true -charset = utf-8 - -[*.{json,yml,yaml,html,tf}] -indent_size = 2 -ij_json_array_wrapping = normal - -[*.{kt,kts}] -ktlint_code_style = intellij_idea -max_line_length = 150 -ij_kotlin_allow_trailing_comma = true -ij_kotlin_allow_trailing_comma_on_call_site = true - -# IntelliJ/Android Studio specific (ktlint respects these too) -ij_kotlin_continuation_indent_size = 4 -ij_kotlin_align_multiline_parameters = false -ij_kotlin_align_multiline_parameters_in_calls = false -ij_kotlin_call_parameters_new_line_after_left_paren = true -ij_kotlin_call_parameters_right_paren_on_new_line = true - -[**/test/**/*.kt] -max_line_length = off - -[**/androidTest/**/*.kt] -max_line_length = off diff --git a/build.gradle b/build.gradle index dfbad19..2e5b99a 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,6 @@ android { kotlinOptions { jvmTarget = '17' } - testOptions { unitTests.all { jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] From c20e5ab32682620ccc42b9b4a5ab9e1f82d61617 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 14:09:21 -0500 Subject: [PATCH 07/14] Fix lint error --- .../kotlin/com/mparticle/kits/AppboyKit.kt | 376 ++++++++++-------- 1 file changed, 205 insertions(+), 171 deletions(-) diff --git a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt index 895778e..3c2be32 100644 --- a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt @@ -97,11 +97,13 @@ open class AppboyKit : } } forwardScreenViews = settings[FORWARD_SCREEN_VIEWS].toBoolean() - subscriptionGroupIds = settings[SUBSCRIPTION_GROUP_MAPPING]?.let { - getSubscriptionGroupIds(it) - } + subscriptionGroupIds = settings[SUBSCRIPTION_GROUP_MAPPING] + ?.let { + getSubscriptionGroupIds(it) + } if (key != null) { - val config = BrazeConfig.Builder().setApiKey(key) + val config = BrazeConfig.Builder() + .setApiKey(key) .setSdkFlavor(SdkFlavor.MPARTICLE) .setSdkMetadata(EnumSet.of(BrazeSdkMetadata.MPARTICLE)) .build() @@ -163,31 +165,32 @@ open class AppboyKit : } } Braze.getInstance(context).logCustomEvent(event.eventName, properties) - Braze.getInstance(context).getCurrentUser(object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) - event.customAttributeStrings?.let { it -> - for ((key, attributeValue) in it) { - val hashedKey = - KitUtils.hashForFiltering(event.eventType.value.toString() + event.eventName + key) - - configuration.eventAttributesAddToUser?.get(hashedKey)?.let { - value.addToCustomAttributeArray(it, attributeValue) - } - configuration.eventAttributesRemoveFromUser?.get(hashedKey)?.let { - value.removeFromCustomAttributeArray(it, attributeValue) - } - configuration.eventAttributesSingleItemUser?.get(hashedKey)?.let { - userAttributeSetter.parseValue(it, attributeValue) + Braze.getInstance(context) + .getCurrentUser(object : IValueCallback { + override fun onSuccess(value: BrazeUser) { + val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) + event.customAttributeStrings?.let { it -> + for ((key, attributeValue) in it) { + val hashedKey = + KitUtils.hashForFiltering(event.eventType.value.toString() + event.eventName + key) + + configuration.eventAttributesAddToUser?.get(hashedKey)?.let { + value.addToCustomAttributeArray(it, attributeValue) + } + configuration.eventAttributesRemoveFromUser?.get(hashedKey)?.let { + value.removeFromCustomAttributeArray(it, attributeValue) + } + configuration.eventAttributesSingleItemUser?.get(hashedKey)?.let { + userAttributeSetter.parseValue(it, attributeValue) + } } } } - } - override fun onError() { - Logger.warning("unable to acquire user to add or remove custom user attributes from events") - } - }) + override fun onError() { + Logger.warning("unable to acquire user to add or remove custom user attributes from events") + } + }) } queueDataFlush() return listOf(ReportingMessage.fromEvent(this, event).setAttributes(newAttributes)) @@ -277,86 +280,87 @@ open class AppboyKit : override fun setUserAttribute(keyIn: String, attributeValue: String) { var key = keyIn - Braze.getInstance(context).getCurrentUser(object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) - - when (key) { - UserAttributes.CITY -> value.setHomeCity(attributeValue) - UserAttributes.COUNTRY -> value.setCountry(attributeValue) - UserAttributes.FIRSTNAME -> value.setFirstName(attributeValue) - UserAttributes.LASTNAME -> value.setLastName(attributeValue) - UserAttributes.MOBILE_NUMBER -> value.setPhoneNumber(attributeValue) - UserAttributes.ZIPCODE -> value.setCustomUserAttribute("Zip", attributeValue) - UserAttributes.AGE -> { - val calendar = getCalendarMinusYears(attributeValue) - if (calendar != null) { - value.setDateOfBirth(calendar[Calendar.YEAR], Month.JANUARY, 1) - } else { - Logger.warning("unable to set DateOfBirth for " + UserAttributes.AGE + " = " + value) + Braze.getInstance(context) + .getCurrentUser(object : IValueCallback { + override fun onSuccess(value: BrazeUser) { + val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) + + when (key) { + UserAttributes.CITY -> value.setHomeCity(attributeValue) + UserAttributes.COUNTRY -> value.setCountry(attributeValue) + UserAttributes.FIRSTNAME -> value.setFirstName(attributeValue) + UserAttributes.LASTNAME -> value.setLastName(attributeValue) + UserAttributes.MOBILE_NUMBER -> value.setPhoneNumber(attributeValue) + UserAttributes.ZIPCODE -> value.setCustomUserAttribute("Zip", attributeValue) + UserAttributes.AGE -> { + val calendar = getCalendarMinusYears(attributeValue) + if (calendar != null) { + value.setDateOfBirth(calendar[Calendar.YEAR], Month.JANUARY, 1) + } else { + Logger.warning("unable to set DateOfBirth for " + UserAttributes.AGE + " = " + value) + } } - } - EMAIL_SUBSCRIBE -> { - when (attributeValue) { - OPTED_IN -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.OPTED_IN) - UNSUBSCRIBED -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.UNSUBSCRIBED) - SUBSCRIBED -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.SUBSCRIBED) - else -> { - Logger.warning("unable to set email_subscribe with invalid value: " + value) + EMAIL_SUBSCRIBE -> { + when (attributeValue) { + OPTED_IN -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.OPTED_IN) + UNSUBSCRIBED -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.UNSUBSCRIBED) + SUBSCRIBED -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.SUBSCRIBED) + else -> { + Logger.warning("unable to set email_subscribe with invalid value: " + value) + } } } - } - PUSH_SUBSCRIBE -> { - when (attributeValue) { - OPTED_IN -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.OPTED_IN) - UNSUBSCRIBED -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.UNSUBSCRIBED) - SUBSCRIBED -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.SUBSCRIBED) - else -> { - Logger.warning("unable to set push_subscribe with invalid value: " + value) + PUSH_SUBSCRIBE -> { + when (attributeValue) { + OPTED_IN -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.OPTED_IN) + UNSUBSCRIBED -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.UNSUBSCRIBED) + SUBSCRIBED -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.SUBSCRIBED) + else -> { + Logger.warning("unable to set push_subscribe with invalid value: " + value) + } } } - } - DOB -> useDobString(attributeValue, value) - UserAttributes.GENDER -> { - if (attributeValue.contains("fe")) { - value.setGender(Gender.FEMALE) - } else { - value.setGender(Gender.MALE) + DOB -> useDobString(attributeValue, value) + UserAttributes.GENDER -> { + if (attributeValue.contains("fe")) { + value.setGender(Gender.FEMALE) + } else { + value.setGender(Gender.MALE) + } } - } - else -> { - if (subscriptionGroupIds?.containsKey(key) == true) { - val groupId = subscriptionGroupIds?.get(key) - when (attributeValue.lowercase()) { - "true" -> { - groupId?.let { value.addToSubscriptionGroup(it) } + else -> { + if (subscriptionGroupIds?.containsKey(key) == true) { + val groupId = subscriptionGroupIds?.get(key) + when (attributeValue.lowercase()) { + "true" -> { + groupId?.let { value.addToSubscriptionGroup(it) } + } + + "false" -> { + groupId?.let { value.removeFromSubscriptionGroup(it) } + } + + else -> { + Logger.warning( + "Unable to set Subscription Group ID for user attribute: $key due to invalid value data type. Expected Boolean.", + ) + } } - - "false" -> { - groupId?.let { value.removeFromSubscriptionGroup(it) } + } else { + if (key.startsWith("$")) { + key = key.substring(1) } - - else -> { - Logger.warning( - "Unable to set Subscription Group ID for user attribute: $key due to invalid value data type. Expected Boolean.", - ) - } - } - } else { - if (key.startsWith("$")) { - key = key.substring(1) + userAttributeSetter?.parseValue(key, attributeValue) } - userAttributeSetter?.parseValue(key, attributeValue) } } + queueDataFlush() } - queueDataFlush() - } - override fun onError() { - Logger.warning("unable to set key: " + key + " with value: " + attributeValue) - } - }) + override fun onError() { + Logger.warning("unable to set key: " + key + " with value: " + attributeValue) + } + }) } // Expected Date Format @"yyyy'-'MM'-'dd" @@ -376,17 +380,18 @@ open class AppboyKit : } override fun setUserAttributeList(key: String, list: List) { - Braze.getInstance(context).getCurrentUser(object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - val array = list.toTypedArray() - value.setCustomAttributeArray(key, array) - queueDataFlush() - } + Braze.getInstance(context) + .getCurrentUser(object : IValueCallback { + override fun onSuccess(value: BrazeUser) { + val array = list.toTypedArray() + value.setCustomAttributeArray(key, array) + queueDataFlush() + } - override fun onError() { - Logger.warning("unable to set key: " + key + " with User Attribute List: " + list) - } - }) + override fun onError() { + Logger.warning("unable to set key: " + key + " with User Attribute List: " + list) + } + }) } override fun onIncrementUserAttribute(key: String?, incrementedBy: Number?, value: String?, user: FilteredMParticleUser?) { @@ -412,6 +417,7 @@ open class AppboyKit : } override fun supportsAttributeLists(): Boolean = true + override fun onConsentStateUpdated(oldState: ConsentState, newState: ConsentState, user: FilteredMParticleUser) { setConsent(newState) } @@ -428,30 +434,33 @@ open class AppboyKit : JSONObject(isConsentAvailable.toString()).opt("consented") as Boolean when (currentConsent.value) { - "google_ad_user_data" -> setConsentValueToBraze( - KEY_GOOGLE_AD_USER_DATA, - isConsentGranted, - ) - - "google_ad_personalization" -> setConsentValueToBraze( - KEY_GOOGLE_AD_PERSONALIZATION, - isConsentGranted, - ) + "google_ad_user_data" -> + setConsentValueToBraze( + KEY_GOOGLE_AD_USER_DATA, + isConsentGranted, + ) + + "google_ad_personalization" -> + setConsentValueToBraze( + KEY_GOOGLE_AD_PERSONALIZATION, + isConsentGranted, + ) } } } } private fun setConsentValueToBraze(key: String, value: Boolean) { - Braze.getInstance(context).getCurrentUser(object : IValueCallback { - override fun onSuccess(brazeUser: BrazeUser) { - brazeUser.setCustomUserAttribute(key, value) - } + Braze.getInstance(context) + .getCurrentUser(object : IValueCallback { + override fun onSuccess(brazeUser: BrazeUser) { + brazeUser.setCustomUserAttribute(key, value) + } - override fun onError() { - super.onError() - } - }) + override fun onError() { + super.onError() + } + }) } private fun parseConsentMapping(json: String?): Map { @@ -546,44 +555,48 @@ open class AppboyKit : override fun removeUserAttribute(keyIn: String) { var key = keyIn - Braze.getInstance(context).getCurrentUser(object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - if (UserAttributes.CITY == key) { - value.setHomeCity(null) - } else if (UserAttributes.COUNTRY == key) { - value.setCountry(null) - } else if (UserAttributes.FIRSTNAME == key) { - value.setFirstName(null) - } // else if (UserAttributes.GENDER == key) { //Braze SDK wont allow for gender parameter to be null. - // user.setGender(null)} - else if (UserAttributes.LASTNAME == key) { - value.setLastName(null) - } else if (UserAttributes.MOBILE_NUMBER == key) { - value.setPhoneNumber(null) - } else { - if (key.startsWith("$")) { - key = key.substring(1) + Braze.getInstance(context) + .getCurrentUser(object : IValueCallback { + override fun onSuccess(value: BrazeUser) { + if (UserAttributes.CITY == key) { + value.setHomeCity(null) + } else if (UserAttributes.COUNTRY == key) { + value.setCountry(null) + } else if (UserAttributes.FIRSTNAME == key) { + value.setFirstName(null) + } else if (UserAttributes.LASTNAME == key) { + value.setLastName(null) + } else if (UserAttributes.MOBILE_NUMBER == key) { + value.setPhoneNumber(null) + } else { + if (key.startsWith("$")) { + key = key.substring(1) + } + value.unsetCustomUserAttribute(key) } - value.unsetCustomUserAttribute(key) + queueDataFlush() } - queueDataFlush() - } - override fun onError() { - Logger.warning("unable to remove User Attribute with key: " + key) - } - }) + override fun onError() { + Logger.warning("unable to remove User Attribute with key: " + key) + } + }) } override fun setUserIdentity(identityType: IdentityType, identity: String) {} + override fun removeUserIdentity(identityType: IdentityType) {} + override fun logout(): List = emptyList() fun logTransaction(event: CommerceEvent?, product: Product) { val purchaseProperties = BrazeProperties() val currency = arrayOfNulls(1) val commerceTypeParser: StringTypeParser = - BrazePropertiesSetter(purchaseProperties, enableTypeDetection) + BrazePropertiesSetter( + purchaseProperties, + enableTypeDetection, + ) val onAttributeExtracted: OnAttributeExtracted = object : OnAttributeExtracted { override fun onAttributeExtracted(key: String, value: String) { if (!checkCurrency(key, value)) { @@ -677,7 +690,10 @@ open class AppboyKit : val properties = BrazeProperties() val currency = arrayOfNulls(1) val commerceTypeParser: StringTypeParser = - BrazePropertiesSetter(properties, enableTypeDetection) + BrazePropertiesSetter( + properties, + enableTypeDetection, + ) val onAttributeExtracted: OnAttributeExtracted = object : OnAttributeExtracted { override fun onAttributeExtracted(key: String, value: String) { if (!checkCurrency(key, value)) { @@ -752,13 +768,22 @@ open class AppboyKit : } else { if (!KitUtils.isEmpty(event?.productAction)) { Braze.getInstance(context) - .logCustomEvent(String.format(eventName, event?.productAction), properties) + .logCustomEvent( + String.format(eventName, event?.productAction), + properties, + ) } else if (!KitUtils.isEmpty(event?.promotionAction)) { Braze.getInstance(context) - .logCustomEvent(String.format(eventName, event?.promotionAction), properties) + .logCustomEvent( + String.format(eventName, event?.promotionAction), + properties, + ) } else { Braze.getInstance(context) - .logCustomEvent(String.format(eventName, "Impression"), properties) + .logCustomEvent( + String.format(eventName, "Impression"), + properties, + ) } } } @@ -790,7 +815,8 @@ open class AppboyKit : protected open fun setAuthority(authority: String?) { Braze.setEndpointProvider { appboyEndpoint -> appboyEndpoint.buildUpon() - .authority(authority).build() + .authority(authority) + .build() } } @@ -828,33 +854,35 @@ open class AppboyKit : } protected open fun setId(customerId: String) { - Braze.getInstance(context).getCurrentUser(object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - if (value.userId != customerId) { - Braze.getInstance(context).changeUser(customerId) - queueDataFlush() + Braze.getInstance(context) + .getCurrentUser(object : IValueCallback { + override fun onSuccess(value: BrazeUser) { + if (value.userId != customerId) { + Braze.getInstance(context).changeUser(customerId) + queueDataFlush() + } } - } - override fun onError() { - Logger.warning("unable to change user to customer ID: " + customerId) - } - }) + override fun onError() { + Logger.warning("unable to change user to customer ID: " + customerId) + } + }) } protected open fun setEmail(email: String) { if (email != kitPreferences.getString(PREF_KEY_CURRENT_EMAIL, null)) { - Braze.getInstance(context).getCurrentUser(object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - value.setEmail(email) - queueDataFlush() - kitPreferences.edit().putString(PREF_KEY_CURRENT_EMAIL, email).apply() - } + Braze.getInstance(context) + .getCurrentUser(object : IValueCallback { + override fun onSuccess(value: BrazeUser) { + value.setEmail(email) + queueDataFlush() + kitPreferences.edit().putString(PREF_KEY_CURRENT_EMAIL, email).apply() + } - override fun onError() { - Logger.warning("unable to set email with value: " + email) - } - }) + override fun onError() { + Logger.warning("unable to set email with value: " + email) + } + }) } } @@ -1030,7 +1058,8 @@ open class AppboyKit : toString(key, value) return value } - return if (true.toString().equals(value, true) || + return if ( + true.toString().equals(value, true) || false.toString().equals( value, true, @@ -1064,9 +1093,13 @@ open class AppboyKit : } abstract fun toInt(key: String, value: Int) + abstract fun toLong(key: String, value: Long) + abstract fun toDouble(key: String, value: Double) + abstract fun toBoolean(key: String, value: Boolean) + abstract fun toString(key: String, value: String) } @@ -1093,7 +1126,8 @@ open class AppboyKit : } } - internal inner class UserAttributeSetter(private var brazeUser: BrazeUser, enableTypeDetection: Boolean) : StringTypeParser(enableTypeDetection) { + internal inner class UserAttributeSetter(private var brazeUser: BrazeUser, enableTypeDetection: Boolean) : + StringTypeParser(enableTypeDetection) { override fun toInt(key: String, value: Int) { brazeUser.setCustomUserAttribute(key, value) } From adcc949d5980a4e881f7be6864cd183e236eb70a Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 14:23:58 -0500 Subject: [PATCH 08/14] Fix Lint Issue --- .../kotlin/com/mparticle/kits/AppboyKit.kt | 466 +++++++++++++----- 1 file changed, 329 insertions(+), 137 deletions(-) diff --git a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt index 3c2be32..49b014f 100644 --- a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt @@ -71,7 +71,10 @@ open class AppboyKit : override fun getName() = NAME - public override fun onKitCreate(settings: Map, context: Context): List? { + public override fun onKitCreate( + settings: Map, + context: Context, + ): List? { val key = settings[APPBOY_KEY] require(!KitUtils.isEmpty(key)) { "Braze key is empty." } @@ -97,19 +100,22 @@ open class AppboyKit : } } forwardScreenViews = settings[FORWARD_SCREEN_VIEWS].toBoolean() - subscriptionGroupIds = settings[SUBSCRIPTION_GROUP_MAPPING] - ?.let { - getSubscriptionGroupIds(it) - } + subscriptionGroupIds = + settings[SUBSCRIPTION_GROUP_MAPPING] + ?.let { + getSubscriptionGroupIds(it) + } if (key != null) { - val config = BrazeConfig.Builder() - .setApiKey(key) - .setSdkFlavor(SdkFlavor.MPARTICLE) - .setSdkMetadata(EnumSet.of(BrazeSdkMetadata.MPARTICLE)) - .build() + val config = + BrazeConfig.Builder() + .setApiKey(key) + .setSdkFlavor(SdkFlavor.MPARTICLE) + .setSdkMetadata(EnumSet.of(BrazeSdkMetadata.MPARTICLE)) + .build() Braze.configure(context, config) } - dataFlushRunnable = Runnable { + dataFlushRunnable = + Runnable { if (kitManager.isBackgrounded) { Braze.getInstance(getContext()).requestImmediateDataFlush() } @@ -146,11 +152,21 @@ open class AppboyKit : override fun setOptOut(optedOut: Boolean): List = emptyList() - override fun leaveBreadcrumb(breadcrumb: String): List = emptyList() + override fun leaveBreadcrumb( + breadcrumb: String, + ): List = emptyList() - override fun logError(message: String, errorAttributes: Map): List = emptyList() + override fun logError( + message: String, + errorAttributes: Map, + ): List = emptyList() - override fun logException(exception: Exception, exceptionAttributes: Map, message: String): List = emptyList() + override fun logException( + exception: Exception, + exceptionAttributes: Map, + message: String, + ): List = + emptyList() override fun logEvent(event: MPEvent): List { val newAttributes: MutableMap = HashMap() @@ -166,7 +182,8 @@ open class AppboyKit : } Braze.getInstance(context).logCustomEvent(event.eventName, properties) Braze.getInstance(context) - .getCurrentUser(object : IValueCallback { + .getCurrentUser( + object : IValueCallback { override fun onSuccess(value: BrazeUser) { val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) event.customAttributeStrings?.let { it -> @@ -190,13 +207,18 @@ open class AppboyKit : override fun onError() { Logger.warning("unable to acquire user to add or remove custom user attributes from events") } - }) + }, + ) } queueDataFlush() return listOf(ReportingMessage.fromEvent(this, event).setAttributes(newAttributes)) } - override fun logScreen(screenName: String, screenAttributes: Map?): List = if (forwardScreenViews) { + override fun logScreen( + screenName: String, + screenAttributes: Map?, + ): List = + if (forwardScreenViews) { if (screenAttributes == null) { Braze.getInstance(context).logCustomEvent(screenName) } else { @@ -217,10 +239,10 @@ open class AppboyKit : screenAttributes, ), ) - messages - } else { - emptyList() - } + messages + } else { + emptyList() + } override fun logLtvIncrease( valueIncreased: BigDecimal, @@ -278,10 +300,14 @@ open class AppboyKit : return messages } - override fun setUserAttribute(keyIn: String, attributeValue: String) { + override fun setUserAttribute( + keyIn: String, + attributeValue: String, + ) { var key = keyIn Braze.getInstance(context) - .getCurrentUser(object : IValueCallback { + .getCurrentUser( + object : IValueCallback { override fun onSuccess(value: BrazeUser) { val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) @@ -360,11 +386,15 @@ open class AppboyKit : override fun onError() { Logger.warning("unable to set key: " + key + " with value: " + attributeValue) } - }) + }, + ) } // Expected Date Format @"yyyy'-'MM'-'dd" - private fun useDobString(value: String, user: BrazeUser) { + private fun useDobString( + value: String, + user: BrazeUser, + ) { val dateFormat = SimpleDateFormat("yyyy-MM-dd") try { val calendar = Calendar.getInstance() @@ -379,9 +409,13 @@ open class AppboyKit : } } - override fun setUserAttributeList(key: String, list: List) { + override fun setUserAttributeList( + key: String, + list: List, + ) { Braze.getInstance(context) - .getCurrentUser(object : IValueCallback { + .getCurrentUser( + object : IValueCallback { override fun onSuccess(value: BrazeUser) { val array = list.toTypedArray() value.setCustomAttributeArray(key, array) @@ -391,22 +425,42 @@ open class AppboyKit : override fun onError() { Logger.warning("unable to set key: " + key + " with User Attribute List: " + list) } - }) + }, + ) } - override fun onIncrementUserAttribute(key: String?, incrementedBy: Number?, value: String?, user: FilteredMParticleUser?) { + override fun onIncrementUserAttribute( + key: String?, + incrementedBy: Number?, + value: String?, + user: FilteredMParticleUser?, + ) { } - override fun onRemoveUserAttribute(key: String?, user: FilteredMParticleUser?) { + override fun onRemoveUserAttribute( + key: String?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserAttribute(key: String?, value: Any?, user: FilteredMParticleUser?) { + override fun onSetUserAttribute( + key: String?, + value: Any?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserTag(key: String?, user: FilteredMParticleUser?) { + override fun onSetUserTag( + key: String?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserAttributeList(attributeKey: String?, attributeValueList: MutableList?, user: FilteredMParticleUser?) { + override fun onSetUserAttributeList( + attributeKey: String?, + attributeValueList: MutableList?, + user: FilteredMParticleUser?, + ) { } override fun onSetAllUserAttributes( @@ -418,7 +472,11 @@ open class AppboyKit : override fun supportsAttributeLists(): Boolean = true - override fun onConsentStateUpdated(oldState: ConsentState, newState: ConsentState, user: FilteredMParticleUser) { + override fun onConsentStateUpdated( + oldState: ConsentState, + newState: ConsentState, + user: FilteredMParticleUser, + ) { setConsent(newState) } @@ -450,9 +508,13 @@ open class AppboyKit : } } - private fun setConsentValueToBraze(key: String, value: Boolean) { + private fun setConsentValueToBraze( + key: String, + value: Boolean, + ) { Braze.getInstance(context) - .getCurrentUser(object : IValueCallback { + .getCurrentUser( + object : IValueCallback { override fun onSuccess(brazeUser: BrazeUser) { brazeUser.setCustomUserAttribute(key, value) } @@ -460,7 +522,8 @@ open class AppboyKit : override fun onError() { super.onError() } - }) + }, + ) } private fun parseConsentMapping(json: String?): Map { @@ -508,7 +571,10 @@ open class AppboyKit : return topLevelMap } - private fun searchKeyInNestedMap(map: Map<*, *>, key: Any): Any? { + private fun searchKeyInNestedMap( + map: Map<*, *>, + key: Any, + ): Any? { if (map.isNullOrEmpty()) { return null } @@ -541,7 +607,10 @@ open class AppboyKit : /** * This is called when the Kit is added to the mParticle SDK, typically on app-startup. */ - override fun setAllUserAttributes(attributes: Map, attributeLists: Map>) { + override fun setAllUserAttributes( + attributes: Map, + attributeLists: Map>, + ) { if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) { for ((key, value) in attributes) { setUserAttribute(key, value) @@ -556,7 +625,8 @@ open class AppboyKit : override fun removeUserAttribute(keyIn: String) { var key = keyIn Braze.getInstance(context) - .getCurrentUser(object : IValueCallback { + .getCurrentUser( + object : IValueCallback { override fun onSuccess(value: BrazeUser) { if (UserAttributes.CITY == key) { value.setHomeCity(null) @@ -580,16 +650,23 @@ open class AppboyKit : override fun onError() { Logger.warning("unable to remove User Attribute with key: " + key) } - }) + }, + ) } - override fun setUserIdentity(identityType: IdentityType, identity: String) {} + override fun setUserIdentity( + identityType: IdentityType, + identity: String, + ) {} override fun removeUserIdentity(identityType: IdentityType) {} override fun logout(): List = emptyList() - fun logTransaction(event: CommerceEvent?, product: Product) { + fun logTransaction( + event: CommerceEvent?, + product: Product, + ) { val purchaseProperties = BrazeProperties() val currency = arrayOfNulls(1) val commerceTypeParser: StringTypeParser = @@ -597,38 +674,52 @@ open class AppboyKit : purchaseProperties, enableTypeDetection, ) - val onAttributeExtracted: OnAttributeExtracted = object : OnAttributeExtracted { - override fun onAttributeExtracted(key: String, value: String) { + val onAttributeExtracted: OnAttributeExtracted = + object : OnAttributeExtracted { + override fun onAttributeExtracted( + key: String, + value: String, + ) { if (!checkCurrency(key, value)) { commerceTypeParser.parseValue(key, value) } - } + } - override fun onAttributeExtracted(key: String, value: Double) { - if (!checkCurrency(key, value)) { - purchaseProperties.addProperty(key, value) + override fun onAttributeExtracted( + key: String, + value: Double, + ) { + if (!checkCurrency(key, value)) { + purchaseProperties.addProperty(key, value) + } } - } - override fun onAttributeExtracted(key: String, value: Int) { - purchaseProperties.addProperty(key, value) - } + override fun onAttributeExtracted( + key: String, + value: Int, + ) { + purchaseProperties.addProperty(key, value) + } - override fun onAttributeExtracted(attributes: Map) { - for ((key, value) in attributes) { - if (!checkCurrency(key, value)) { - commerceTypeParser.parseValue(key, value) + override fun onAttributeExtracted(attributes: Map) { + for ((key, value) in attributes) { + if (!checkCurrency(key, value)) { + commerceTypeParser.parseValue(key, value) + } } } - } - private fun checkCurrency(key: String, value: Any?): Boolean = if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { - currency[0] = value?.toString() - true - } else { - false + private fun checkCurrency( + key: String, + value: Any?, + ): Boolean = + if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { + currency[0] = value?.toString() + true + } else { + false + } } - } CommerceEventUtils.extractActionAttributes(event, onAttributeExtracted) var currencyValue = currency[0] if (KitUtils.isEmpty(currencyValue)) { @@ -694,38 +785,52 @@ open class AppboyKit : properties, enableTypeDetection, ) - val onAttributeExtracted: OnAttributeExtracted = object : OnAttributeExtracted { - override fun onAttributeExtracted(key: String, value: String) { + val onAttributeExtracted: OnAttributeExtracted = + object : OnAttributeExtracted { + override fun onAttributeExtracted( + key: String, + value: String, + ) { if (!checkCurrency(key, value)) { commerceTypeParser.parseValue(key, value) } - } + } - override fun onAttributeExtracted(key: String, value: Double) { - if (!checkCurrency(key, value)) { - properties.addProperty(key, value) + override fun onAttributeExtracted( + key: String, + value: Double, + ) { + if (!checkCurrency(key, value)) { + properties.addProperty(key, value) + } } - } - override fun onAttributeExtracted(key: String, value: Int) { - properties.addProperty(key, value) - } + override fun onAttributeExtracted( + key: String, + value: Int, + ) { + properties.addProperty(key, value) + } - override fun onAttributeExtracted(attributes: Map) { - for ((key, value) in attributes) { - if (!checkCurrency(key, value)) { - commerceTypeParser.parseValue(key, value) + override fun onAttributeExtracted(attributes: Map) { + for ((key, value) in attributes) { + if (!checkCurrency(key, value)) { + commerceTypeParser.parseValue(key, value) + } } } - } - private fun checkCurrency(key: String, value: Any?): Boolean = if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { - currency[0] = value?.toString() - true - } else { - false + private fun checkCurrency( + key: String, + value: Any?, + ): Boolean = + if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { + currency[0] = value?.toString() + true + } else { + false + } } - } CommerceEventUtils.extractActionAttributes(event, onAttributeExtracted) var currencyValue = currency[0] if (KitUtils.isEmpty(currencyValue)) { @@ -788,13 +893,17 @@ open class AppboyKit : } } - override fun willHandlePushMessage(intent: Intent): Boolean = if (!(settings[PUSH_ENABLED].toBoolean())) { - false - } else { - intent.isBrazePushMessage() - } + override fun willHandlePushMessage(intent: Intent): Boolean = + if (!(settings[PUSH_ENABLED].toBoolean())) { + false + } else { + intent.isBrazePushMessage() + } - override fun onPushMessageReceived(context: Context, pushIntent: Intent) { + override fun onPushMessageReceived( + context: Context, + pushIntent: Intent, + ) { if (settings[PUSH_ENABLED].toBoolean()) { BrazeFirebaseMessagingService.handleBrazeRemoteMessage( context, @@ -803,14 +912,18 @@ open class AppboyKit : } } - override fun onPushRegistration(instanceId: String, senderId: String): Boolean = if (settings[PUSH_ENABLED].toBoolean()) { - updatedInstanceId = instanceId - Braze.getInstance(context).registeredPushToken = instanceId - queueDataFlush() - true - } else { - false - } + override fun onPushRegistration( + instanceId: String, + senderId: String, + ): Boolean = + if (settings[PUSH_ENABLED].toBoolean()) { + updatedInstanceId = instanceId + Braze.getInstance(context).registeredPushToken = instanceId + queueDataFlush() + true + } else { + false + } protected open fun setAuthority(authority: String?) { Braze.setEndpointProvider { appboyEndpoint -> @@ -820,19 +933,31 @@ open class AppboyKit : } } - override fun onIdentifyCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { + override fun onIdentifyCompleted( + mParticleUser: MParticleUser, + filteredIdentityApiRequest: FilteredIdentityApiRequest?, + ) { updateUser(mParticleUser) } - override fun onLoginCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { + override fun onLoginCompleted( + mParticleUser: MParticleUser, + filteredIdentityApiRequest: FilteredIdentityApiRequest?, + ) { updateUser(mParticleUser) } - override fun onLogoutCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { + override fun onLogoutCompleted( + mParticleUser: MParticleUser, + filteredIdentityApiRequest: FilteredIdentityApiRequest?, + ) { updateUser(mParticleUser) } - override fun onModifyCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { + override fun onModifyCompleted( + mParticleUser: MParticleUser, + filteredIdentityApiRequest: FilteredIdentityApiRequest?, + ) { updateUser(mParticleUser) } @@ -843,7 +968,11 @@ open class AppboyKit : email?.let { setEmail(it) } } - fun getIdentity(isMpidIdentityType: Boolean, identityType: IdentityType?, mParticleUser: MParticleUser?): String? { + fun getIdentity( + isMpidIdentityType: Boolean, + identityType: IdentityType?, + mParticleUser: MParticleUser?, + ): String? { var identity: String? = null if (isMpidIdentityType && mParticleUser != null) { identity = mParticleUser.id.toString() @@ -855,7 +984,8 @@ open class AppboyKit : protected open fun setId(customerId: String) { Braze.getInstance(context) - .getCurrentUser(object : IValueCallback { + .getCurrentUser( + object : IValueCallback { override fun onSuccess(value: BrazeUser) { if (value.userId != customerId) { Braze.getInstance(context).changeUser(customerId) @@ -866,13 +996,15 @@ open class AppboyKit : override fun onError() { Logger.warning("unable to change user to customer ID: " + customerId) } - }) + }, + ) } protected open fun setEmail(email: String) { if (email != kitPreferences.getString(PREF_KEY_CURRENT_EMAIL, null)) { Braze.getInstance(context) - .getCurrentUser(object : IValueCallback { + .getCurrentUser( + object : IValueCallback { override fun onSuccess(value: BrazeUser) { value.setEmail(email) queueDataFlush() @@ -882,7 +1014,8 @@ open class AppboyKit : override fun onError() { Logger.warning("unable to set email with value: " + email) } - }) + }, + ) } } @@ -892,7 +1025,11 @@ open class AppboyKit : } } - fun addToProperties(properties: BrazeProperties, key: String, value: String) { + fun addToProperties( + properties: BrazeProperties, + key: String, + value: String, + ) { try { if ("true".equals(value, true) || "false".equals( @@ -928,13 +1065,14 @@ open class AppboyKit : return null } - fun getCalendarMinusYears(years: Int): Calendar? = if (years >= 0) { - val calendar = Calendar.getInstance() - calendar[Calendar.YEAR] = calendar[Calendar.YEAR] - years - calendar - } else { - null - } + fun getCalendarMinusYears(years: Int): Calendar? = + if (years >= 0) { + val calendar = Calendar.getInstance() + calendar[Calendar.YEAR] = calendar[Calendar.YEAR] - years + calendar + } else { + null + } fun getProductListParameters(productList: List): JSONArray { val productArray = JSONArray() @@ -1052,8 +1190,13 @@ open class AppboyKit : return impressionArray } - internal abstract class StringTypeParser(var enableTypeDetection: Boolean) { - fun parseValue(key: String, value: String): Any { + internal abstract class StringTypeParser( + var enableTypeDetection: Boolean, + ) { + fun parseValue( + key: String, + value: String, + ): Any { if (!enableTypeDetection) { toString(key, value) return value @@ -1092,59 +1235,108 @@ open class AppboyKit : } } - abstract fun toInt(key: String, value: Int) + abstract fun toInt( + key: String, + value: Int, + ) - abstract fun toLong(key: String, value: Long) + abstract fun toLong( + key: String, + value: Long, + ) - abstract fun toDouble(key: String, value: Double) + abstract fun toDouble( + key: String, + value: Double, + ) - abstract fun toBoolean(key: String, value: Boolean) + abstract fun toBoolean( + key: String, + value: Boolean, + ) - abstract fun toString(key: String, value: String) + abstract fun toString( + key: String, + value: String, + ) } - internal inner class BrazePropertiesSetter(private var properties: BrazeProperties, enableTypeDetection: Boolean) : - StringTypeParser(enableTypeDetection) { - override fun toInt(key: String, value: Int) { + internal inner class BrazePropertiesSetter( + private var properties: BrazeProperties, + enableTypeDetection: Boolean, + ) : StringTypeParser(enableTypeDetection) { + override fun toInt( + key: String, + value: Int, + ) { properties.addProperty(key, value) } - override fun toLong(key: String, value: Long) { + override fun toLong( + key: String, + value: Long, + ) { properties.addProperty(key, value) } - override fun toDouble(key: String, value: Double) { + override fun toDouble( + key: String, + value: Double, + ) { properties.addProperty(key, value) } - override fun toBoolean(key: String, value: Boolean) { + override fun toBoolean( + key: String, + value: Boolean, + ) { properties.addProperty(key, value) } - override fun toString(key: String, value: String) { + override fun toString( + key: String, + value: String, + ) { properties.addProperty(key, value) } } - internal inner class UserAttributeSetter(private var brazeUser: BrazeUser, enableTypeDetection: Boolean) : - StringTypeParser(enableTypeDetection) { - override fun toInt(key: String, value: Int) { + internal inner class UserAttributeSetter( + private var brazeUser: BrazeUser, + enableTypeDetection: Boolean, + ) : StringTypeParser(enableTypeDetection) { + override fun toInt( + key: String, + value: Int, + ) { brazeUser.setCustomUserAttribute(key, value) } - override fun toLong(key: String, value: Long) { + override fun toLong( + key: String, + value: Long, + ) { brazeUser.setCustomUserAttribute(key, value) } - override fun toDouble(key: String, value: Double) { + override fun toDouble( + key: String, + value: Double, + ) { brazeUser.setCustomUserAttribute(key, value) } - override fun toBoolean(key: String, value: Boolean) { + override fun toBoolean( + key: String, + value: Boolean, + ) { brazeUser.setCustomUserAttribute(key, value) } - override fun toString(key: String, value: String) { + override fun toString( + key: String, + value: String, + ) { brazeUser.setCustomUserAttribute(key, value) } } From 6d1f47b200f4dc080a86ad2b01ae73c083a18e1a Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 14:51:18 -0500 Subject: [PATCH 09/14] Fix the lint error and properties --- gradle.properties | 1 - .../kotlin/com/mparticle/kits/AppboyKit.kt | 369 +++++++++--------- 2 files changed, 188 insertions(+), 182 deletions(-) diff --git a/gradle.properties b/gradle.properties index 988448b..56fb79f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,4 @@ android.enableJetifier=true android.useAndroidX=true org.gradle.daemon=true -org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g diff --git a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt index 49b014f..20915b9 100644 --- a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt @@ -107,7 +107,8 @@ open class AppboyKit : } if (key != null) { val config = - BrazeConfig.Builder() + BrazeConfig + .Builder() .setApiKey(key) .setSdkFlavor(SdkFlavor.MPARTICLE) .setSdkMetadata(EnumSet.of(BrazeSdkMetadata.MPARTICLE)) @@ -116,10 +117,10 @@ open class AppboyKit : } dataFlushRunnable = Runnable { - if (kitManager.isBackgrounded) { - Braze.getInstance(getContext()).requestImmediateDataFlush() + if (kitManager.isBackgrounded) { + Braze.getInstance(getContext()).requestImmediateDataFlush() + } } - } queueDataFlush() if (setDefaultAppboyLifecycleCallbackListener) { (context.applicationContext as Application).registerActivityLifecycleCallbacks( @@ -152,9 +153,7 @@ open class AppboyKit : override fun setOptOut(optedOut: Boolean): List = emptyList() - override fun leaveBreadcrumb( - breadcrumb: String, - ): List = emptyList() + override fun leaveBreadcrumb(breadcrumb: String): List = emptyList() override fun logError( message: String, @@ -165,8 +164,7 @@ open class AppboyKit : exception: Exception, exceptionAttributes: Map, message: String, - ): List = - emptyList() + ): List = emptyList() override fun logEvent(event: MPEvent): List { val newAttributes: MutableMap = HashMap() @@ -184,30 +182,30 @@ open class AppboyKit : Braze.getInstance(context) .getCurrentUser( object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) - event.customAttributeStrings?.let { it -> - for ((key, attributeValue) in it) { - val hashedKey = - KitUtils.hashForFiltering(event.eventType.value.toString() + event.eventName + key) - - configuration.eventAttributesAddToUser?.get(hashedKey)?.let { - value.addToCustomAttributeArray(it, attributeValue) - } - configuration.eventAttributesRemoveFromUser?.get(hashedKey)?.let { - value.removeFromCustomAttributeArray(it, attributeValue) - } - configuration.eventAttributesSingleItemUser?.get(hashedKey)?.let { - userAttributeSetter.parseValue(it, attributeValue) + override fun onSuccess(value: BrazeUser) { + val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) + event.customAttributeStrings?.let { it -> + for ((key, attributeValue) in it) { + val hashedKey = + KitUtils.hashForFiltering(event.eventType.value.toString() + event.eventName + key) + + configuration.eventAttributesAddToUser?.get(hashedKey)?.let { + value.addToCustomAttributeArray(it, attributeValue) + } + configuration.eventAttributesRemoveFromUser?.get(hashedKey)?.let { + value.removeFromCustomAttributeArray(it, attributeValue) + } + configuration.eventAttributesSingleItemUser?.get(hashedKey)?.let { + userAttributeSetter.parseValue(it, attributeValue) + } } } } - } - override fun onError() { - Logger.warning("unable to acquire user to add or remove custom user attributes from events") - } - }, + override fun onError() { + Logger.warning("unable to acquire user to add or remove custom user attributes from events") + } + }, ) } queueDataFlush() @@ -219,26 +217,26 @@ open class AppboyKit : screenAttributes: Map?, ): List = if (forwardScreenViews) { - if (screenAttributes == null) { - Braze.getInstance(context).logCustomEvent(screenName) - } else { - val properties = BrazeProperties() - val propertyParser = BrazePropertiesSetter(properties, enableTypeDetection) - for ((key, value) in screenAttributes) { - propertyParser.parseValue(key, value) + if (screenAttributes == null) { + Braze.getInstance(context).logCustomEvent(screenName) + } else { + val properties = BrazeProperties() + val propertyParser = BrazePropertiesSetter(properties, enableTypeDetection) + for ((key, value) in screenAttributes) { + propertyParser.parseValue(key, value) + } + Braze.getInstance(context).logCustomEvent(screenName, properties) } - Braze.getInstance(context).logCustomEvent(screenName, properties) - } - queueDataFlush() - val messages: MutableList = LinkedList() - messages.add( - ReportingMessage( - this, - ReportingMessage.MessageType.SCREEN_VIEW, - System.currentTimeMillis(), - screenAttributes, - ), - ) + queueDataFlush() + val messages: MutableList = LinkedList() + messages.add( + ReportingMessage( + this, + ReportingMessage.MessageType.SCREEN_VIEW, + System.currentTimeMillis(), + screenAttributes, + ), + ) messages } else { emptyList() @@ -308,85 +306,85 @@ open class AppboyKit : Braze.getInstance(context) .getCurrentUser( object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) - - when (key) { - UserAttributes.CITY -> value.setHomeCity(attributeValue) - UserAttributes.COUNTRY -> value.setCountry(attributeValue) - UserAttributes.FIRSTNAME -> value.setFirstName(attributeValue) - UserAttributes.LASTNAME -> value.setLastName(attributeValue) - UserAttributes.MOBILE_NUMBER -> value.setPhoneNumber(attributeValue) - UserAttributes.ZIPCODE -> value.setCustomUserAttribute("Zip", attributeValue) - UserAttributes.AGE -> { - val calendar = getCalendarMinusYears(attributeValue) - if (calendar != null) { - value.setDateOfBirth(calendar[Calendar.YEAR], Month.JANUARY, 1) - } else { - Logger.warning("unable to set DateOfBirth for " + UserAttributes.AGE + " = " + value) + override fun onSuccess(value: BrazeUser) { + val userAttributeSetter = UserAttributeSetter(value, enableTypeDetection) + + when (key) { + UserAttributes.CITY -> value.setHomeCity(attributeValue) + UserAttributes.COUNTRY -> value.setCountry(attributeValue) + UserAttributes.FIRSTNAME -> value.setFirstName(attributeValue) + UserAttributes.LASTNAME -> value.setLastName(attributeValue) + UserAttributes.MOBILE_NUMBER -> value.setPhoneNumber(attributeValue) + UserAttributes.ZIPCODE -> value.setCustomUserAttribute("Zip", attributeValue) + UserAttributes.AGE -> { + val calendar = getCalendarMinusYears(attributeValue) + if (calendar != null) { + value.setDateOfBirth(calendar[Calendar.YEAR], Month.JANUARY, 1) + } else { + Logger.warning("unable to set DateOfBirth for " + UserAttributes.AGE + " = " + value) + } } - } - EMAIL_SUBSCRIBE -> { - when (attributeValue) { - OPTED_IN -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.OPTED_IN) - UNSUBSCRIBED -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.UNSUBSCRIBED) - SUBSCRIBED -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.SUBSCRIBED) - else -> { - Logger.warning("unable to set email_subscribe with invalid value: " + value) + EMAIL_SUBSCRIBE -> { + when (attributeValue) { + OPTED_IN -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.OPTED_IN) + UNSUBSCRIBED -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.UNSUBSCRIBED) + SUBSCRIBED -> value.setEmailNotificationSubscriptionType(NotificationSubscriptionType.SUBSCRIBED) + else -> { + Logger.warning("unable to set email_subscribe with invalid value: " + value) + } } } - } - PUSH_SUBSCRIBE -> { - when (attributeValue) { - OPTED_IN -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.OPTED_IN) - UNSUBSCRIBED -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.UNSUBSCRIBED) - SUBSCRIBED -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.SUBSCRIBED) - else -> { - Logger.warning("unable to set push_subscribe with invalid value: " + value) + PUSH_SUBSCRIBE -> { + when (attributeValue) { + OPTED_IN -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.OPTED_IN) + UNSUBSCRIBED -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.UNSUBSCRIBED) + SUBSCRIBED -> value.setPushNotificationSubscriptionType(NotificationSubscriptionType.SUBSCRIBED) + else -> { + Logger.warning("unable to set push_subscribe with invalid value: " + value) + } } } - } - DOB -> useDobString(attributeValue, value) - UserAttributes.GENDER -> { - if (attributeValue.contains("fe")) { - value.setGender(Gender.FEMALE) - } else { - value.setGender(Gender.MALE) + DOB -> useDobString(attributeValue, value) + UserAttributes.GENDER -> { + if (attributeValue.contains("fe")) { + value.setGender(Gender.FEMALE) + } else { + value.setGender(Gender.MALE) + } } - } - else -> { - if (subscriptionGroupIds?.containsKey(key) == true) { - val groupId = subscriptionGroupIds?.get(key) - when (attributeValue.lowercase()) { - "true" -> { - groupId?.let { value.addToSubscriptionGroup(it) } + else -> { + if (subscriptionGroupIds?.containsKey(key) == true) { + val groupId = subscriptionGroupIds?.get(key) + when (attributeValue.lowercase()) { + "true" -> { + groupId?.let { value.addToSubscriptionGroup(it) } + } + + "false" -> { + groupId?.let { value.removeFromSubscriptionGroup(it) } + } + + else -> { + Logger.warning( + "Unable to set Subscription Group ID for user attribute: $key due to invalid value data type. Expected Boolean.", + ) + } } - - "false" -> { - groupId?.let { value.removeFromSubscriptionGroup(it) } - } - - else -> { - Logger.warning( - "Unable to set Subscription Group ID for user attribute: $key due to invalid value data type. Expected Boolean.", - ) + } else { + if (key.startsWith("$")) { + key = key.substring(1) } + userAttributeSetter?.parseValue(key, attributeValue) } - } else { - if (key.startsWith("$")) { - key = key.substring(1) - } - userAttributeSetter?.parseValue(key, attributeValue) } } + queueDataFlush() } - queueDataFlush() - } - override fun onError() { - Logger.warning("unable to set key: " + key + " with value: " + attributeValue) - } - }, + override fun onError() { + Logger.warning("unable to set key: " + key + " with value: " + attributeValue) + } + }, ) } @@ -416,16 +414,16 @@ open class AppboyKit : Braze.getInstance(context) .getCurrentUser( object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - val array = list.toTypedArray() - value.setCustomAttributeArray(key, array) - queueDataFlush() - } + override fun onSuccess(value: BrazeUser) { + val array = list.toTypedArray() + value.setCustomAttributeArray(key, array) + queueDataFlush() + } - override fun onError() { - Logger.warning("unable to set key: " + key + " with User Attribute List: " + list) - } - }, + override fun onError() { + Logger.warning("unable to set key: " + key + " with User Attribute List: " + list) + } + }, ) } @@ -515,14 +513,14 @@ open class AppboyKit : Braze.getInstance(context) .getCurrentUser( object : IValueCallback { - override fun onSuccess(brazeUser: BrazeUser) { - brazeUser.setCustomUserAttribute(key, value) - } + override fun onSuccess(brazeUser: BrazeUser) { + brazeUser.setCustomUserAttribute(key, value) + } - override fun onError() { - super.onError() - } - }, + override fun onError() { + super.onError() + } + }, ) } @@ -627,30 +625,30 @@ open class AppboyKit : Braze.getInstance(context) .getCurrentUser( object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - if (UserAttributes.CITY == key) { - value.setHomeCity(null) - } else if (UserAttributes.COUNTRY == key) { - value.setCountry(null) - } else if (UserAttributes.FIRSTNAME == key) { - value.setFirstName(null) - } else if (UserAttributes.LASTNAME == key) { - value.setLastName(null) - } else if (UserAttributes.MOBILE_NUMBER == key) { - value.setPhoneNumber(null) - } else { - if (key.startsWith("$")) { - key = key.substring(1) + override fun onSuccess(value: BrazeUser) { + if (UserAttributes.CITY == key) { + value.setHomeCity(null) + } else if (UserAttributes.COUNTRY == key) { + value.setCountry(null) + } else if (UserAttributes.FIRSTNAME == key) { + value.setFirstName(null) + } else if (UserAttributes.LASTNAME == key) { + value.setLastName(null) + } else if (UserAttributes.MOBILE_NUMBER == key) { + value.setPhoneNumber(null) + } else { + if (key.startsWith("$")) { + key = key.substring(1) + } + value.unsetCustomUserAttribute(key) } - value.unsetCustomUserAttribute(key) + queueDataFlush() } - queueDataFlush() - } - override fun onError() { - Logger.warning("unable to remove User Attribute with key: " + key) - } - }, + override fun onError() { + Logger.warning("unable to remove User Attribute with key: " + key) + } + }, ) } @@ -680,9 +678,9 @@ open class AppboyKit : key: String, value: String, ) { - if (!checkCurrency(key, value)) { - commerceTypeParser.parseValue(key, value) - } + if (!checkCurrency(key, value)) { + commerceTypeParser.parseValue(key, value) + } } override fun onAttributeExtracted( @@ -791,9 +789,9 @@ open class AppboyKit : key: String, value: String, ) { - if (!checkCurrency(key, value)) { - commerceTypeParser.parseValue(key, value) - } + if (!checkCurrency(key, value)) { + commerceTypeParser.parseValue(key, value) + } } override fun onAttributeExtracted( @@ -872,19 +870,22 @@ open class AppboyKit : ) } else { if (!KitUtils.isEmpty(event?.productAction)) { - Braze.getInstance(context) + Braze + .getInstance(context) .logCustomEvent( String.format(eventName, event?.productAction), properties, ) } else if (!KitUtils.isEmpty(event?.promotionAction)) { - Braze.getInstance(context) + Braze + .getInstance(context) .logCustomEvent( String.format(eventName, event?.promotionAction), properties, ) } else { - Braze.getInstance(context) + Braze + .getInstance(context) .logCustomEvent( String.format(eventName, "Impression"), properties, @@ -927,7 +928,8 @@ open class AppboyKit : protected open fun setAuthority(authority: String?) { Braze.setEndpointProvider { appboyEndpoint -> - appboyEndpoint.buildUpon() + appboyEndpoint + .buildUpon() .authority(authority) .build() } @@ -983,38 +985,43 @@ open class AppboyKit : } protected open fun setId(customerId: String) { - Braze.getInstance(context) + Braze + .getInstance(context) .getCurrentUser( object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - if (value.userId != customerId) { - Braze.getInstance(context).changeUser(customerId) - queueDataFlush() + override fun onSuccess(value: BrazeUser) { + if (value.userId != customerId) { + Braze.getInstance(context).changeUser(customerId) + queueDataFlush() + } } - } - override fun onError() { - Logger.warning("unable to change user to customer ID: " + customerId) - } - }, + override fun onError() { + Logger.warning("unable to change user to customer ID: " + customerId) + } + }, ) } protected open fun setEmail(email: String) { if (email != kitPreferences.getString(PREF_KEY_CURRENT_EMAIL, null)) { - Braze.getInstance(context) + Braze + .getInstance(context) .getCurrentUser( object : IValueCallback { - override fun onSuccess(value: BrazeUser) { - value.setEmail(email) - queueDataFlush() - kitPreferences.edit().putString(PREF_KEY_CURRENT_EMAIL, email).apply() - } + override fun onSuccess(value: BrazeUser) { + value.setEmail(email) + queueDataFlush() + kitPreferences + .edit() + .putString(PREF_KEY_CURRENT_EMAIL, email) + .apply() + } - override fun onError() { - Logger.warning("unable to set email with value: " + email) - } - }, + override fun onError() { + Logger.warning("unable to set email with value: " + email) + } + }, ) } } From f42cc87b5cbdfde6b5ce257686bb4414258cc5a6 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 15:12:50 -0500 Subject: [PATCH 10/14] added lint rule --- build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.gradle b/build.gradle index 2e5b99a..279a387 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,12 @@ android { kotlinOptions { jvmTarget = '17' } + lint { + abortOnError = false + checkReleaseBuilds = false + ignoreWarnings = true + baseline = file("lint-baseline.xml") + } testOptions { unitTests.all { jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] From 71a16a4b8cecba7e75fcd4021ff05672d3d69156 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 15:32:54 -0500 Subject: [PATCH 11/14] Reset gradle config --- build.gradle | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 279a387..43727ed 100644 --- a/build.gradle +++ b/build.gradle @@ -35,12 +35,12 @@ apply plugin: 'com.mparticle.kit' android { namespace 'com.mparticle.kits.appboy' - defaultConfig { - minSdkVersion 21 - } buildFeatures { buildConfig = true } + defaultConfig { + minSdkVersion 21 + } compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 @@ -48,12 +48,6 @@ android { kotlinOptions { jvmTarget = '17' } - lint { - abortOnError = false - checkReleaseBuilds = false - ignoreWarnings = true - baseline = file("lint-baseline.xml") - } testOptions { unitTests.all { jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] From 43fd557c405b344152f8df11745a78cb643ac240 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Fri, 16 Jan 2026 15:49:57 -0500 Subject: [PATCH 12/14] Apply ktlint format --- .../kotlin/com/mparticle/kits/AppboyKit.kt | 382 +++++------------- 1 file changed, 106 insertions(+), 276 deletions(-) diff --git a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt index 20915b9..1846c3f 100644 --- a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt @@ -71,10 +71,7 @@ open class AppboyKit : override fun getName() = NAME - public override fun onKitCreate( - settings: Map, - context: Context, - ): List? { + public override fun onKitCreate(settings: Map, context: Context): List? { val key = settings[APPBOY_KEY] require(!KitUtils.isEmpty(key)) { "Braze key is empty." } @@ -155,16 +152,9 @@ open class AppboyKit : override fun leaveBreadcrumb(breadcrumb: String): List = emptyList() - override fun logError( - message: String, - errorAttributes: Map, - ): List = emptyList() + override fun logError(message: String, errorAttributes: Map): List = emptyList() - override fun logException( - exception: Exception, - exceptionAttributes: Map, - message: String, - ): List = emptyList() + override fun logException(exception: Exception, exceptionAttributes: Map, message: String): List = emptyList() override fun logEvent(event: MPEvent): List { val newAttributes: MutableMap = HashMap() @@ -212,35 +202,31 @@ open class AppboyKit : return listOf(ReportingMessage.fromEvent(this, event).setAttributes(newAttributes)) } - override fun logScreen( - screenName: String, - screenAttributes: Map?, - ): List = - if (forwardScreenViews) { - if (screenAttributes == null) { - Braze.getInstance(context).logCustomEvent(screenName) - } else { - val properties = BrazeProperties() - val propertyParser = BrazePropertiesSetter(properties, enableTypeDetection) - for ((key, value) in screenAttributes) { - propertyParser.parseValue(key, value) - } - Braze.getInstance(context).logCustomEvent(screenName, properties) - } - queueDataFlush() - val messages: MutableList = LinkedList() - messages.add( - ReportingMessage( - this, - ReportingMessage.MessageType.SCREEN_VIEW, - System.currentTimeMillis(), - screenAttributes, - ), - ) - messages + override fun logScreen(screenName: String, screenAttributes: Map?): List = if (forwardScreenViews) { + if (screenAttributes == null) { + Braze.getInstance(context).logCustomEvent(screenName) } else { - emptyList() + val properties = BrazeProperties() + val propertyParser = BrazePropertiesSetter(properties, enableTypeDetection) + for ((key, value) in screenAttributes) { + propertyParser.parseValue(key, value) + } + Braze.getInstance(context).logCustomEvent(screenName, properties) } + queueDataFlush() + val messages: MutableList = LinkedList() + messages.add( + ReportingMessage( + this, + ReportingMessage.MessageType.SCREEN_VIEW, + System.currentTimeMillis(), + screenAttributes, + ), + ) + messages + } else { + emptyList() + } override fun logLtvIncrease( valueIncreased: BigDecimal, @@ -298,10 +284,7 @@ open class AppboyKit : return messages } - override fun setUserAttribute( - keyIn: String, - attributeValue: String, - ) { + override fun setUserAttribute(keyIn: String, attributeValue: String) { var key = keyIn Braze.getInstance(context) .getCurrentUser( @@ -389,10 +372,7 @@ open class AppboyKit : } // Expected Date Format @"yyyy'-'MM'-'dd" - private fun useDobString( - value: String, - user: BrazeUser, - ) { + private fun useDobString(value: String, user: BrazeUser) { val dateFormat = SimpleDateFormat("yyyy-MM-dd") try { val calendar = Calendar.getInstance() @@ -407,10 +387,7 @@ open class AppboyKit : } } - override fun setUserAttributeList( - key: String, - list: List, - ) { + override fun setUserAttributeList(key: String, list: List) { Braze.getInstance(context) .getCurrentUser( object : IValueCallback { @@ -427,38 +404,19 @@ open class AppboyKit : ) } - override fun onIncrementUserAttribute( - key: String?, - incrementedBy: Number?, - value: String?, - user: FilteredMParticleUser?, - ) { + override fun onIncrementUserAttribute(key: String?, incrementedBy: Number?, value: String?, user: FilteredMParticleUser?) { } - override fun onRemoveUserAttribute( - key: String?, - user: FilteredMParticleUser?, - ) { + override fun onRemoveUserAttribute(key: String?, user: FilteredMParticleUser?) { } - override fun onSetUserAttribute( - key: String?, - value: Any?, - user: FilteredMParticleUser?, - ) { + override fun onSetUserAttribute(key: String?, value: Any?, user: FilteredMParticleUser?) { } - override fun onSetUserTag( - key: String?, - user: FilteredMParticleUser?, - ) { + override fun onSetUserTag(key: String?, user: FilteredMParticleUser?) { } - override fun onSetUserAttributeList( - attributeKey: String?, - attributeValueList: MutableList?, - user: FilteredMParticleUser?, - ) { + override fun onSetUserAttributeList(attributeKey: String?, attributeValueList: MutableList?, user: FilteredMParticleUser?) { } override fun onSetAllUserAttributes( @@ -470,11 +428,7 @@ open class AppboyKit : override fun supportsAttributeLists(): Boolean = true - override fun onConsentStateUpdated( - oldState: ConsentState, - newState: ConsentState, - user: FilteredMParticleUser, - ) { + override fun onConsentStateUpdated(oldState: ConsentState, newState: ConsentState, user: FilteredMParticleUser) { setConsent(newState) } @@ -506,10 +460,7 @@ open class AppboyKit : } } - private fun setConsentValueToBraze( - key: String, - value: Boolean, - ) { + private fun setConsentValueToBraze(key: String, value: Boolean) { Braze.getInstance(context) .getCurrentUser( object : IValueCallback { @@ -569,10 +520,7 @@ open class AppboyKit : return topLevelMap } - private fun searchKeyInNestedMap( - map: Map<*, *>, - key: Any, - ): Any? { + private fun searchKeyInNestedMap(map: Map<*, *>, key: Any): Any? { if (map.isNullOrEmpty()) { return null } @@ -605,10 +553,7 @@ open class AppboyKit : /** * This is called when the Kit is added to the mParticle SDK, typically on app-startup. */ - override fun setAllUserAttributes( - attributes: Map, - attributeLists: Map>, - ) { + override fun setAllUserAttributes(attributes: Map, attributeLists: Map>) { if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) { for ((key, value) in attributes) { setUserAttribute(key, value) @@ -652,19 +597,13 @@ open class AppboyKit : ) } - override fun setUserIdentity( - identityType: IdentityType, - identity: String, - ) {} + override fun setUserIdentity(identityType: IdentityType, identity: String) {} override fun removeUserIdentity(identityType: IdentityType) {} override fun logout(): List = emptyList() - fun logTransaction( - event: CommerceEvent?, - product: Product, - ) { + fun logTransaction(event: CommerceEvent?, product: Product) { val purchaseProperties = BrazeProperties() val currency = arrayOfNulls(1) val commerceTypeParser: StringTypeParser = @@ -674,28 +613,19 @@ open class AppboyKit : ) val onAttributeExtracted: OnAttributeExtracted = object : OnAttributeExtracted { - override fun onAttributeExtracted( - key: String, - value: String, - ) { + override fun onAttributeExtracted(key: String, value: String) { if (!checkCurrency(key, value)) { commerceTypeParser.parseValue(key, value) } } - override fun onAttributeExtracted( - key: String, - value: Double, - ) { + override fun onAttributeExtracted(key: String, value: Double) { if (!checkCurrency(key, value)) { purchaseProperties.addProperty(key, value) } } - override fun onAttributeExtracted( - key: String, - value: Int, - ) { + override fun onAttributeExtracted(key: String, value: Int) { purchaseProperties.addProperty(key, value) } @@ -707,16 +637,12 @@ open class AppboyKit : } } - private fun checkCurrency( - key: String, - value: Any?, - ): Boolean = - if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { - currency[0] = value?.toString() - true - } else { - false - } + private fun checkCurrency(key: String, value: Any?): Boolean = if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { + currency[0] = value?.toString() + true + } else { + false + } } CommerceEventUtils.extractActionAttributes(event, onAttributeExtracted) var currencyValue = currency[0] @@ -785,28 +711,19 @@ open class AppboyKit : ) val onAttributeExtracted: OnAttributeExtracted = object : OnAttributeExtracted { - override fun onAttributeExtracted( - key: String, - value: String, - ) { + override fun onAttributeExtracted(key: String, value: String) { if (!checkCurrency(key, value)) { commerceTypeParser.parseValue(key, value) } } - override fun onAttributeExtracted( - key: String, - value: Double, - ) { + override fun onAttributeExtracted(key: String, value: Double) { if (!checkCurrency(key, value)) { properties.addProperty(key, value) } } - override fun onAttributeExtracted( - key: String, - value: Int, - ) { + override fun onAttributeExtracted(key: String, value: Int) { properties.addProperty(key, value) } @@ -818,16 +735,12 @@ open class AppboyKit : } } - private fun checkCurrency( - key: String, - value: Any?, - ): Boolean = - if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { - currency[0] = value?.toString() - true - } else { - false - } + private fun checkCurrency(key: String, value: Any?): Boolean = if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { + currency[0] = value?.toString() + true + } else { + false + } } CommerceEventUtils.extractActionAttributes(event, onAttributeExtracted) var currencyValue = currency[0] @@ -894,17 +807,13 @@ open class AppboyKit : } } - override fun willHandlePushMessage(intent: Intent): Boolean = - if (!(settings[PUSH_ENABLED].toBoolean())) { - false - } else { - intent.isBrazePushMessage() - } + override fun willHandlePushMessage(intent: Intent): Boolean = if (!(settings[PUSH_ENABLED].toBoolean())) { + false + } else { + intent.isBrazePushMessage() + } - override fun onPushMessageReceived( - context: Context, - pushIntent: Intent, - ) { + override fun onPushMessageReceived(context: Context, pushIntent: Intent) { if (settings[PUSH_ENABLED].toBoolean()) { BrazeFirebaseMessagingService.handleBrazeRemoteMessage( context, @@ -913,18 +822,14 @@ open class AppboyKit : } } - override fun onPushRegistration( - instanceId: String, - senderId: String, - ): Boolean = - if (settings[PUSH_ENABLED].toBoolean()) { - updatedInstanceId = instanceId - Braze.getInstance(context).registeredPushToken = instanceId - queueDataFlush() - true - } else { - false - } + override fun onPushRegistration(instanceId: String, senderId: String): Boolean = if (settings[PUSH_ENABLED].toBoolean()) { + updatedInstanceId = instanceId + Braze.getInstance(context).registeredPushToken = instanceId + queueDataFlush() + true + } else { + false + } protected open fun setAuthority(authority: String?) { Braze.setEndpointProvider { appboyEndpoint -> @@ -935,31 +840,19 @@ open class AppboyKit : } } - override fun onIdentifyCompleted( - mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest?, - ) { + override fun onIdentifyCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { updateUser(mParticleUser) } - override fun onLoginCompleted( - mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest?, - ) { + override fun onLoginCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { updateUser(mParticleUser) } - override fun onLogoutCompleted( - mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest?, - ) { + override fun onLogoutCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { updateUser(mParticleUser) } - override fun onModifyCompleted( - mParticleUser: MParticleUser, - filteredIdentityApiRequest: FilteredIdentityApiRequest?, - ) { + override fun onModifyCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { updateUser(mParticleUser) } @@ -970,11 +863,7 @@ open class AppboyKit : email?.let { setEmail(it) } } - fun getIdentity( - isMpidIdentityType: Boolean, - identityType: IdentityType?, - mParticleUser: MParticleUser?, - ): String? { + fun getIdentity(isMpidIdentityType: Boolean, identityType: IdentityType?, mParticleUser: MParticleUser?): String? { var identity: String? = null if (isMpidIdentityType && mParticleUser != null) { identity = mParticleUser.id.toString() @@ -1032,11 +921,7 @@ open class AppboyKit : } } - fun addToProperties( - properties: BrazeProperties, - key: String, - value: String, - ) { + fun addToProperties(properties: BrazeProperties, key: String, value: String) { try { if ("true".equals(value, true) || "false".equals( @@ -1072,14 +957,13 @@ open class AppboyKit : return null } - fun getCalendarMinusYears(years: Int): Calendar? = - if (years >= 0) { - val calendar = Calendar.getInstance() - calendar[Calendar.YEAR] = calendar[Calendar.YEAR] - years - calendar - } else { - null - } + fun getCalendarMinusYears(years: Int): Calendar? = if (years >= 0) { + val calendar = Calendar.getInstance() + calendar[Calendar.YEAR] = calendar[Calendar.YEAR] - years + calendar + } else { + null + } fun getProductListParameters(productList: List): JSONArray { val productArray = JSONArray() @@ -1197,13 +1081,8 @@ open class AppboyKit : return impressionArray } - internal abstract class StringTypeParser( - var enableTypeDetection: Boolean, - ) { - fun parseValue( - key: String, - value: String, - ): Any { + internal abstract class StringTypeParser(var enableTypeDetection: Boolean) { + fun parseValue(key: String, value: String): Any { if (!enableTypeDetection) { toString(key, value) return value @@ -1242,108 +1121,59 @@ open class AppboyKit : } } - abstract fun toInt( - key: String, - value: Int, - ) + abstract fun toInt(key: String, value: Int) - abstract fun toLong( - key: String, - value: Long, - ) + abstract fun toLong(key: String, value: Long) - abstract fun toDouble( - key: String, - value: Double, - ) + abstract fun toDouble(key: String, value: Double) - abstract fun toBoolean( - key: String, - value: Boolean, - ) + abstract fun toBoolean(key: String, value: Boolean) - abstract fun toString( - key: String, - value: String, - ) + abstract fun toString(key: String, value: String) } - internal inner class BrazePropertiesSetter( - private var properties: BrazeProperties, - enableTypeDetection: Boolean, - ) : StringTypeParser(enableTypeDetection) { - override fun toInt( - key: String, - value: Int, - ) { + internal inner class BrazePropertiesSetter(private var properties: BrazeProperties, enableTypeDetection: Boolean) : + StringTypeParser(enableTypeDetection) { + override fun toInt(key: String, value: Int) { properties.addProperty(key, value) } - override fun toLong( - key: String, - value: Long, - ) { + override fun toLong(key: String, value: Long) { properties.addProperty(key, value) } - override fun toDouble( - key: String, - value: Double, - ) { + override fun toDouble(key: String, value: Double) { properties.addProperty(key, value) } - override fun toBoolean( - key: String, - value: Boolean, - ) { + override fun toBoolean(key: String, value: Boolean) { properties.addProperty(key, value) } - override fun toString( - key: String, - value: String, - ) { + override fun toString(key: String, value: String) { properties.addProperty(key, value) } } - internal inner class UserAttributeSetter( - private var brazeUser: BrazeUser, - enableTypeDetection: Boolean, - ) : StringTypeParser(enableTypeDetection) { - override fun toInt( - key: String, - value: Int, - ) { + internal inner class UserAttributeSetter(private var brazeUser: BrazeUser, enableTypeDetection: Boolean) : + StringTypeParser(enableTypeDetection) { + override fun toInt(key: String, value: Int) { brazeUser.setCustomUserAttribute(key, value) } - override fun toLong( - key: String, - value: Long, - ) { + override fun toLong(key: String, value: Long) { brazeUser.setCustomUserAttribute(key, value) } - override fun toDouble( - key: String, - value: Double, - ) { + override fun toDouble(key: String, value: Double) { brazeUser.setCustomUserAttribute(key, value) } - override fun toBoolean( - key: String, - value: Boolean, - ) { + override fun toBoolean(key: String, value: Boolean) { brazeUser.setCustomUserAttribute(key, value) } - override fun toString( - key: String, - value: String, - ) { + override fun toString(key: String, value: String) { brazeUser.setCustomUserAttribute(key, value) } } From f76d17e7f78e075f5d2ea1f39c84f12fe283fab4 Mon Sep 17 00:00:00 2001 From: Thomson Thomas Date: Fri, 16 Jan 2026 16:07:28 -0500 Subject: [PATCH 13/14] Fix ktlint errors --- .../kotlin/com/mparticle/kits/AppboyKit.kt | 401 ++++++++---- src/test/kotlin/com/braze/Braze.kt | 11 +- src/test/kotlin/com/braze/BrazeUser.kt | 49 +- .../braze/models/outgoing/BrazeProperties.kt | 30 +- .../com/mparticle/kits/AppboyKitTests.kt | 609 +++++++++++------- .../com/mparticle/kits/TypeDetectionTests.kt | 40 +- .../com/mparticle/kits/mocks/MockAppboyKit.kt | 16 +- .../mparticle/kits/mocks/MockApplication.kt | 10 +- .../com/mparticle/kits/mocks/MockContext.kt | 188 +++++- .../kits/mocks/MockContextApplication.kt | 6 +- .../mparticle/kits/mocks/MockCoreCallbacks.kt | 43 +- .../kits/mocks/MockKitConfiguration.kt | 13 +- .../kits/mocks/MockKitManagerImpl.kt | 57 +- .../com/mparticle/kits/mocks/MockResources.kt | 12 +- .../kits/mocks/MockSharedPreferences.kt | 71 +- .../com/mparticle/kits/mocks/MockUser.kt | 20 +- 16 files changed, 1096 insertions(+), 480 deletions(-) diff --git a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt index 1846c3f..c44edcf 100644 --- a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt @@ -71,7 +71,10 @@ open class AppboyKit : override fun getName() = NAME - public override fun onKitCreate(settings: Map, context: Context): List? { + public override fun onKitCreate( + settings: Map, + context: Context, + ): List? { val key = settings[APPBOY_KEY] require(!KitUtils.isEmpty(key)) { "Braze key is empty." } @@ -152,9 +155,16 @@ open class AppboyKit : override fun leaveBreadcrumb(breadcrumb: String): List = emptyList() - override fun logError(message: String, errorAttributes: Map): List = emptyList() + override fun logError( + message: String, + errorAttributes: Map, + ): List = emptyList() - override fun logException(exception: Exception, exceptionAttributes: Map, message: String): List = emptyList() + override fun logException( + exception: Exception, + exceptionAttributes: Map, + message: String, + ): List = emptyList() override fun logEvent(event: MPEvent): List { val newAttributes: MutableMap = HashMap() @@ -169,7 +179,8 @@ open class AppboyKit : } } Braze.getInstance(context).logCustomEvent(event.eventName, properties) - Braze.getInstance(context) + Braze + .getInstance(context) .getCurrentUser( object : IValueCallback { override fun onSuccess(value: BrazeUser) { @@ -202,31 +213,35 @@ open class AppboyKit : return listOf(ReportingMessage.fromEvent(this, event).setAttributes(newAttributes)) } - override fun logScreen(screenName: String, screenAttributes: Map?): List = if (forwardScreenViews) { - if (screenAttributes == null) { - Braze.getInstance(context).logCustomEvent(screenName) - } else { - val properties = BrazeProperties() - val propertyParser = BrazePropertiesSetter(properties, enableTypeDetection) - for ((key, value) in screenAttributes) { - propertyParser.parseValue(key, value) + override fun logScreen( + screenName: String, + screenAttributes: Map?, + ): List = + if (forwardScreenViews) { + if (screenAttributes == null) { + Braze.getInstance(context).logCustomEvent(screenName) + } else { + val properties = BrazeProperties() + val propertyParser = BrazePropertiesSetter(properties, enableTypeDetection) + for ((key, value) in screenAttributes) { + propertyParser.parseValue(key, value) + } + Braze.getInstance(context).logCustomEvent(screenName, properties) } - Braze.getInstance(context).logCustomEvent(screenName, properties) + queueDataFlush() + val messages: MutableList = LinkedList() + messages.add( + ReportingMessage( + this, + ReportingMessage.MessageType.SCREEN_VIEW, + System.currentTimeMillis(), + screenAttributes, + ), + ) + messages + } else { + emptyList() } - queueDataFlush() - val messages: MutableList = LinkedList() - messages.add( - ReportingMessage( - this, - ReportingMessage.MessageType.SCREEN_VIEW, - System.currentTimeMillis(), - screenAttributes, - ), - ) - messages - } else { - emptyList() - } override fun logLtvIncrease( valueIncreased: BigDecimal, @@ -284,9 +299,13 @@ open class AppboyKit : return messages } - override fun setUserAttribute(keyIn: String, attributeValue: String) { + override fun setUserAttribute( + keyIn: String, + attributeValue: String, + ) { var key = keyIn - Braze.getInstance(context) + Braze + .getInstance(context) .getCurrentUser( object : IValueCallback { override fun onSuccess(value: BrazeUser) { @@ -372,7 +391,10 @@ open class AppboyKit : } // Expected Date Format @"yyyy'-'MM'-'dd" - private fun useDobString(value: String, user: BrazeUser) { + private fun useDobString( + value: String, + user: BrazeUser, + ) { val dateFormat = SimpleDateFormat("yyyy-MM-dd") try { val calendar = Calendar.getInstance() @@ -387,8 +409,12 @@ open class AppboyKit : } } - override fun setUserAttributeList(key: String, list: List) { - Braze.getInstance(context) + override fun setUserAttributeList( + key: String, + list: List, + ) { + Braze + .getInstance(context) .getCurrentUser( object : IValueCallback { override fun onSuccess(value: BrazeUser) { @@ -404,19 +430,38 @@ open class AppboyKit : ) } - override fun onIncrementUserAttribute(key: String?, incrementedBy: Number?, value: String?, user: FilteredMParticleUser?) { + override fun onIncrementUserAttribute( + key: String?, + incrementedBy: Number?, + value: String?, + user: FilteredMParticleUser?, + ) { } - override fun onRemoveUserAttribute(key: String?, user: FilteredMParticleUser?) { + override fun onRemoveUserAttribute( + key: String?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserAttribute(key: String?, value: Any?, user: FilteredMParticleUser?) { + override fun onSetUserAttribute( + key: String?, + value: Any?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserTag(key: String?, user: FilteredMParticleUser?) { + override fun onSetUserTag( + key: String?, + user: FilteredMParticleUser?, + ) { } - override fun onSetUserAttributeList(attributeKey: String?, attributeValueList: MutableList?, user: FilteredMParticleUser?) { + override fun onSetUserAttributeList( + attributeKey: String?, + attributeValueList: MutableList?, + user: FilteredMParticleUser?, + ) { } override fun onSetAllUserAttributes( @@ -428,7 +473,11 @@ open class AppboyKit : override fun supportsAttributeLists(): Boolean = true - override fun onConsentStateUpdated(oldState: ConsentState, newState: ConsentState, user: FilteredMParticleUser) { + override fun onConsentStateUpdated( + oldState: ConsentState, + newState: ConsentState, + user: FilteredMParticleUser, + ) { setConsent(newState) } @@ -460,8 +509,12 @@ open class AppboyKit : } } - private fun setConsentValueToBraze(key: String, value: Boolean) { - Braze.getInstance(context) + private fun setConsentValueToBraze( + key: String, + value: Boolean, + ) { + Braze + .getInstance(context) .getCurrentUser( object : IValueCallback { override fun onSuccess(brazeUser: BrazeUser) { @@ -520,7 +573,10 @@ open class AppboyKit : return topLevelMap } - private fun searchKeyInNestedMap(map: Map<*, *>, key: Any): Any? { + private fun searchKeyInNestedMap( + map: Map<*, *>, + key: Any, + ): Any? { if (map.isNullOrEmpty()) { return null } @@ -553,7 +609,10 @@ open class AppboyKit : /** * This is called when the Kit is added to the mParticle SDK, typically on app-startup. */ - override fun setAllUserAttributes(attributes: Map, attributeLists: Map>) { + override fun setAllUserAttributes( + attributes: Map, + attributeLists: Map>, + ) { if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) { for ((key, value) in attributes) { setUserAttribute(key, value) @@ -567,7 +626,8 @@ open class AppboyKit : override fun removeUserAttribute(keyIn: String) { var key = keyIn - Braze.getInstance(context) + Braze + .getInstance(context) .getCurrentUser( object : IValueCallback { override fun onSuccess(value: BrazeUser) { @@ -597,13 +657,19 @@ open class AppboyKit : ) } - override fun setUserIdentity(identityType: IdentityType, identity: String) {} + override fun setUserIdentity( + identityType: IdentityType, + identity: String, + ) {} override fun removeUserIdentity(identityType: IdentityType) {} override fun logout(): List = emptyList() - fun logTransaction(event: CommerceEvent?, product: Product) { + fun logTransaction( + event: CommerceEvent?, + product: Product, + ) { val purchaseProperties = BrazeProperties() val currency = arrayOfNulls(1) val commerceTypeParser: StringTypeParser = @@ -613,19 +679,28 @@ open class AppboyKit : ) val onAttributeExtracted: OnAttributeExtracted = object : OnAttributeExtracted { - override fun onAttributeExtracted(key: String, value: String) { + override fun onAttributeExtracted( + key: String, + value: String, + ) { if (!checkCurrency(key, value)) { commerceTypeParser.parseValue(key, value) } } - override fun onAttributeExtracted(key: String, value: Double) { + override fun onAttributeExtracted( + key: String, + value: Double, + ) { if (!checkCurrency(key, value)) { purchaseProperties.addProperty(key, value) } } - override fun onAttributeExtracted(key: String, value: Int) { + override fun onAttributeExtracted( + key: String, + value: Int, + ) { purchaseProperties.addProperty(key, value) } @@ -637,12 +712,18 @@ open class AppboyKit : } } - private fun checkCurrency(key: String, value: Any?): Boolean = if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { - currency[0] = value?.toString() - true - } else { - false - } + private fun checkCurrency( + key: String, + value: Any?, + ): Boolean = + if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == + key + ) { + currency[0] = value?.toString() + true + } else { + false + } } CommerceEventUtils.extractActionAttributes(event, onAttributeExtracted) var currencyValue = currency[0] @@ -711,19 +792,28 @@ open class AppboyKit : ) val onAttributeExtracted: OnAttributeExtracted = object : OnAttributeExtracted { - override fun onAttributeExtracted(key: String, value: String) { + override fun onAttributeExtracted( + key: String, + value: String, + ) { if (!checkCurrency(key, value)) { commerceTypeParser.parseValue(key, value) } } - override fun onAttributeExtracted(key: String, value: Double) { + override fun onAttributeExtracted( + key: String, + value: Double, + ) { if (!checkCurrency(key, value)) { properties.addProperty(key, value) } } - override fun onAttributeExtracted(key: String, value: Int) { + override fun onAttributeExtracted( + key: String, + value: Int, + ) { properties.addProperty(key, value) } @@ -735,12 +825,18 @@ open class AppboyKit : } } - private fun checkCurrency(key: String, value: Any?): Boolean = if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == key) { - currency[0] = value?.toString() - true - } else { - false - } + private fun checkCurrency( + key: String, + value: Any?, + ): Boolean = + if (CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE == + key + ) { + currency[0] = value?.toString() + true + } else { + false + } } CommerceEventUtils.extractActionAttributes(event, onAttributeExtracted) var currencyValue = currency[0] @@ -807,13 +903,17 @@ open class AppboyKit : } } - override fun willHandlePushMessage(intent: Intent): Boolean = if (!(settings[PUSH_ENABLED].toBoolean())) { - false - } else { - intent.isBrazePushMessage() - } + override fun willHandlePushMessage(intent: Intent): Boolean = + if (!(settings[PUSH_ENABLED].toBoolean())) { + false + } else { + intent.isBrazePushMessage() + } - override fun onPushMessageReceived(context: Context, pushIntent: Intent) { + override fun onPushMessageReceived( + context: Context, + pushIntent: Intent, + ) { if (settings[PUSH_ENABLED].toBoolean()) { BrazeFirebaseMessagingService.handleBrazeRemoteMessage( context, @@ -822,14 +922,18 @@ open class AppboyKit : } } - override fun onPushRegistration(instanceId: String, senderId: String): Boolean = if (settings[PUSH_ENABLED].toBoolean()) { - updatedInstanceId = instanceId - Braze.getInstance(context).registeredPushToken = instanceId - queueDataFlush() - true - } else { - false - } + override fun onPushRegistration( + instanceId: String, + senderId: String, + ): Boolean = + if (settings[PUSH_ENABLED].toBoolean()) { + updatedInstanceId = instanceId + Braze.getInstance(context).registeredPushToken = instanceId + queueDataFlush() + true + } else { + false + } protected open fun setAuthority(authority: String?) { Braze.setEndpointProvider { appboyEndpoint -> @@ -840,19 +944,31 @@ open class AppboyKit : } } - override fun onIdentifyCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { + override fun onIdentifyCompleted( + mParticleUser: MParticleUser, + filteredIdentityApiRequest: FilteredIdentityApiRequest?, + ) { updateUser(mParticleUser) } - override fun onLoginCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { + override fun onLoginCompleted( + mParticleUser: MParticleUser, + filteredIdentityApiRequest: FilteredIdentityApiRequest?, + ) { updateUser(mParticleUser) } - override fun onLogoutCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { + override fun onLogoutCompleted( + mParticleUser: MParticleUser, + filteredIdentityApiRequest: FilteredIdentityApiRequest?, + ) { updateUser(mParticleUser) } - override fun onModifyCompleted(mParticleUser: MParticleUser, filteredIdentityApiRequest: FilteredIdentityApiRequest?) { + override fun onModifyCompleted( + mParticleUser: MParticleUser, + filteredIdentityApiRequest: FilteredIdentityApiRequest?, + ) { updateUser(mParticleUser) } @@ -863,7 +979,11 @@ open class AppboyKit : email?.let { setEmail(it) } } - fun getIdentity(isMpidIdentityType: Boolean, identityType: IdentityType?, mParticleUser: MParticleUser?): String? { + fun getIdentity( + isMpidIdentityType: Boolean, + identityType: IdentityType?, + mParticleUser: MParticleUser?, + ): String? { var identity: String? = null if (isMpidIdentityType && mParticleUser != null) { identity = mParticleUser.id.toString() @@ -921,7 +1041,11 @@ open class AppboyKit : } } - fun addToProperties(properties: BrazeProperties, key: String, value: String) { + fun addToProperties( + properties: BrazeProperties, + key: String, + value: String, + ) { try { if ("true".equals(value, true) || "false".equals( @@ -957,13 +1081,14 @@ open class AppboyKit : return null } - fun getCalendarMinusYears(years: Int): Calendar? = if (years >= 0) { - val calendar = Calendar.getInstance() - calendar[Calendar.YEAR] = calendar[Calendar.YEAR] - years - calendar - } else { - null - } + fun getCalendarMinusYears(years: Int): Calendar? = + if (years >= 0) { + val calendar = Calendar.getInstance() + calendar[Calendar.YEAR] = calendar[Calendar.YEAR] - years + calendar + } else { + null + } fun getProductListParameters(productList: List): JSONArray { val productArray = JSONArray() @@ -1081,8 +1206,13 @@ open class AppboyKit : return impressionArray } - internal abstract class StringTypeParser(var enableTypeDetection: Boolean) { - fun parseValue(key: String, value: String): Any { + internal abstract class StringTypeParser( + var enableTypeDetection: Boolean, + ) { + fun parseValue( + key: String, + value: String, + ): Any { if (!enableTypeDetection) { toString(key, value) return value @@ -1121,59 +1251,108 @@ open class AppboyKit : } } - abstract fun toInt(key: String, value: Int) + abstract fun toInt( + key: String, + value: Int, + ) - abstract fun toLong(key: String, value: Long) + abstract fun toLong( + key: String, + value: Long, + ) - abstract fun toDouble(key: String, value: Double) + abstract fun toDouble( + key: String, + value: Double, + ) - abstract fun toBoolean(key: String, value: Boolean) + abstract fun toBoolean( + key: String, + value: Boolean, + ) - abstract fun toString(key: String, value: String) + abstract fun toString( + key: String, + value: String, + ) } - internal inner class BrazePropertiesSetter(private var properties: BrazeProperties, enableTypeDetection: Boolean) : - StringTypeParser(enableTypeDetection) { - override fun toInt(key: String, value: Int) { + internal inner class BrazePropertiesSetter( + private var properties: BrazeProperties, + enableTypeDetection: Boolean, + ) : StringTypeParser(enableTypeDetection) { + override fun toInt( + key: String, + value: Int, + ) { properties.addProperty(key, value) } - override fun toLong(key: String, value: Long) { + override fun toLong( + key: String, + value: Long, + ) { properties.addProperty(key, value) } - override fun toDouble(key: String, value: Double) { + override fun toDouble( + key: String, + value: Double, + ) { properties.addProperty(key, value) } - override fun toBoolean(key: String, value: Boolean) { + override fun toBoolean( + key: String, + value: Boolean, + ) { properties.addProperty(key, value) } - override fun toString(key: String, value: String) { + override fun toString( + key: String, + value: String, + ) { properties.addProperty(key, value) } } - internal inner class UserAttributeSetter(private var brazeUser: BrazeUser, enableTypeDetection: Boolean) : - StringTypeParser(enableTypeDetection) { - override fun toInt(key: String, value: Int) { + internal inner class UserAttributeSetter( + private var brazeUser: BrazeUser, + enableTypeDetection: Boolean, + ) : StringTypeParser(enableTypeDetection) { + override fun toInt( + key: String, + value: Int, + ) { brazeUser.setCustomUserAttribute(key, value) } - override fun toLong(key: String, value: Long) { + override fun toLong( + key: String, + value: Long, + ) { brazeUser.setCustomUserAttribute(key, value) } - override fun toDouble(key: String, value: Double) { + override fun toDouble( + key: String, + value: Double, + ) { brazeUser.setCustomUserAttribute(key, value) } - override fun toBoolean(key: String, value: Boolean) { + override fun toBoolean( + key: String, + value: Boolean, + ) { brazeUser.setCustomUserAttribute(key, value) } - override fun toString(key: String, value: String) { + override fun toString( + key: String, + value: String, + ) { brazeUser.setCustomUserAttribute(key, value) } } diff --git a/src/test/kotlin/com/braze/Braze.kt b/src/test/kotlin/com/braze/Braze.kt index 4b2268b..f2ebeff 100644 --- a/src/test/kotlin/com/braze/Braze.kt +++ b/src/test/kotlin/com/braze/Braze.kt @@ -8,7 +8,6 @@ import com.mparticle.kits.BrazePurchase import java.math.BigDecimal class Braze { - fun getCurrentUser(): BrazeUser = Companion.currentUser fun getCustomAttributeArray(): java.util.HashMap> = Companion.currentUser.getCustomAttribute() @@ -17,7 +16,10 @@ class Braze { callback.onSuccess(currentUser) } - fun logCustomEvent(key: String, brazeProperties: BrazeProperties) { + fun logCustomEvent( + key: String, + brazeProperties: BrazeProperties, + ) { events[key] = brazeProperties } @@ -50,7 +52,10 @@ class Braze { val currentUser = BrazeUser() @JvmStatic - fun configure(context: Context?, config: BrazeConfig?) = true + fun configure( + context: Context?, + config: BrazeConfig?, + ) = true @JvmStatic fun getInstance(context: Context?): Braze = Braze() diff --git a/src/test/kotlin/com/braze/BrazeUser.kt b/src/test/kotlin/com/braze/BrazeUser.kt index 881a1d0..1398391 100644 --- a/src/test/kotlin/com/braze/BrazeUser.kt +++ b/src/test/kotlin/com/braze/BrazeUser.kt @@ -7,7 +7,11 @@ class BrazeUser { var dobMonth: Month? = null var dobDay = -1 - fun setDateOfBirth(year: Int, month: Month?, day: Int): Boolean { + fun setDateOfBirth( + year: Int, + month: Month?, + day: Int, + ): Boolean { dobYear = year dobMonth = month dobDay = day @@ -17,7 +21,10 @@ class BrazeUser { val customAttributeArray = HashMap>() val customUserAttributes = HashMap() - fun addToCustomAttributeArray(key: String, value: String): Boolean { + fun addToCustomAttributeArray( + key: String, + value: String, + ): Boolean { var customArray = customAttributeArray[key] if (customArray == null) { customArray = ArrayList() @@ -27,31 +34,47 @@ class BrazeUser { return true } - fun removeFromCustomAttributeArray(key: String, value: String): Boolean = try { - if (customAttributeArray.containsKey(key)) { - customAttributeArray.remove(key) + fun removeFromCustomAttributeArray( + key: String, + value: String, + ): Boolean = + try { + if (customAttributeArray.containsKey(key)) { + customAttributeArray.remove(key) + } + true + } catch (npe: NullPointerException) { + false } - true - } catch (npe: NullPointerException) { - false - } - fun setCustomUserAttribute(key: String, value: String): Boolean { + fun setCustomUserAttribute( + key: String, + value: String, + ): Boolean { customUserAttributes[key] = value return true } - fun setCustomUserAttribute(key: String, value: Boolean): Boolean { + fun setCustomUserAttribute( + key: String, + value: Boolean, + ): Boolean { customUserAttributes[key] = value return true } - fun setCustomUserAttribute(key: String, value: Int): Boolean { + fun setCustomUserAttribute( + key: String, + value: Int, + ): Boolean { customUserAttributes[key] = value return true } - fun setCustomUserAttribute(key: String, value: Double): Boolean { + fun setCustomUserAttribute( + key: String, + value: Double, + ): Boolean { customUserAttributes[key] = value return true } diff --git a/src/test/kotlin/com/braze/models/outgoing/BrazeProperties.kt b/src/test/kotlin/com/braze/models/outgoing/BrazeProperties.kt index 3881c71..e36de65 100644 --- a/src/test/kotlin/com/braze/models/outgoing/BrazeProperties.kt +++ b/src/test/kotlin/com/braze/models/outgoing/BrazeProperties.kt @@ -5,32 +5,50 @@ import java.util.HashMap class BrazeProperties { val properties = HashMap() - fun addProperty(key: String, value: Long): BrazeProperties { + fun addProperty( + key: String, + value: Long, + ): BrazeProperties { properties[key] = value return this } - fun addProperty(key: String, value: Int): BrazeProperties { + fun addProperty( + key: String, + value: Int, + ): BrazeProperties { properties[key] = value return this } - fun addProperty(key: String, value: String): BrazeProperties { + fun addProperty( + key: String, + value: String, + ): BrazeProperties { properties[key] = value return this } - fun addProperty(key: String, value: Double): BrazeProperties { + fun addProperty( + key: String, + value: Double, + ): BrazeProperties { properties[key] = value return this } - fun addProperty(key: String, value: Boolean): BrazeProperties { + fun addProperty( + key: String, + value: Boolean, + ): BrazeProperties { properties[key] = value return this } - fun addProperty(key: String, value: Any): BrazeProperties { + fun addProperty( + key: String, + value: Any, + ): BrazeProperties { properties[key] = value return this } diff --git a/src/test/kotlin/com/mparticle/kits/AppboyKitTests.kt b/src/test/kotlin/com/mparticle/kits/AppboyKitTests.kt index af0bf86..d0f6800 100644 --- a/src/test/kotlin/com/mparticle/kits/AppboyKitTests.kt +++ b/src/test/kotlin/com/mparticle/kits/AppboyKitTests.kt @@ -171,18 +171,19 @@ class AppboyKitTests { val values = arrayOfNulls(2) val mockEmail = "mockEmail$i" val mockCustomerId = "12345$i" - val kit: AppboyKit = object : AppboyKit() { - override fun setId(customerId: String) { - values[0] = customerId - } + val kit: AppboyKit = + object : AppboyKit() { + override fun setId(customerId: String) { + values[0] = customerId + } - override fun setEmail(email: String) { - if (values[0] == null) { - Assert.fail("customerId should have been set first") + override fun setEmail(email: String) { + if (values[0] == null) { + Assert.fail("customerId should have been set first") + } + values[1] = email } - values[1] = email } - } kit.identityType = IdentityType.CustomerId val map = HashMap() map[IdentityType.Email] = mockEmail @@ -218,18 +219,22 @@ class AppboyKitTests { val kit: AppboyKit = MockAppboyKit() val currentYear = Calendar.getInstance()[Calendar.YEAR] var calendar = kit.getCalendarMinusYears("5") - calendar?.get(Calendar.YEAR) + calendar + ?.get(Calendar.YEAR) ?.let { Assert.assertEquals((currentYear - 5).toLong(), it.toLong()) } calendar = kit.getCalendarMinusYears(22) - calendar?.get(Calendar.YEAR) + calendar + ?.get(Calendar.YEAR) ?.let { Assert.assertEquals((currentYear - 22).toLong(), it.toLong()) } // round down doubles calendar = kit.getCalendarMinusYears("5.001") - calendar?.get(Calendar.YEAR) + calendar + ?.get(Calendar.YEAR) ?.let { Assert.assertEquals((currentYear - 5).toLong(), it.toLong()) } calendar = kit.getCalendarMinusYears("5.9") - calendar?.get(Calendar.YEAR) + calendar + ?.get(Calendar.YEAR) ?.let { Assert.assertEquals((currentYear - 5).toLong(), it.toLong()) } // invalid ages (negative, non numeric), don't get set @@ -242,10 +247,13 @@ class AppboyKitTests { val settings = HashMap() settings[AppboyKit.APPBOY_KEY] = "key" settings[AppboyKit.HOST] = hostName - settings["subscriptionGroupMapping"] = "" + - "[{\"jsmap\":null,\"map\":\"test1\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"00000000-0000-0000-0000-000000000000\"}," + - "{\"jsmap\":null,\"map\":\"test2\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"00000000-0000-0000-0000-000000000001\"}," + - "{\"jsmap\":null,\"map\":\"test3\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"00000000-0000-0000-0000-000000000002\"}]" + settings["subscriptionGroupMapping"] = + "[{\"jsmap\":null,\"map\":\"test1\",\"maptype\":\"UserAttributeClass.Name\"," + + "\"value\":\"00000000-0000-0000-0000-000000000000\"}," + + "{\"jsmap\":null,\"map\":\"test2\",\"maptype\":\"UserAttributeClass.Name\"," + + "\"value\":\"00000000-0000-0000-0000-000000000001\"}," + + "{\"jsmap\":null,\"map\":\"test3\",\"maptype\":\"UserAttributeClass.Name\"," + + "\"value\":\"00000000-0000-0000-0000-000000000002\"}]" val kit = MockAppboyKit() val currentUser = braze.currentUser @@ -314,11 +322,18 @@ class AppboyKitTests { @Test fun setIdentityType() { - val possibleValues = arrayOf( - "Other", "CustomerId", "Facebook", - "Twitter", "Google", "Microsoft", - "Yahoo", "Email", "Alias", - ) + val possibleValues = + arrayOf( + "Other", + "CustomerId", + "Facebook", + "Twitter", + "Google", + "Microsoft", + "Yahoo", + "Email", + "Alias", + ) val mpid = "MPID" for (`val` in possibleValues) { val kit = kit @@ -364,15 +379,17 @@ class AppboyKitTests { // // override fun getEventAttributesAddToUser(): Map { // val map = HashMap() -// map[KitUtils.hashForFiltering(MParticle.EventType.Navigation.toString() + "Navigation Event" + "key1")] = -// "output" +// map[KitUtils.hashForFiltering( +// MParticle.EventType.Navigation.toString() + "Navigation Event" + "key1" +// )] = "output" // return map // } // // override fun getEventAttributesRemoveFromUser(): Map { // val map = HashMap() -// map[KitUtils.hashForFiltering(MParticle.EventType.Location.toString() + "location event" + "key1")] = -// "output" +// map[KitUtils.hashForFiltering( +// MParticle.EventType.Location.toString() + "location event" + "key1" +// )] = "output" // return map // } // @@ -404,34 +421,46 @@ class AppboyKitTests { @Test fun testPurchaseCurrency() { val kit = MockAppboyKit() - val product = Product.Builder("product name", "sku1", 4.5) - .build() - val commerceEvent = CommerceEvent.Builder(Product.CHECKOUT, product) - .currency("Moon Dollars") - .build() + val product = + Product + .Builder("product name", "sku1", 4.5) + .build() + val commerceEvent = + CommerceEvent + .Builder(Product.CHECKOUT, product) + .currency("Moon Dollars") + .build() kit.logTransaction(commerceEvent, product) val braze = Braze val purchases = braze.purchases Assert.assertEquals(1, purchases.size.toLong()) val purchase = purchases[0] Assert.assertEquals("Moon Dollars", purchase.currency) - Assert.assertNull(purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE]) + Assert.assertNull( + purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE], + ) } @Test fun testPurchaseDefaultCurrency() { val kit = MockAppboyKit() - val product = Product.Builder("product name", "sku1", 4.5) - .build() - val commerceEvent = CommerceEvent.Builder(Product.CHECKOUT, product) - .build() + val product = + Product + .Builder("product name", "sku1", 4.5) + .build() + val commerceEvent = + CommerceEvent + .Builder(Product.CHECKOUT, product) + .build() kit.logTransaction(commerceEvent, product) val braze = Braze val purchases = braze.purchases Assert.assertEquals(1, purchases.size.toLong()) val purchase = purchases[0] Assert.assertEquals(CommerceEventUtils.Constants.DEFAULT_CURRENCY_CODE, purchase.currency) - Assert.assertNull(purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE]) + Assert.assertNull( + purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE], + ) } @Test @@ -443,27 +472,32 @@ class AppboyKitTests { val productCustomAttributes = HashMap() productCustomAttributes["productKey1"] = "value1" productCustomAttributes["productKey2"] = "value2" - val transactionAttributes = TransactionAttributes("the id") - .setTax(100.0) - .setShipping(12.0) - .setRevenue(99.0) - .setCouponCode("coupon code") - .setAffiliation("the affiliation") - val product = Product.Builder("product name", "sku1", 4.5) - .quantity(5.0) - .brand("testBrand") - .variant("testVariant") - .position(1) - .category("testCategory") - .customAttributes(productCustomAttributes) - .build() - val commerceEvent = CommerceEvent.Builder(Product.PURCHASE, product) - .currency("Moon Dollars") - .productListName("product list name") - .productListSource("the source") - .customAttributes(customAttributes) - .transactionAttributes(transactionAttributes) - .build() + val transactionAttributes = + TransactionAttributes("the id") + .setTax(100.0) + .setShipping(12.0) + .setRevenue(99.0) + .setCouponCode("coupon code") + .setAffiliation("the affiliation") + val product = + Product + .Builder("product name", "sku1", 4.5) + .quantity(5.0) + .brand("testBrand") + .variant("testVariant") + .position(1) + .category("testCategory") + .customAttributes(productCustomAttributes) + .build() + val commerceEvent = + CommerceEvent + .Builder(Product.PURCHASE, product) + .currency("Moon Dollars") + .productListName("product list name") + .productListSource("the source") + .customAttributes(customAttributes) + .transactionAttributes(transactionAttributes) + .build() kit.logTransaction(commerceEvent, product) val braze = Braze val purchases = braze.purchases @@ -538,22 +572,27 @@ class AppboyKitTests { val customAttributes = HashMap() customAttributes["key1"] = "value1" customAttributes["key #2"] = "value #3" - val transactionAttributes = TransactionAttributes("the id") - .setTax(100.0) - .setShipping(12.0) - .setRevenue(99.0) - .setCouponCode("coupon code") - .setAffiliation("the affiliation") - val product = Product.Builder("product name", "sku1", 4.5) - .quantity(5.0) - .build() - val commerceEvent = CommerceEvent.Builder(Product.PURCHASE, product) - .currency("Moon Dollars") - .productListName("product list name") - .productListSource("the source") - .customAttributes(customAttributes) - .transactionAttributes(transactionAttributes) - .build() + val transactionAttributes = + TransactionAttributes("the id") + .setTax(100.0) + .setShipping(12.0) + .setRevenue(99.0) + .setCouponCode("coupon code") + .setAffiliation("the affiliation") + val product = + Product + .Builder("product name", "sku1", 4.5) + .quantity(5.0) + .build() + val commerceEvent = + CommerceEvent + .Builder(Product.PURCHASE, product) + .currency("Moon Dollars") + .productListName("product list name") + .productListSource("the source") + .customAttributes(customAttributes) + .transactionAttributes(transactionAttributes) + .build() kit.logOrderLevelTransaction(commerceEvent) val braze = Braze val purchases = braze.purchases @@ -673,15 +712,18 @@ class AppboyKitTests { val customAttributes = HashMap() customAttributes["key1"] = "value1" customAttributes["key #2"] = "value #3" - val promotion = Promotion().apply { - id = "my_promo_1" - creative = "sale_banner_1" - name = "App-wide 50% off sale" - position = "dashboard_bottom" - } - val commerceEvent = CommerceEvent.Builder(Promotion.VIEW, promotion) - .customAttributes(customAttributes) - .build() + val promotion = + Promotion().apply { + id = "my_promo_1" + creative = "sale_banner_1" + name = "App-wide 50% off sale" + position = "dashboard_bottom" + } + val commerceEvent = + CommerceEvent + .Builder(Promotion.VIEW, promotion) + .customAttributes(customAttributes) + .build() kit.logOrderLevelTransaction(commerceEvent) val braze = Braze val events = braze.events @@ -756,12 +798,22 @@ class AppboyKitTests { // Assert.assertNotNull(event.properties) // val properties = event.properties // -// Assert.assertEquals(properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_TOTAL_AMOUNT), "22.5") -// Assert.assertEquals(properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_NAME), "product name") -// Assert.assertEquals(properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_QUANTITY), "5.0") +// Assert.assertEquals( +// properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_TOTAL_AMOUNT), "22.5" +// ) +// Assert.assertEquals( +// properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_NAME), "product name" +// ) +// Assert.assertEquals( +// properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_QUANTITY), "5.0" +// ) // Assert.assertEquals(properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_ID), "sku1") -// Assert.assertEquals(properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_PRICE), "4.5") -// Assert.assertEquals(properties.remove("Product Impression List"), "Suggested Products List") +// Assert.assertEquals( +// properties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_PRICE), "4.5" +// ) +// Assert.assertEquals( +// properties.remove("Product Impression List"), "Suggested Products List" +// ) // Assert.assertEquals(properties.remove("key1"), "value1") // Assert.assertEquals(properties.remove("key #2"), "value #3") // @@ -777,16 +829,21 @@ class AppboyKitTests { val customAttributes = HashMap() customAttributes["key1"] = "value1" customAttributes["key #2"] = "value #3" - val product = Product.Builder("product name", "sku1", 4.5) - .quantity(5.0) - .customAttributes(customAttributes) - .build() - val impression = Impression("Suggested Products List", product).let { - CommerceEvent.Builder(it).build() - } - val commerceEvent = CommerceEvent.Builder(impression) - .customAttributes(customAttributes) - .build() + val product = + Product + .Builder("product name", "sku1", 4.5) + .quantity(5.0) + .customAttributes(customAttributes) + .build() + val impression = + Impression("Suggested Products List", product).let { + CommerceEvent.Builder(it).build() + } + val commerceEvent = + CommerceEvent + .Builder(impression) + .customAttributes(customAttributes) + .build() kit.logOrderLevelTransaction(commerceEvent) val braze = Braze val events = braze.events @@ -814,7 +871,9 @@ class AppboyKitTests { if (productBrazeProperties is BrazeProperties) { val productProperties = productBrazeProperties.properties Assert.assertEquals( - productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_TOTAL_AMOUNT), + productProperties.remove( + CommerceEventUtils.Constants.ATT_PRODUCT_TOTAL_AMOUNT, + ), 22.5, ) Assert.assertEquals( @@ -822,7 +881,9 @@ class AppboyKitTests { "product name", ) Assert.assertEquals( - productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_QUANTITY), + productProperties.remove( + CommerceEventUtils.Constants.ATT_PRODUCT_QUANTITY, + ), 5.0, ) Assert.assertEquals( @@ -830,7 +891,9 @@ class AppboyKitTests { "sku1", ) Assert.assertEquals( - productProperties.remove(CommerceEventUtils.Constants.ATT_PRODUCT_PRICE), + productProperties.remove( + CommerceEventUtils.Constants.ATT_PRODUCT_PRICE, + ), 4.5, ) val brazeProductCustomAttributesDictionary = @@ -1020,9 +1083,11 @@ class AppboyKitTests { kit.configuration = kitConfiguration val customAttributes: MutableMap = HashMap() customAttributes["destination"] = "Shop" - val event = MPEvent.Builder("AndroidTEST", MParticle.EventType.Navigation) - .customAttributes(customAttributes) - .build() + val event = + MPEvent + .Builder("AndroidTEST", MParticle.EventType.Navigation) + .customAttributes(customAttributes) + .build() val instance = MParticle.getInstance() instance?.logEvent(event) kit.logEvent(event) @@ -1058,9 +1123,11 @@ class AppboyKitTests { kit.configuration = kitConfiguration val customAttributes: MutableMap = HashMap() customAttributes["destination"] = "Shop" - val event = MPEvent.Builder("AndroidTEST", MParticle.EventType.Navigation) - .customAttributes(customAttributes) - .build() + val event = + MPEvent + .Builder("AndroidTEST", MParticle.EventType.Navigation) + .customAttributes(customAttributes) + .build() val instance = MParticle.getInstance() instance?.logEvent(event) kit.logEvent(event) @@ -1089,9 +1156,11 @@ class AppboyKitTests { kit.configuration = kitConfiguration val customAttributes: MutableMap = HashMap() customAttributes["destination"] = "Shop" - val event = MPEvent.Builder("AndroidTEST", MParticle.EventType.Navigation) - .customAttributes(customAttributes) - .build() + val event = + MPEvent + .Builder("AndroidTEST", MParticle.EventType.Navigation) + .customAttributes(customAttributes) + .build() val instance = MParticle.getInstance() instance?.logEvent(event) kit.logEvent(event) @@ -1109,12 +1178,20 @@ class AppboyKitTests { fun testParseToNestedMap_When_JSON_Is_INVALID() { val kit = MockAppboyKit() var jsonInput = - "{'GDPR':{'marketing':'{:false,'timestamp':1711038269644:'Test consent','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}','performance':'{'consented':true,'timestamp':1711038269644,'document':'parental_consent_agreement_v2','location':'17 Cherry Tree Lan 3','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'},'CCPA':'{'consented':true,'timestamp':1711038269644,'document':'ccpa_consent_agreement_v3','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'}" - - val method: Method = AppboyKit::class.java.getDeclaredMethod( - "parseToNestedMap", - String::class.java, - ) + "{'GDPR':{'marketing':'{:false,'timestamp':1711038269644:'Test consent'," + + "'location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}," + + "'performance':'{'consented':true,'timestamp':1711038269644," + + "'document':'parental_consent_agreement_v2','location':'17 Cherry Tree Lan 3'," + + "'hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'}," + + "'CCPA':'{'consented':true,'timestamp':1711038269644," + + "'document':'ccpa_consent_agreement_v3','location':'17 Cherry Tree Lane'," + + "'hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'}" + + val method: Method = + AppboyKit::class.java.getDeclaredMethod( + "parseToNestedMap", + String::class.java, + ) method.isAccessible = true val result = method.invoke(kit, jsonInput) Assert.assertEquals(mutableMapOf(), result) @@ -1125,10 +1202,11 @@ class AppboyKitTests { val kit = MockAppboyKit() var jsonInput = "" - val method: Method = AppboyKit::class.java.getDeclaredMethod( - "parseToNestedMap", - String::class.java, - ) + val method: Method = + AppboyKit::class.java.getDeclaredMethod( + "parseToNestedMap", + String::class.java, + ) method.isAccessible = true val result = method.invoke(kit, jsonInput) Assert.assertEquals(mutableMapOf(), result) @@ -1137,22 +1215,26 @@ class AppboyKitTests { @Test fun testSearchKeyInNestedMap_When_Input_Key_Is_Empty_String() { val kit = MockAppboyKit() - val map = mapOf( - "FeatureEnabled" to true, - "settings" to mapOf( - "darkMode" to false, - "notifications" to mapOf( - "email" to false, - "push" to true, - "lastUpdated" to 1633046400000L, - ), - ), - ) - val method: Method = AppboyKit::class.java.getDeclaredMethod( - "searchKeyInNestedMap", - Map::class.java, - Any::class.java, - ) + val map = + mapOf( + "FeatureEnabled" to true, + "settings" to + mapOf( + "darkMode" to false, + "notifications" to + mapOf( + "email" to false, + "push" to true, + "lastUpdated" to 1633046400000L, + ), + ), + ) + val method: Method = + AppboyKit::class.java.getDeclaredMethod( + "searchKeyInNestedMap", + Map::class.java, + Any::class.java, + ) method.isAccessible = true val result = method.invoke(kit, map, "") Assert.assertEquals(null, result) @@ -1162,11 +1244,12 @@ class AppboyKitTests { fun testSearchKeyInNestedMap_When_Input_Is_Empty_Map() { val kit = MockAppboyKit() val emptyMap: Map = emptyMap() - val method: Method = AppboyKit::class.java.getDeclaredMethod( - "searchKeyInNestedMap", - Map::class.java, - Any::class.java, - ) + val method: Method = + AppboyKit::class.java.getDeclaredMethod( + "searchKeyInNestedMap", + Map::class.java, + Any::class.java, + ) method.isAccessible = true val result = method.invoke(kit, emptyMap, "1") Assert.assertEquals(null, result) @@ -1176,10 +1259,11 @@ class AppboyKitTests { fun testParseConsentMapping_When_Input_Is_Empty_Json() { val kit = MockAppboyKit() val emptyJson = "" - val method: Method = AppboyKit::class.java.getDeclaredMethod( - "parseConsentMapping", - String::class.java, - ) + val method: Method = + AppboyKit::class.java.getDeclaredMethod( + "parseConsentMapping", + String::class.java, + ) method.isAccessible = true val result = method.invoke(kit, emptyJson) Assert.assertEquals(emptyMap(), result) @@ -1189,11 +1273,19 @@ class AppboyKitTests { fun testParseConsentMapping_When_Input_Is_Invalid_Json() { val kit = MockAppboyKit() var jsonInput = - "{'GDPR':{'marketing':'{:false,'timestamp':1711038269644:'Test consent','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}','performance':'{'consented':true,'timestamp':1711038269644,'document':'parental_consent_agreement_v2','location':'17 Cherry Tree Lan 3','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'},'CCPA':'{'consented':true,'timestamp':1711038269644,'document':'ccpa_consent_agreement_v3','location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'}" - val method: Method = AppboyKit::class.java.getDeclaredMethod( - "parseConsentMapping", - String::class.java, - ) + "{'GDPR':{'marketing':'{:false,'timestamp':1711038269644:'Test consent'," + + "'location':'17 Cherry Tree Lane','hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}," + + "'performance':'{'consented':true,'timestamp':1711038269644," + + "'document':'parental_consent_agreement_v2','location':'17 Cherry Tree Lan 3'," + + "'hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'}," + + "'CCPA':'{'consented':true,'timestamp':1711038269644," + + "'document':'ccpa_consent_agreement_v3','location':'17 Cherry Tree Lane'," + + "'hardware_id':'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'}'}" + val method: Method = + AppboyKit::class.java.getDeclaredMethod( + "parseConsentMapping", + String::class.java, + ) method.isAccessible = true val result = method.invoke(kit, jsonInput) Assert.assertEquals(emptyMap(), result) @@ -1202,10 +1294,11 @@ class AppboyKitTests { @Test fun testParseConsentMapping_When_Input_Is_NULL() { val kit = MockAppboyKit() - val method: Method = AppboyKit::class.java.getDeclaredMethod( - "parseConsentMapping", - String::class.java, - ) + val method: Method = + AppboyKit::class.java.getDeclaredMethod( + "parseConsentMapping", + String::class.java, + ) method.isAccessible = true val result = method.invoke(kit, null) Assert.assertEquals(emptyMap(), result) @@ -1219,24 +1312,34 @@ class AppboyKitTests { val map = java.util.HashMap() map["consentMappingSDK"] = - " [{\\\"jsmap\\\":null,\\\"map\\\":\\\"Performance\\\",\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_user_data\\\"},{\\\"jsmap\\\":null,\\\"map\\\":\\\"Marketing\\\",\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_personalization\\\"}]" + " [{\\\"jsmap\\\":null,\\\"map\\\":\\\"Performance\\\"," + + "\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_user_data\\\"}," + + "{\\\"jsmap\\\":null,\\\"map\\\":\\\"Marketing\\\"," + + "\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_personalization\\\"}]" var kitConfiguration = MockKitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) kit.configuration = kitConfiguration - val marketingConsent = GDPRConsent.builder(false) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - val state = ConsentState.builder() - .addGDPRConsentState("Marketing", marketingConsent) - .build() + val marketingConsent = + GDPRConsent + .builder(false) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + val state = + ConsentState + .builder() + .addGDPRConsentState("Marketing", marketingConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) - TestCase.assertEquals(false, currentUser.getCustomUserAttribute()["\$google_ad_personalization"]) + TestCase.assertEquals( + false, + currentUser.getCustomUserAttribute()["\$google_ad_personalization"], + ) } @Test @@ -1247,33 +1350,45 @@ class AppboyKitTests { val map = java.util.HashMap() map["consentMappingSDK"] = - " [{\\\"jsmap\\\":null,\\\"map\\\":\\\"Performance\\\",\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_user_data\\\"},{\\\"jsmap\\\":null,\\\"map\\\":\\\"Marketing\\\",\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_personalization\\\"}]" + " [{\\\"jsmap\\\":null,\\\"map\\\":\\\"Performance\\\"," + + "\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_user_data\\\"}," + + "{\\\"jsmap\\\":null,\\\"map\\\":\\\"Marketing\\\"," + + "\\\"maptype\\\":\\\"ConsentPurposes\\\",\\\"value\\\":\\\"google_ad_personalization\\\"}]" var kitConfiguration = MockKitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) kit.configuration = kitConfiguration - val marketingConsent = GDPRConsent.builder(true) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val performanceConsent = GDPRConsent.builder(true) - .document("parental_consent_agreement_v2") - .location("17 Cherry Tree Lan 3") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val state = ConsentState.builder() - .addGDPRConsentState("Marketing", marketingConsent) - .addGDPRConsentState("Performance", performanceConsent) - .build() + val marketingConsent = + GDPRConsent + .builder(true) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val performanceConsent = + GDPRConsent + .builder(true) + .document("parental_consent_agreement_v2") + .location("17 Cherry Tree Lan 3") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val state = + ConsentState + .builder() + .addGDPRConsentState("Marketing", marketingConsent) + .addGDPRConsentState("Performance", performanceConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) TestCase.assertEquals(true, currentUser.getCustomUserAttribute()["\$google_ad_user_data"]) - TestCase.assertEquals(true, currentUser.getCustomUserAttribute()["\$google_ad_personalization"]) + TestCase.assertEquals( + true, + currentUser.getCustomUserAttribute()["\$google_ad_personalization"], + ) } @Test @@ -1281,22 +1396,28 @@ class AppboyKitTests { val kit = MockAppboyKit() val currentUser = braze.currentUser kit.configuration = MockKitConfiguration() - val marketingConsent = GDPRConsent.builder(true) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val performanceConsent = GDPRConsent.builder(true) - .document("parental_consent_agreement_v2") - .location("17 Cherry Tree Lan 3") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val state = ConsentState.builder() - .addGDPRConsentState("Marketing", marketingConsent) - .addGDPRConsentState("Performance", performanceConsent) - .build() + val marketingConsent = + GDPRConsent + .builder(true) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val performanceConsent = + GDPRConsent + .builder(true) + .document("parental_consent_agreement_v2") + .location("17 Cherry Tree Lan 3") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val state = + ConsentState + .builder() + .addGDPRConsentState("Marketing", marketingConsent) + .addGDPRConsentState("Performance", performanceConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) TestCase.assertEquals(0, currentUser.getCustomUserAttribute().size) @@ -1316,22 +1437,28 @@ class AppboyKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", map.toMutableMap())) - val marketingConsent = GDPRConsent.builder(true) - .document("Test consent") - .location("17 Cherry Tree Lane") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val performanceConsent = GDPRConsent.builder(true) - .document("parental_consent_agreement_v2") - .location("17 Cherry Tree Lan 3") - .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") - .build() - - val state = ConsentState.builder() - .addGDPRConsentState("Marketing", marketingConsent) - .addGDPRConsentState("Performance", performanceConsent) - .build() + val marketingConsent = + GDPRConsent + .builder(true) + .document("Test consent") + .location("17 Cherry Tree Lane") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val performanceConsent = + GDPRConsent + .builder(true) + .document("parental_consent_agreement_v2") + .location("17 Cherry Tree Lan 3") + .hardwareId("IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702") + .build() + + val state = + ConsentState + .builder() + .addGDPRConsentState("Marketing", marketingConsent) + .addGDPRConsentState("Performance", performanceConsent) + .build() filteredMParticleUser = FilteredMParticleUser.getInstance(user, kit) kit.onConsentStateUpdated(state, state, filteredMParticleUser) @@ -1349,18 +1476,24 @@ class AppboyKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", settings)) kit.onKitCreate(settings, MockContextApplication()) - val product = Product.Builder("product name", "sku1", 4.5) - .build() - val commerceEvent = CommerceEvent.Builder(Product.CHECKOUT, product) - .currency("Moon Dollars") - .build() + val product = + Product + .Builder("product name", "sku1", 4.5) + .build() + val commerceEvent = + CommerceEvent + .Builder(Product.CHECKOUT, product) + .currency("Moon Dollars") + .build() kit.logTransaction(commerceEvent, product) val braze = Braze val purchases = braze.purchases Assert.assertEquals(1, purchases.size.toLong()) val purchase = purchases[0] Assert.assertEquals("product name", purchase.sku) - Assert.assertNull(purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE]) + Assert.assertNull( + purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE], + ) } @Test @@ -1373,18 +1506,24 @@ class AppboyKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", settings)) kit.onKitCreate(settings, MockContextApplication()) - val product = Product.Builder("product name", "sku1", 4.5) - .build() - val commerceEvent = CommerceEvent.Builder(Product.CHECKOUT, product) - .currency("Moon Dollars") - .build() + val product = + Product + .Builder("product name", "sku1", 4.5) + .build() + val commerceEvent = + CommerceEvent + .Builder(Product.CHECKOUT, product) + .currency("Moon Dollars") + .build() kit.logTransaction(commerceEvent, product) val braze = Braze val purchases = braze.purchases Assert.assertEquals(1, purchases.size.toLong()) val purchase = purchases[0] Assert.assertEquals("sku1", purchase.sku) - Assert.assertNull(purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE]) + Assert.assertNull( + purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE], + ) } @Test @@ -1396,17 +1535,23 @@ class AppboyKitTests { kit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("as", settings)) kit.onKitCreate(settings, MockContextApplication()) - val product = Product.Builder("product name", "sku1", 4.5) - .build() - val commerceEvent = CommerceEvent.Builder(Product.CHECKOUT, product) - .currency("Moon Dollars") - .build() + val product = + Product + .Builder("product name", "sku1", 4.5) + .build() + val commerceEvent = + CommerceEvent + .Builder(Product.CHECKOUT, product) + .currency("Moon Dollars") + .build() kit.logTransaction(commerceEvent, product) val braze = Braze val purchases = braze.purchases Assert.assertEquals(1, purchases.size.toLong()) val purchase = purchases[0] Assert.assertEquals("sku1", purchase.sku) - Assert.assertNull(purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE]) + Assert.assertNull( + purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE], + ) } } diff --git a/src/test/kotlin/com/mparticle/kits/TypeDetectionTests.kt b/src/test/kotlin/com/mparticle/kits/TypeDetectionTests.kt index 56bdbfb..65e9b5e 100644 --- a/src/test/kotlin/com/mparticle/kits/TypeDetectionTests.kt +++ b/src/test/kotlin/com/mparticle/kits/TypeDetectionTests.kt @@ -48,28 +48,44 @@ class TypeDetectionTests { Assert.assertEquals("true", parser.parseValue("key", "true")) } - private inner class SomeParser internal constructor(enableTypeDetection: Boolean?) : - StringTypeParser( + private inner class SomeParser internal constructor( + enableTypeDetection: Boolean?, + ) : StringTypeParser( enableTypeDetection!!, ) { - override fun toString(key: String, value: String) { - /* do nothing */ + override fun toString( + key: String, + value: String, + ) { + // do nothing } - override fun toInt(key: String, value: Int) { - /* do nothing */ + override fun toInt( + key: String, + value: Int, + ) { + // do nothing } - override fun toLong(key: String, value: Long) { - /* do nothing */ + override fun toLong( + key: String, + value: Long, + ) { + // do nothing } - override fun toDouble(key: String, value: Double) { - /* do nothing */ + override fun toDouble( + key: String, + value: Double, + ) { + // do nothing } - override fun toBoolean(key: String, value: Boolean) { - /* do nothing */ + override fun toBoolean( + key: String, + value: Boolean, + ) { + // do nothing } } } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockAppboyKit.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockAppboyKit.kt index 386a454..f96faa2 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockAppboyKit.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockAppboyKit.kt @@ -7,6 +7,7 @@ import org.mockito.Mockito class MockAppboyKit : AppboyKit() { val calledAuthority = arrayOfNulls(1) + override fun setAuthority(authority: String?) { calledAuthority[0] = authority } @@ -16,12 +17,13 @@ class MockAppboyKit : AppboyKit() { } init { - kitManager = MockKitManagerImpl( - Mockito.mock(Context::class.java), - Mockito.mock( - ReportingManager::class.java, - ), - MockCoreCallbacks(), - ) + kitManager = + MockKitManagerImpl( + Mockito.mock(Context::class.java), + Mockito.mock( + ReportingManager::class.java, + ), + MockCoreCallbacks(), + ) } } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockApplication.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockApplication.kt index fc5a818..be9dc8b 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockApplication.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockApplication.kt @@ -7,8 +7,11 @@ import android.content.pm.ApplicationInfo import android.content.pm.PackageManager import android.content.res.Resources -class MockApplication(var mContext: MockContext) : Application() { +class MockApplication( + var mContext: MockContext, +) : Application() { var mCallbacks: ActivityLifecycleCallbacks? = null + override fun registerActivityLifecycleCallbacks(callback: ActivityLifecycleCallbacks) { mCallbacks = callback } @@ -21,7 +24,10 @@ class MockApplication(var mContext: MockContext) : Application() { override fun getSystemService(name: String): Any? = mContext.getSystemService(name) - override fun getSharedPreferences(name: String, mode: Int): SharedPreferences = mContext.getSharedPreferences(name, mode) + override fun getSharedPreferences( + name: String, + mode: Int, + ): SharedPreferences = mContext.getSharedPreferences(name, mode) override fun getPackageManager(): PackageManager = mContext.packageManager diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockContext.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockContext.kt index 999be6d..1d62077 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockContext.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockContext.kt @@ -43,6 +43,7 @@ class MockContext : Context() { private var sharedPreferences: SharedPreferences = MockSharedPreferences() private var resources: Resources = MockResources() var application: MockApplication? = null + fun setSharedPreferences(prefs: SharedPreferences) { sharedPreferences = prefs } @@ -56,15 +57,19 @@ class MockContext : Context() { override fun checkCallingOrSelfPermission(permission: String): Int = PackageManager.PERMISSION_GRANTED - override fun getSharedPreferences(name: String, mode: Int): SharedPreferences = sharedPreferences + override fun getSharedPreferences( + name: String, + mode: Int, + ): SharedPreferences = sharedPreferences override fun getResources(): Resources? = resources - override fun getSystemService(name: String): Any? = if (name == TELEPHONY_SERVICE) { - Mockito.mock(TelephonyManager::class.java) - } else { - null - } + override fun getSystemService(name: String): Any? = + if (name == TELEPHONY_SERVICE) { + Mockito.mock(TelephonyManager::class.java) + } else { + null + } override fun getPackageManager(): PackageManager { val manager = Mockito.mock(PackageManager::class.java) @@ -73,11 +78,14 @@ class MockContext : Context() { info.versionCode = 42 val appInfo = Mockito.mock(ApplicationInfo::class.java) try { - Mockito.`when`(manager.getPackageInfo(Mockito.anyString(), Mockito.anyInt())) + Mockito + .`when`(manager.getPackageInfo(Mockito.anyString(), Mockito.anyInt())) .thenReturn(info) - Mockito.`when`(manager.getInstallerPackageName(Mockito.anyString())) + Mockito + .`when`(manager.getInstallerPackageName(Mockito.anyString())) .thenReturn("com.mparticle.test.installer") - Mockito.`when`(manager.getApplicationInfo(Mockito.anyString(), Mockito.anyInt())) + Mockito + .`when`(manager.getApplicationInfo(Mockito.anyString(), Mockito.anyInt())) .thenReturn(appInfo) Mockito.`when`(manager.getApplicationLabel(appInfo)).thenReturn("test label") } catch (e: Exception) { @@ -94,13 +102,23 @@ class MockContext : Context() { * Stubbed methods */ override fun setTheme(resid: Int) {} + override fun getTheme(): Theme? = null override fun getClassLoader(): ClassLoader? = null override fun sendBroadcast(intent: Intent) {} - override fun sendBroadcast(intent: Intent, receiverPermission: String?) {} - override fun sendOrderedBroadcast(intent: Intent, receiverPermission: String?) {} + + override fun sendBroadcast( + intent: Intent, + receiverPermission: String?, + ) {} + + override fun sendOrderedBroadcast( + intent: Intent, + receiverPermission: String?, + ) {} + override fun sendOrderedBroadcast( intent: Intent, receiverPermission: String?, @@ -112,7 +130,11 @@ class MockContext : Context() { ) { } - override fun sendBroadcastAsUser(intent: Intent, user: UserHandle) {} + override fun sendBroadcastAsUser( + intent: Intent, + user: UserHandle, + ) {} + override fun sendBroadcastAsUser( intent: Intent, user: UserHandle, @@ -133,6 +155,7 @@ class MockContext : Context() { } override fun sendStickyBroadcast(intent: Intent) {} + override fun sendStickyOrderedBroadcast( intent: Intent, resultReceiver: BroadcastReceiver, @@ -144,7 +167,12 @@ class MockContext : Context() { } override fun removeStickyBroadcast(intent: Intent) {} - override fun sendStickyBroadcastAsUser(intent: Intent, user: UserHandle) {} + + override fun sendStickyBroadcastAsUser( + intent: Intent, + user: UserHandle, + ) {} + override fun sendStickyOrderedBroadcastAsUser( intent: Intent, user: UserHandle, @@ -156,8 +184,15 @@ class MockContext : Context() { ) { } - override fun removeStickyBroadcastAsUser(intent: Intent, user: UserHandle) {} - override fun registerReceiver(receiver: BroadcastReceiver?, filter: IntentFilter): Intent? = null + override fun removeStickyBroadcastAsUser( + intent: Intent, + user: UserHandle, + ) {} + + override fun registerReceiver( + receiver: BroadcastReceiver?, + filter: IntentFilter, + ): Intent? = null override fun registerReceiver( receiver: BroadcastReceiver?, @@ -181,15 +216,21 @@ class MockContext : Context() { ): Intent? = null override fun unregisterReceiver(receiver: BroadcastReceiver) {} + override fun startService(service: Intent): ComponentName? = null override fun startForegroundService(service: Intent): ComponentName? = null override fun stopService(service: Intent): Boolean = false - override fun bindService(service: Intent, conn: ServiceConnection, flags: Int): Boolean = false + override fun bindService( + service: Intent, + conn: ServiceConnection, + flags: Int, + ): Boolean = false override fun unbindService(conn: ServiceConnection) {} + override fun startInstrumentation( className: ComponentName, profileFile: String?, @@ -198,17 +239,56 @@ class MockContext : Context() { override fun checkSelfPermission(permission: String): Int = 0 - override fun enforcePermission(permission: String, pid: Int, uid: Int, message: String?) {} - override fun enforceCallingPermission(permission: String, message: String?) {} - override fun enforceCallingOrSelfPermission(permission: String, message: String?) {} - override fun grantUriPermission(toPackage: String, uri: Uri, modeFlags: Int) {} - override fun revokeUriPermission(uri: Uri, modeFlags: Int) {} - override fun revokeUriPermission(toPackage: String, uri: Uri, modeFlags: Int) {} - override fun checkUriPermission(uri: Uri, pid: Int, uid: Int, modeFlags: Int): Int = 0 + override fun enforcePermission( + permission: String, + pid: Int, + uid: Int, + message: String?, + ) {} + + override fun enforceCallingPermission( + permission: String, + message: String?, + ) {} + + override fun enforceCallingOrSelfPermission( + permission: String, + message: String?, + ) {} + + override fun grantUriPermission( + toPackage: String, + uri: Uri, + modeFlags: Int, + ) {} + + override fun revokeUriPermission( + uri: Uri, + modeFlags: Int, + ) {} + + override fun revokeUriPermission( + toPackage: String, + uri: Uri, + modeFlags: Int, + ) {} + + override fun checkUriPermission( + uri: Uri, + pid: Int, + uid: Int, + modeFlags: Int, + ): Int = 0 - override fun checkCallingUriPermission(uri: Uri, modeFlags: Int): Int = 0 + override fun checkCallingUriPermission( + uri: Uri, + modeFlags: Int, + ): Int = 0 - override fun checkCallingOrSelfUriPermission(uri: Uri, modeFlags: Int): Int = 0 + override fun checkCallingOrSelfUriPermission( + uri: Uri, + modeFlags: Int, + ): Int = 0 override fun checkUriPermission( uri: Uri?, @@ -228,8 +308,18 @@ class MockContext : Context() { ) { } - override fun enforceCallingUriPermission(uri: Uri, modeFlags: Int, message: String) {} - override fun enforceCallingOrSelfUriPermission(uri: Uri, modeFlags: Int, message: String) {} + override fun enforceCallingUriPermission( + uri: Uri, + modeFlags: Int, + message: String, + ) {} + + override fun enforceCallingOrSelfUriPermission( + uri: Uri, + modeFlags: Int, + message: String, + ) {} + override fun enforceUriPermission( uri: Uri?, readPermission: String?, @@ -242,7 +332,10 @@ class MockContext : Context() { } @Throws(NameNotFoundException::class) - override fun createPackageContext(packageName: String, flags: Int): Context? = null + override fun createPackageContext( + packageName: String, + flags: Int, + ): Context? = null @Throws(NameNotFoundException::class) override fun createContextForSplit(splitName: String): Context? = null @@ -255,7 +348,10 @@ class MockContext : Context() { override fun isDeviceProtectedStorage(): Boolean = false - override fun moveSharedPreferencesFrom(sourceContext: Context, name: String): Boolean = false + override fun moveSharedPreferencesFrom( + sourceContext: Context, + name: String, + ): Boolean = false override fun deleteSharedPreferences(name: String): Boolean = false @@ -263,7 +359,10 @@ class MockContext : Context() { override fun openFileInput(name: String): FileInputStream? = null @Throws(FileNotFoundException::class) - override fun openFileOutput(name: String, mode: Int): FileOutputStream? = null + override fun openFileOutput( + name: String, + mode: Int, + ): FileOutputStream? = null override fun deleteFile(name: String): Boolean = false @@ -295,7 +394,10 @@ class MockContext : Context() { override fun fileList(): Array = arrayOfNulls(0) - override fun getDir(name: String, mode: Int): File? = null + override fun getDir( + name: String, + mode: Int, + ): File? = null override fun openOrCreateDatabase( name: String, @@ -310,7 +412,10 @@ class MockContext : Context() { errorHandler: DatabaseErrorHandler?, ): SQLiteDatabase? = null - override fun moveDatabaseFrom(sourceContext: Context, name: String): Boolean = false + override fun moveDatabaseFrom( + sourceContext: Context, + name: String, + ): Boolean = false override fun deleteDatabase(name: String): Boolean = false @@ -339,9 +444,18 @@ class MockContext : Context() { } override fun startActivity(intent: Intent) {} - override fun startActivity(intent: Intent, options: Bundle?) {} + + override fun startActivity( + intent: Intent, + options: Bundle?, + ) {} + override fun startActivities(intents: Array) {} - override fun startActivities(intents: Array, options: Bundle) {} + + override fun startActivities( + intents: Array, + options: Bundle, + ) {} @Throws(SendIntentException::class) override fun startIntentSender( @@ -366,7 +480,11 @@ class MockContext : Context() { override fun getSystemServiceName(serviceClass: Class<*>): String? = null - override fun checkPermission(permission: String, pid: Int, uid: Int): Int = 0 + override fun checkPermission( + permission: String, + pid: Int, + uid: Int, + ): Int = 0 override fun checkCallingPermission(permission: String): Int = 0 diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockContextApplication.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockContextApplication.kt index 3d8fec7..274af78 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockContextApplication.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockContextApplication.kt @@ -4,12 +4,14 @@ import android.app.Application import android.app.Application.ActivityLifecycleCallbacks import android.content.Context import android.content.SharedPreferences -import com.mparticle.kits.mocks.MockSharedPreferences class MockContextApplication : Application() { override fun getApplicationContext(): Context = this - override fun getSharedPreferences(name: String, mode: Int): SharedPreferences = MockSharedPreferences() + override fun getSharedPreferences( + name: String, + mode: Int, + ): SharedPreferences = MockSharedPreferences() override fun registerActivityLifecycleCallbacks(callback: ActivityLifecycleCallbacks) { // do nothing diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockCoreCallbacks.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockCoreCallbacks.kt index 0688d05..fe538f4 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockCoreCallbacks.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockCoreCallbacks.kt @@ -15,7 +15,11 @@ class MockCoreCallbacks : CoreCallbacks { override fun isEnabled(): Boolean = false - override fun setIntegrationAttributes(kitId: Int, integrationAttributes: Map) {} + override fun setIntegrationAttributes( + kitId: Int, + integrationAttributes: Map, + ) {} + override fun getIntegrationAttributes(kitId: Int): Map? = null override fun getCurrentActivity(): WeakReference? = null @@ -34,12 +38,33 @@ class MockCoreCallbacks : CoreCallbacks { override fun getLaunchAction(): String? = null - override fun getKitListener(): KitListener = object : KitListener { - override fun kitFound(kitId: Int) {} - override fun kitConfigReceived(kitId: Int, configuration: String?) {} - override fun kitExcluded(kitId: Int, reason: String?) {} - override fun kitStarted(kitId: Int) {} - override fun onKitApiCalled(kitId: Int, used: Boolean?, vararg objects: Any?) {} - override fun onKitApiCalled(methodName: String?, kitId: Int, used: Boolean?, vararg objects: Any?) {} - } + override fun getKitListener(): KitListener = + object : KitListener { + override fun kitFound(kitId: Int) {} + + override fun kitConfigReceived( + kitId: Int, + configuration: String?, + ) {} + + override fun kitExcluded( + kitId: Int, + reason: String?, + ) {} + + override fun kitStarted(kitId: Int) {} + + override fun onKitApiCalled( + kitId: Int, + used: Boolean?, + vararg objects: Any?, + ) {} + + override fun onKitApiCalled( + methodName: String?, + kitId: Int, + used: Boolean?, + vararg objects: Any?, + ) {} + } } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockKitConfiguration.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockKitConfiguration.kt index 7a8a37c..556310a 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockKitConfiguration.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockKitConfiguration.kt @@ -3,8 +3,6 @@ package com.mparticle.kits.mocks import android.util.SparseBooleanArray import com.mparticle.internal.Logger import com.mparticle.kits.KitConfiguration -import com.mparticle.kits.mocks.MockKitConfiguration -import com.mparticle.kits.mocks.MockKitConfiguration.MockSparseBooleanArray import org.json.JSONException import org.json.JSONObject import java.util.HashMap @@ -42,7 +40,10 @@ open class MockKitConfiguration : KitConfiguration() { internal inner class MockSparseBooleanArray : SparseBooleanArray() { override fun get(key: Int): Boolean = get(key, false) - override fun get(key: Int, valueIfKeyNotFound: Boolean): Boolean { + override fun get( + key: Int, + valueIfKeyNotFound: Boolean, + ): Boolean { print("SparseArray getting: $key") return if (map.containsKey(key)) { true @@ -52,7 +53,11 @@ open class MockKitConfiguration : KitConfiguration() { } var map: MutableMap = HashMap() - override fun put(key: Int, value: Boolean) { + + override fun put( + key: Int, + value: Boolean, + ) { map[key] = value } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockKitManagerImpl.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockKitManagerImpl.kt index b440e6c..eb493b2 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockKitManagerImpl.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockKitManagerImpl.kt @@ -7,8 +7,6 @@ import com.mparticle.internal.CoreCallbacks.KitListener import com.mparticle.internal.ReportingManager import com.mparticle.kits.KitConfiguration import com.mparticle.kits.KitManagerImpl -import com.mparticle.kits.mocks.MockContext -import com.mparticle.kits.mocks.MockKitConfiguration import org.json.JSONException import org.json.JSONObject import org.mockito.Mockito @@ -19,13 +17,13 @@ class MockKitManagerImpl( reportingManager: ReportingManager?, coreCallbacks: CoreCallbacks?, ) : KitManagerImpl( - context, - reportingManager, - coreCallbacks, - Mockito.mock( - MParticleOptions::class.java, - ), -) { + context, + reportingManager, + coreCallbacks, + Mockito.mock( + MParticleOptions::class.java, + ), + ) { constructor() : this( MockContext(), Mockito.mock(ReportingManager::class.java), @@ -33,18 +31,41 @@ class MockKitManagerImpl( CoreCallbacks::class.java, ), ) { - Mockito.`when`(mCoreCallbacks.getKitListener()).thenReturn(object : KitListener { - override fun kitFound(kitId: Int) {} - override fun kitConfigReceived(kitId: Int, configuration: String?) {} - override fun kitExcluded(kitId: Int, reason: String?) {} - override fun kitStarted(kitId: Int) {} - override fun onKitApiCalled(kitId: Int, used: Boolean?, vararg objects: Any?) {} - override fun onKitApiCalled(methodName: String?, kitId: Int, used: Boolean?, vararg objects: Any?) {} - }) + Mockito.`when`(mCoreCallbacks.getKitListener()).thenReturn( + object : KitListener { + override fun kitFound(kitId: Int) {} + + override fun kitConfigReceived( + kitId: Int, + configuration: String?, + ) {} + + override fun kitExcluded( + kitId: Int, + reason: String?, + ) {} + + override fun kitStarted(kitId: Int) {} + + override fun onKitApiCalled( + kitId: Int, + used: Boolean?, + vararg objects: Any?, + ) {} + + override fun onKitApiCalled( + methodName: String?, + kitId: Int, + used: Boolean?, + vararg objects: Any?, + ) {} + }, + ) } @Throws(JSONException::class) - override fun createKitConfiguration(configuration: JSONObject): KitConfiguration = MockKitConfiguration.createKitConfiguration(configuration) + override fun createKitConfiguration(configuration: JSONObject): KitConfiguration = + MockKitConfiguration.createKitConfiguration(configuration) override fun getUserBucket(): Int = 50 } diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockResources.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockResources.kt index bb962e3..4b2dca6 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockResources.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockResources.kt @@ -2,11 +2,14 @@ package com.mparticle.kits.mocks import android.content.res.Resources import android.content.res.Resources.NotFoundException -import com.mparticle.kits.mocks.MockResources import kotlin.Throws class MockResources : Resources(null, null, null) { - override fun getIdentifier(name: String, defType: String, defPackage: String): Int { + override fun getIdentifier( + name: String, + defType: String, + defPackage: String, + ): Int { if (name == "mp_key") { return 1 } else if (name == "mp_secret") { @@ -25,7 +28,10 @@ class MockResources : Resources(null, null, null) { } @Throws(NotFoundException::class) - override fun getString(id: Int, vararg formatArgs: Any): String = super.getString(id, *formatArgs) + override fun getString( + id: Int, + vararg formatArgs: Any, + ): String = super.getString(id, *formatArgs) companion object { var testAppKey = "the app key" diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockSharedPreferences.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockSharedPreferences.kt index 8b99f8f..70f5609 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockSharedPreferences.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockSharedPreferences.kt @@ -8,20 +8,37 @@ import java.util.TreeSet class MockSharedPreferences : SharedPreferences, Editor { - override fun getAll(): Map? = null - override fun getString(key: String, defValue: String?): String = "" + override fun getString( + key: String, + defValue: String?, + ): String = "" - override fun getStringSet(key: String, defValues: Set?): Set = TreeSet() + override fun getStringSet( + key: String, + defValues: Set?, + ): Set = TreeSet() - override fun getInt(key: String, defValue: Int): Int = 0 + override fun getInt( + key: String, + defValue: Int, + ): Int = 0 - override fun getLong(key: String, defValue: Long): Long = 0 + override fun getLong( + key: String, + defValue: Long, + ): Long = 0 - override fun getFloat(key: String, defValue: Float): Float = 0f + override fun getFloat( + key: String, + defValue: Float, + ): Float = 0f - override fun getBoolean(key: String, defValue: Boolean): Boolean = false + override fun getBoolean( + key: String, + defValue: Boolean, + ): Boolean = false override fun contains(key: String): Boolean = false @@ -31,17 +48,35 @@ class MockSharedPreferences : override fun unregisterOnSharedPreferenceChangeListener(listener: OnSharedPreferenceChangeListener) {} - override fun putString(key: String, value: String?): Editor = this - - override fun putStringSet(key: String, values: Set?): Editor = this - - override fun putInt(key: String, value: Int): Editor = this - - override fun putLong(key: String, value: Long): Editor = this - - override fun putFloat(key: String, value: Float): Editor = this - - override fun putBoolean(key: String, value: Boolean): Editor = this + override fun putString( + key: String, + value: String?, + ): Editor = this + + override fun putStringSet( + key: String, + values: Set?, + ): Editor = this + + override fun putInt( + key: String, + value: Int, + ): Editor = this + + override fun putLong( + key: String, + value: Long, + ): Editor = this + + override fun putFloat( + key: String, + value: Float, + ): Editor = this + + override fun putBoolean( + key: String, + value: Boolean, + ): Editor = this override fun remove(key: String): Editor = this diff --git a/src/test/kotlin/com/mparticle/kits/mocks/MockUser.kt b/src/test/kotlin/com/mparticle/kits/mocks/MockUser.kt index b5bebca..35125bb 100644 --- a/src/test/kotlin/com/mparticle/kits/mocks/MockUser.kt +++ b/src/test/kotlin/com/mparticle/kits/mocks/MockUser.kt @@ -7,8 +7,9 @@ import com.mparticle.audience.AudienceTask import com.mparticle.consent.ConsentState import com.mparticle.identity.MParticleUser -class MockUser(var identities: Map) : MParticleUser { - +class MockUser( + var identities: Map, +) : MParticleUser { override fun getId(): Long = 0 override fun getUserAttributes(): Map = mapOf() @@ -19,11 +20,20 @@ class MockUser(var identities: Map) : MParticleUser { override fun getUserIdentities(): Map = identities - override fun setUserAttribute(s: String, o: Any): Boolean = false + override fun setUserAttribute( + s: String, + o: Any, + ): Boolean = false - override fun setUserAttributeList(s: String, o: Any): Boolean = false + override fun setUserAttributeList( + s: String, + o: Any, + ): Boolean = false - override fun incrementUserAttribute(p0: String, p1: Number?): Boolean = false + override fun incrementUserAttribute( + p0: String, + p1: Number?, + ): Boolean = false override fun removeUserAttribute(s: String): Boolean = false From 9cfbc860e665eca1766d90e8736ab4f329953017 Mon Sep 17 00:00:00 2001 From: Thomson Thomas Date: Fri, 16 Jan 2026 16:17:41 -0500 Subject: [PATCH 14/14] Workaround for lint crash --- build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.gradle b/build.gradle index 43727ed..b00ecfc 100644 --- a/build.gradle +++ b/build.gradle @@ -41,6 +41,12 @@ android { defaultConfig { minSdkVersion 21 } + lint { + // Workaround for lint internal crash + abortOnError false + // Ignore obsolete custom lint checks from older fragment library + disable 'ObsoleteLintCustomCheck' + } compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17