Skip to content

Commit

Permalink
feat: SQDSDKS-5543 formatting, clean-up and reorganizing imports (#406)
Browse files Browse the repository at this point in the history
* Formatting core

* Formatting kit-base

* Formatting tooling, kit-plugins and tets-utils

* ktlintformat
  • Loading branch information
markvdouw authored Jul 25, 2023
1 parent 49ec0ea commit 341118c
Show file tree
Hide file tree
Showing 219 changed files with 2,306 additions and 1,802 deletions.
5 changes: 3 additions & 2 deletions android-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ dependencies {

api 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'

lintPublish project( path: ':tooling:custom-lint-rules', configuration: 'lintBuild')
lintPublish project(path: ':tooling:custom-lint-rules', configuration: 'lintBuild')

//the junit tests seem to explicitly need this dependency while
//working in Android studio, but from the command line it's not necessary
Expand Down Expand Up @@ -168,5 +168,6 @@ configurations {
}
}

boolean useOrchestrator() { return project.hasProperty('orchestrator') ? project.property('orchestrator') : false
boolean useOrchestrator() {
return project.hasProperty('orchestrator') ? project.property('orchestrator') : false
}
30 changes: 15 additions & 15 deletions android-core/lint-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
<lint>
<issue id="UnknownNullness">
<ignore path="src/main/java/com/mparticle/internal" />
<ignore path="src/main/java/com/mparticle/networking/BaseNetworkConnection"/>
<ignore path="src/main/java/com/mparticle/ExceptionHandler.java"/>
<ignore path="src/main/java/com/mparticle/messaging/InstanceIdService"/>
<ignore path="src/main/java/com/mparticle/networking/MPConnection"/>
<ignore path="src/main/java/com/mparticle/networking/MPUrl"/>
<ignore path="src/main/java/com/mparticle/messaging/MPMessagingRouter"/>
<ignore path="src/main/java/com/mparticle/MPServiceUtil"/>
<ignore path="src/main/java/com/mparticle/networking/MParticleBaseClientImpl"/>
<ignore path="src/main/java/com/mparticle/networking/MParticleBaseClient"/>
<ignore path="src/main/java/com/mparticle/networking/NetworkConnection"/>
<ignore path="src/main/java/com/mparticle/networking/NetworkOptionsManager"/>
<ignore path="src/main/java/com/mparticle/identity/MParticleUserImpl"/>
<ignore path="src/main/java/com/mparticle/identity/MParticleIdentityClient"/>
<ignore path="src/main/java/com/mparticle/messaging/ProviderCloudMessage"/>
<ignore path="src/main/java/com/mparticle/messaging/PushAnalyticsReceiver"/>
<ignore path="src/main/java/com/mparticle/networking/BaseNetworkConnection" />
<ignore path="src/main/java/com/mparticle/ExceptionHandler.java" />
<ignore path="src/main/java/com/mparticle/messaging/InstanceIdService" />
<ignore path="src/main/java/com/mparticle/networking/MPConnection" />
<ignore path="src/main/java/com/mparticle/networking/MPUrl" />
<ignore path="src/main/java/com/mparticle/messaging/MPMessagingRouter" />
<ignore path="src/main/java/com/mparticle/MPServiceUtil" />
<ignore path="src/main/java/com/mparticle/networking/MParticleBaseClientImpl" />
<ignore path="src/main/java/com/mparticle/networking/MParticleBaseClient" />
<ignore path="src/main/java/com/mparticle/networking/NetworkConnection" />
<ignore path="src/main/java/com/mparticle/networking/NetworkOptionsManager" />
<ignore path="src/main/java/com/mparticle/identity/MParticleUserImpl" />
<ignore path="src/main/java/com/mparticle/identity/MParticleIdentityClient" />
<ignore path="src/main/java/com/mparticle/messaging/ProviderCloudMessage" />
<ignore path="src/main/java/com/mparticle/messaging/PushAnalyticsReceiver" />
</issue>
</lint>
25 changes: 15 additions & 10 deletions android-core/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-sdk android:minSdkVersion="21" tools:overrideLibrary="com.mparticle.testutils"/>
<uses-sdk
android:minSdkVersion="21"
tools:overrideLibrary="com.mparticle.testutils" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<application
android:usesCleartextTraffic="true">
<application android:usesCleartextTraffic="true">

<activity android:exported="true" android:name="com.mparticle.WebViewActivity">
<activity
android:exported="true"
android:name="com.mparticle.WebViewActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:exported="true" android:name="com.mparticle.MPService" />
<service
android:exported="true"
android:name="com.mparticle.MPService" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ public void run() {

@Test
public void testSetUserAttribute() throws Exception {
final String key = mRandomUtils.getAlphaNumericString(25);
final String value = mRandomUtils.getAlphaNumericString(25);
final String key = mRandomUtils.getAlphaNumericString(25);
final String value = mRandomUtils.getAlphaNumericString(25);
String testJavascript = String.format("mParticle.Identity.getCurrentUser().setUserAttribute(\"%s\", \"%s\");\n", key, value);
final MutableBoolean called = new MutableBoolean(false);
final CountDownLatch latch = new MPLatch(1);
runJavascriptTest(testJavascript, new MParticleJSInterface(){
runJavascriptTest(testJavascript, new MParticleJSInterface() {
@Override
@JavascriptInterface
public void setUserAttribute(String json) {
Expand All @@ -232,8 +232,7 @@ public void setUserAttribute(String json) {
assertEquals(value, jsonObject.getString("value"));
called.value = true;
latch.countDown();
}
catch (JSONException jse) {
} catch (JSONException jse) {
jse.printStackTrace();
}

Expand All @@ -249,7 +248,7 @@ public void testRemoveUserAttribute() throws Exception {
String testJavascript = String.format("mParticle.Identity.getCurrentUser().removeUserAttribute(\"%s\");\n", key);
final MutableBoolean called = new MutableBoolean(false);
final CountDownLatch latch = new MPLatch(1);
runJavascriptTest(testJavascript, new MParticleJSInterface(){
runJavascriptTest(testJavascript, new MParticleJSInterface() {
@Override
@JavascriptInterface
public void removeUserAttribute(String json) {
Expand All @@ -259,8 +258,7 @@ public void removeUserAttribute(String json) {
assertEquals(key, jsonObject.getString("key"));
called.value = true;
latch.countDown();
}
catch (JSONException jse) {
} catch (JSONException jse) {
jse.printStackTrace();
}
}
Expand All @@ -276,7 +274,7 @@ public void testSetUserTag() throws Exception {
final MutableBoolean called = new MutableBoolean(false);
final CountDownLatch latch = new MPLatch(1);
//This is acceptable if the JS SDK calls either setUserTag, or setUserAttribute with a null value
runJavascriptTest(testJavascript, new MParticleJSInterface(){
runJavascriptTest(testJavascript, new MParticleJSInterface() {
@Override
@JavascriptInterface
public void setUserTag(String json) {
Expand All @@ -286,8 +284,7 @@ public void setUserTag(String json) {
assertEquals(tag, jsonObject.getString("key"));
called.value = true;
latch.countDown();
}
catch (JSONException jse) {
} catch (JSONException jse) {
jse.printStackTrace();
}
}
Expand All @@ -302,8 +299,7 @@ public void setUserAttribute(String json) {
assertEquals(jsonObject.optString("value", "null"), "null");
called.value = true;
latch.countDown();
}
catch (JSONException jse) {
} catch (JSONException jse) {
jse.printStackTrace();
}
}
Expand All @@ -314,7 +310,7 @@ public void setUserAttribute(String json) {

@Test
public void testLogEvent() throws Exception {
final JSONObject customAttributes = MPUtility.mapToJson( mRandomUtils.getRandomAttributes(10));
final JSONObject customAttributes = MPUtility.mapToJson(mRandomUtils.getRandomAttributes(10));
final JSONObject customFlagsJSON = MPUtility.mapToJson(getCustomFlags());
String testJavascript = String.format("mParticle.logEvent('Play Movie Tapped',\n" +
" mParticle.EventType.Navigation,\n" +
Expand Down Expand Up @@ -371,7 +367,7 @@ public void logEvent(String json) {

@Test
public void testLogCommerceEvent() throws Exception {
final JSONObject customAttributes = MPUtility.mapToJson( mRandomUtils.getRandomAttributes(10));
final JSONObject customAttributes = MPUtility.mapToJson(mRandomUtils.getRandomAttributes(10));
final JSONObject customFlags = MPUtility.mapToJson(getCustomFlags());
String testJavascript = String.format("// 1. Create the product\n" +
"var product = mParticle.eCommerce.createProduct(\n" +
Expand Down Expand Up @@ -454,7 +450,7 @@ public void logEvent(String json) {

@Test
public void testLogout() throws Exception {
final Map<MParticle.IdentityType, String> userIdentityMap = mRandomUtils.getRandomUserIdentities();
final Map<MParticle.IdentityType, String> userIdentityMap = mRandomUtils.getRandomUserIdentities();
JSONObject jsonObject = userIdentityMapToJson(userIdentityMap);
String testJavascript = String.format("mParticle.Identity.logout(%s , null);", jsonObject.toString(4));

Expand Down Expand Up @@ -506,7 +502,7 @@ public void logout() {

@Test
public void testLogin() throws Exception {
final Map<MParticle.IdentityType, String> userIdentityMap = mRandomUtils.getRandomUserIdentities();
final Map<MParticle.IdentityType, String> userIdentityMap = mRandomUtils.getRandomUserIdentities();
JSONObject jsonObject = userIdentityMapToJson(userIdentityMap);
String testJavascript = String.format("mParticle.Identity.login(%s , null);", jsonObject.toString(4));

Expand Down Expand Up @@ -558,7 +554,7 @@ public void login() {

@Test
public void testModify() throws Exception {
final Map<MParticle.IdentityType, String> userIdentities = mRandomUtils.getRandomUserIdentities();
final Map<MParticle.IdentityType, String> userIdentities = mRandomUtils.getRandomUserIdentities();
JSONObject jsonObject = userIdentityMapToJson(userIdentities);
String testJavascript = String.format("mParticle.Identity.modify(%s , null);", jsonObject.toString(4));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ class BatchCreationCallbackTests : BaseCleanInstallEachTest() {
it.optJSONArray("msgs")
?.toList()
?.filterIsInstance<JSONObject>()
?.any { it.optString("n") == targetEventName && it.optString("mb").isNullOrEmpty() } ?: false
?.any {
it.optString("n") == targetEventName && it.optString("mb").isNullOrEmpty()
} ?: false
}
)

mServer.Requests().events.any {
it.bodyJson.optJSONArray("msgs")
?.toList()
?.filterIsInstance<JSONObject>()
?.any { it.optString("n") == targetEventName && it.optString("mb").isNullOrEmpty() } ?: false
?.any { it.optString("n") == targetEventName && it.optString("mb").isNullOrEmpty() }
?: false
}.let {
assertTrue { it }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class PushRegistrationTest : BaseCleanStartedEachTest() {
var setPushes = arrayOf(
object : SetPush {
override fun setPushRegistration(pushRegistration: PushRegistration) {
MParticle.getInstance()?.logPushRegistration(pushRegistration.instanceId, pushRegistration.senderId)
MParticle.getInstance()
?.logPushRegistration(pushRegistration.instanceId, pushRegistration.senderId)
}

override val name: String
Expand All @@ -134,8 +135,10 @@ class PushRegistrationTest : BaseCleanStartedEachTest() {
},
object : SetPush {
override fun setPushRegistration(pushRegistration: PushRegistration) {
MParticle.getInstance()?.mInternal?.configManager?.pushSenderId = pushRegistration.senderId
MParticle.getInstance()?.mInternal?.configManager?.pushInstanceId = pushRegistration.instanceId
MParticle.getInstance()?.mInternal?.configManager?.pushSenderId =
pushRegistration.senderId
MParticle.getInstance()?.mInternal?.configManager?.pushInstanceId =
pushRegistration.instanceId
}

override val name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ class UploadEventKotlinTest : BaseCleanStartedEachTest() {
it.optJSONArray("msgs")?.let { messagesArray ->
(0 until messagesArray.length())
.any {
val eventProductName = messagesArray.getJSONObject(it).optJSONObject("pd")?.optJSONArray("pl")?.optJSONObject(0)?.optString("nm")
val eventProductName =
messagesArray.getJSONObject(it).optJSONObject("pd")
?.optJSONArray("pl")?.optJSONObject(0)?.optString("nm")
assertNotEquals("Should Not Upload", eventProductName)
if (eventProductName == "Should Upload 1" || eventProductName == "Should Upload 2") {
numUploadedEvents++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.json.JSONObject
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import java.lang.Exception
import java.util.UUID
import java.util.concurrent.CountDownLatch

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MParticleUserDelegateITest : BaseCleanStartedEachTest() {
val attributes = HashMap<Long, Map<IdentityType, String>>()
for (i in 0..4) {
val mpid = ran.nextLong()
val pairs = HashMap<IdentityType, String> ()
val pairs = HashMap<IdentityType, String>()
attributes[mpid] = pairs
for (j in 0..2) {
val identityType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class ApplicationContextWrapperITest {
@OrchestratorOnly
@Test
fun testRegisterListenerBackgroundThread() {
val applicationContextWrapper = ApplicationContextWrapper(InstrumentationRegistry.getInstrumentation().getContext().applicationContext as Application)
val applicationContextWrapper = ApplicationContextWrapper(
InstrumentationRegistry.getInstrumentation()
.getContext().applicationContext as Application
)
var exception: Exception? = null
assertNull(Looper.myLooper())
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class BatchSessionInfoTest : BaseCleanStartedEachTest() {
@Test
fun testProperSessionAttachedToBatch() {
InstallReferrerHelper.setInstallReferrer(mContext, "111")
(0..150).forEach { MParticle.getInstance()?.logEvent(MPEvent.Builder(it.toString()).build()) }
(0..150).forEach {
MParticle.getInstance()?.logEvent(MPEvent.Builder(it.toString()).build())
}

AccessUtils.awaitMessageHandler()
MParticle.getInstance()?.Internal()?.apply {
Expand All @@ -56,7 +58,8 @@ class BatchSessionInfoTest : BaseCleanStartedEachTest() {
MParticle.getInstance()?.upload()
mServer.waitForVerify(
Matcher(mServer.Endpoints().getEventsUrl()).bodyMatch {
val version = it.getJSONObject("ai").getString(Constants.MessageKey.INSTALL_REFERRER)
val version =
it.getJSONObject("ai").getString(Constants.MessageKey.INSTALL_REFERRER)
if (it.has("msgs")) {
var messages = it.getJSONArray("msgs")
for (i in 0 until messages.length()) {
Expand All @@ -77,7 +80,8 @@ class BatchSessionInfoTest : BaseCleanStartedEachTest() {
}
mServer.waitForVerify(
Matcher(mServer.Endpoints().getEventsUrl()).bodyMatch {
val version = it.getJSONObject("ai").getString(Constants.MessageKey.INSTALL_REFERRER)
val version =
it.getJSONObject("ai").getString(Constants.MessageKey.INSTALL_REFERRER)
assertEquals("222", version)
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ class ConfigManagerInstrumentedTest : BaseAbstractTest() {
MParticle.getInstance()
?.Identity()?.currentUser?.id
)
MParticle.getInstance()?.Identity()?.currentUser?.isLoggedIn?.let { TestCase.assertTrue(it) }
MParticle.getInstance()
?.Identity()?.currentUser?.isLoggedIn?.let { TestCase.assertTrue(it) }
configManager?.setMpid(mpid3, true)
TestCase.assertEquals(
mpid3,
MParticle.getInstance()
?.Identity()?.currentUser?.id
)
MParticle.getInstance()?.Identity()?.currentUser?.isLoggedIn?.let { TestCase.assertTrue(it) }
MParticle.getInstance()
?.Identity()?.currentUser?.isLoggedIn?.let { TestCase.assertTrue(it) }
}

@Test
Expand Down Expand Up @@ -111,8 +113,14 @@ class ConfigManagerInstrumentedTest : BaseAbstractTest() {
.configuration(AddConfigListener(configLoadedListener))
)
latch.await()
TestCase.assertEquals("", MParticle.getInstance()?.Internal()?.configManager?.workspaceToken)
TestCase.assertEquals(90, MParticle.getInstance()?.Internal()?.configManager?.aliasMaxWindow)
TestCase.assertEquals(
"",
MParticle.getInstance()?.Internal()?.configManager?.workspaceToken
)
TestCase.assertEquals(
90,
MParticle.getInstance()?.Internal()?.configManager?.aliasMaxWindow
)
}

@Test
Expand Down Expand Up @@ -208,6 +216,7 @@ class ConfigManagerInstrumentedTest : BaseAbstractTest() {
override fun configures(): Class<ConfigManager> {
return ConfigManager::class.java
}

override fun apply(configManager: ConfigManager?) {
configManager?.addConfigUpdatedListener(configLoadedListener)
}
Expand Down
Loading

0 comments on commit 341118c

Please sign in to comment.