From 30286987c6688f174d9b7eceaa23cb6bd273e869 Mon Sep 17 00:00:00 2001 From: Zhe Lu Date: Fri, 16 Jun 2023 10:18:41 -0700 Subject: [PATCH] Fix checkbox type value formatting (#238) We should be expecting an array of JSON objects, with `label` and `value` in each object. --- .github/workflows/ci.yml | 2 +- README.md | 4 +- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 3 +- build.gradle | 6 +- connect-api/build.gradle | 2 +- connect-api/publish.gradle | 5 -- connect-api/src/main/AndroidManifest.xml | 3 +- .../ifttt/connect/api/CheckBoxFieldValue.java | 58 +++++++++++++++++++ .../com/ifttt/connect/api/CheckBoxValue.java | 57 ++++++++++++++++++ .../connect/api/ConnectionJsonAdapter.java | 26 +++++---- .../connect/api/StringArrayFieldValue.java | 42 -------------- .../ifttt/connect/api/UserFeatureField.java | 2 +- .../connect/api/ConnectionApiClientTest.java | 10 ++-- connect-button/build.gradle | 2 +- connect-button/publish.gradle | 5 -- connect-button/src/main/AndroidManifest.xml | 3 +- .../ifttt/connect/ui/CheckMarkDrawable.java | 4 +- connect-button/src/test/AndroidManifest.xml | 3 +- .../connect/ui/BaseConnectButtonTest.java | 43 +++++++++----- .../ifttt/connect/ui/ConnectButtonTest.java | 21 ++++++- .../ifttt/connect/ui/DisableTrackingTest.java | 27 ++++++--- .../ifttt/connect/ui/LocalizationTest.java | 22 +++++-- .../ifttt/connect/ui/QueueOperationsTest.java | 18 ++++-- connect-location/README.md | 6 +- connect-location/build.gradle | 2 +- connect-location/publish.gradle | 5 -- connect-location/src/main/AndroidManifest.xml | 3 +- connect-location/src/test/AndroidManifest.xml | 3 +- .../location/CacheUserTokenProviderTest.java | 12 ++-- .../ifttt/location/ConnectLocationTest.java | 27 +++++---- .../location/ConnectionRefresherTest.java | 17 +++--- .../location/LocationEventHelperTest.java | 32 +++++----- gradle/wrapper/gradle-wrapper.properties | 2 +- 34 files changed, 303 insertions(+), 176 deletions(-) create mode 100644 connect-api/src/main/java/com/ifttt/connect/api/CheckBoxFieldValue.java create mode 100644 connect-api/src/main/java/com/ifttt/connect/api/CheckBoxValue.java delete mode 100644 connect-api/src/main/java/com/ifttt/connect/api/StringArrayFieldValue.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f5bcd2d..aa6e3b9a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ on: [push] jobs: test: name: Run unit tests - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: Setup JDK 11 diff --git a/README.md b/README.md index 790dbcde..910f2015 100755 --- a/README.md +++ b/README.md @@ -42,9 +42,9 @@ This SDK uses the following libraries as dependencies: ### Gradle ```groovy // Required for Connect API integration. -implementation "com.ifttt:connect-api:2.5.3" +implementation "com.ifttt:connect-api:2.5.4" // Connect Button UI. -implementation "com.ifttt:connect-button:2.5.3" +implementation "com.ifttt:connect-button:2.5.4" ``` ## Usage diff --git a/app/build.gradle b/app/build.gradle index 164fc192..d9792842 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,7 +3,6 @@ apply plugin: 'kotlin-android' android { compileSdkVersion rootProject.compileSdkVersion - buildToolsVersion rootProject.buildToolsVersion defaultConfig { applicationId "com.ifttt.groceryexpress" @@ -24,6 +23,7 @@ android { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } + namespace 'com.ifttt.groceryexpress' } dependencies { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5085d9ad..9ff0491e 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/build.gradle b/build.gradle index 2466c246..4f35f954 100755 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,12 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.6.21' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.0.4' + classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong @@ -34,7 +34,7 @@ task clean(type: Delete) { ext { libVersion = '2.5.3' - okHttpVersion = '4.9.0' + okHttpVersion = '4.10.0' retrofitVersion = '2.9.0' moshiVersion = '1.8.0' workManagerVersion = '2.7.1' diff --git a/connect-api/build.gradle b/connect-api/build.gradle index bb12affa..75b2df61 100644 --- a/connect-api/build.gradle +++ b/connect-api/build.gradle @@ -2,7 +2,6 @@ apply plugin: 'com.android.library' android { compileSdkVersion rootProject.compileSdkVersion - buildToolsVersion rootProject.buildToolsVersion defaultConfig { minSdkVersion rootProject.minSdkVersion @@ -22,6 +21,7 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + namespace 'com.ifttt.connect.api' } dependencies { diff --git a/connect-api/publish.gradle b/connect-api/publish.gradle index 28250223..6d7ecedb 100644 --- a/connect-api/publish.gradle +++ b/connect-api/publish.gradle @@ -77,11 +77,6 @@ afterEvaluate { name = 'Zhe Lu' email = 'zhe@ifttt.com' } - developer { - id = 'priyaashah' - name = 'Priya Shah' - email = 'priya@ifttt.com' - } } scm { connection = gitUrl diff --git a/connect-api/src/main/AndroidManifest.xml b/connect-api/src/main/AndroidManifest.xml index bdfe8972..94cbbcfc 100644 --- a/connect-api/src/main/AndroidManifest.xml +++ b/connect-api/src/main/AndroidManifest.xml @@ -1,2 +1 @@ - + diff --git a/connect-api/src/main/java/com/ifttt/connect/api/CheckBoxFieldValue.java b/connect-api/src/main/java/com/ifttt/connect/api/CheckBoxFieldValue.java new file mode 100644 index 00000000..bffe56ba --- /dev/null +++ b/connect-api/src/main/java/com/ifttt/connect/api/CheckBoxFieldValue.java @@ -0,0 +1,58 @@ +package com.ifttt.connect.api; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.List; +import java.util.Objects; + +/** + * Data structure representing the checkbox field values. + */ +public final class CheckBoxFieldValue implements Parcelable { + + public final List value; + + public CheckBoxFieldValue(List value) { + this.value = value; + } + + protected CheckBoxFieldValue(Parcel in) { + value = in.createTypedArrayList(CheckBoxValue.CREATOR); + } + + public static final Creator CREATOR = new Creator() { + @Override + public CheckBoxFieldValue createFromParcel(Parcel in) { + return new CheckBoxFieldValue(in); + } + + @Override + public CheckBoxFieldValue[] newArray(int size) { + return new CheckBoxFieldValue[size]; + } + }; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CheckBoxFieldValue that = (CheckBoxFieldValue) o; + return Objects.equals(value, that.value); + } + + @Override + public int hashCode() { + return Objects.hash(value); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeTypedList(value); + } +} diff --git a/connect-api/src/main/java/com/ifttt/connect/api/CheckBoxValue.java b/connect-api/src/main/java/com/ifttt/connect/api/CheckBoxValue.java new file mode 100644 index 00000000..cb2a6d8c --- /dev/null +++ b/connect-api/src/main/java/com/ifttt/connect/api/CheckBoxValue.java @@ -0,0 +1,57 @@ +package com.ifttt.connect.api; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.Objects; + +public final class CheckBoxValue implements Parcelable { + public final String label; + public final String value; + + public CheckBoxValue(String label, String value) { + this.label = label; + this.value = value; + } + + protected CheckBoxValue(Parcel in) { + label = in.readString(); + value = in.readString(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public CheckBoxValue createFromParcel(Parcel in) { + return new CheckBoxValue(in); + } + + @Override + public CheckBoxValue[] newArray(int size) { + return new CheckBoxValue[size]; + } + }; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CheckBoxValue that = (CheckBoxValue) o; + return Objects.equals(label, that.label) && Objects.equals(value, that.value); + } + + @Override + public int hashCode() { + return Objects.hash(label, value); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(label); + dest.writeString(value); + } + } diff --git a/connect-api/src/main/java/com/ifttt/connect/api/ConnectionJsonAdapter.java b/connect-api/src/main/java/com/ifttt/connect/api/ConnectionJsonAdapter.java index a660bd54..14f12240 100755 --- a/connect-api/src/main/java/com/ifttt/connect/api/ConnectionJsonAdapter.java +++ b/connect-api/src/main/java/com/ifttt/connect/api/ConnectionJsonAdapter.java @@ -5,6 +5,7 @@ import com.squareup.moshi.JsonReader; import com.squareup.moshi.JsonWriter; import com.squareup.moshi.ToJson; + import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -13,6 +14,7 @@ import java.util.List; import java.util.Map; import java.util.Set; + import javax.annotation.Nullable; /** @@ -51,7 +53,7 @@ Connection fromJson( JsonAdapter coverImageDelegate, JsonAdapter> servicesDelegate, JsonAdapter collectionFieldDelegate, - JsonAdapter> stringListDelegate + JsonAdapter> checkBoxValueDelegate ) throws IOException { String id = null; String name = null; @@ -100,7 +102,7 @@ Connection fromJson( checkNonNull(featureJsonList); userFeatureGroup = fromJsonToUserFeature(jsonReader, locationDelegate, - stringListDelegate, + checkBoxValueDelegate, collectionFieldDelegate ); break; @@ -136,7 +138,7 @@ void toJson(JsonWriter jsonWriter, Connection connection) { private Map> fromJsonToUserFeature( JsonReader jsonReader, JsonAdapter locationDelegate, - JsonAdapter> stringListDelegate, + JsonAdapter> checkBoxValueDelegate, JsonAdapter collectionFieldDelegate ) throws IOException { ArrayList userFeatures = new ArrayList<>(); @@ -175,7 +177,7 @@ private Map> fromJsonToUserFeature( triggerOptions, locationDelegate, collectionFieldDelegate, - stringListDelegate, + checkBoxValueDelegate, steps ); break; @@ -186,7 +188,7 @@ private Map> fromJsonToUserFeature( queryOptions, locationDelegate, collectionFieldDelegate, - stringListDelegate, + checkBoxValueDelegate, steps ); break; @@ -197,7 +199,7 @@ private Map> fromJsonToUserFeature( actionOptions, locationDelegate, collectionFieldDelegate, - stringListDelegate, + checkBoxValueDelegate, steps ); break; @@ -233,7 +235,7 @@ private void parseUserSteps( JsonReader.Options options, JsonAdapter locationDelegate, JsonAdapter collectionFieldDelegate, - JsonAdapter> stringArrayDelegate, + JsonAdapter> checkboxFieldDelegate, List steps ) throws IOException { jsonReader.beginArray(); @@ -286,12 +288,12 @@ private void parseUserSteps( fieldId )); } else if (FIELD_TYPE_CHECKBOX.equals(fieldType)) { - List arrayValue = stringArrayDelegate.fromJson(jsonReader); - checkNonNull(arrayValue); + List checkBoxFieldValue = + checkboxFieldDelegate.fromJson(jsonReader); + checkNonNull(checkBoxFieldValue); - StringArrayFieldValue stringArrayFieldValue = new StringArrayFieldValue( - arrayValue); - fields.add(new UserFeatureField<>(stringArrayFieldValue, + fields.add(new UserFeatureField<>( + new CheckBoxFieldValue(checkBoxFieldValue), fieldType, fieldId )); diff --git a/connect-api/src/main/java/com/ifttt/connect/api/StringArrayFieldValue.java b/connect-api/src/main/java/com/ifttt/connect/api/StringArrayFieldValue.java deleted file mode 100644 index b5657bf0..00000000 --- a/connect-api/src/main/java/com/ifttt/connect/api/StringArrayFieldValue.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.ifttt.connect.api; - -import android.os.Parcel; -import android.os.Parcelable; -import java.util.List; - -/** - * Data structure representing the checkbox field values. - */ -public final class StringArrayFieldValue implements Parcelable { - public final List value; - - public StringArrayFieldValue(List value) { - this.value = value; - } - - protected StringArrayFieldValue(Parcel in) { - value = in.createStringArrayList(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeStringList(value); - } - - @Override - public int describeContents() { - return 0; - } - - public static final Creator CREATOR = new Creator() { - @Override - public StringArrayFieldValue createFromParcel(Parcel in) { - return new StringArrayFieldValue(in); - } - - @Override - public StringArrayFieldValue[] newArray(int size) { - return new StringArrayFieldValue[size]; - } - }; -} diff --git a/connect-api/src/main/java/com/ifttt/connect/api/UserFeatureField.java b/connect-api/src/main/java/com/ifttt/connect/api/UserFeatureField.java index 9d5ccc40..ab6edcf0 100644 --- a/connect-api/src/main/java/com/ifttt/connect/api/UserFeatureField.java +++ b/connect-api/src/main/java/com/ifttt/connect/api/UserFeatureField.java @@ -7,7 +7,7 @@ * Data structure representing one configuration field for a {@link UserFeature}. Currently, the supported value types * are * - {@link CollectionFieldValue} - * - {@link StringArrayFieldValue} + * - {@link CheckBoxFieldValue} * - {@link LocationFieldValue} * - {@link StringFieldValue} */ diff --git a/connect-api/src/test/java/com/ifttt/connect/api/ConnectionApiClientTest.java b/connect-api/src/test/java/com/ifttt/connect/api/ConnectionApiClientTest.java index f0e67cbc..3c398b14 100644 --- a/connect-api/src/test/java/com/ifttt/connect/api/ConnectionApiClientTest.java +++ b/connect-api/src/test/java/com/ifttt/connect/api/ConnectionApiClientTest.java @@ -1,20 +1,22 @@ package com.ifttt.connect.api; +import static com.google.common.truth.Truth.assertThat; + import android.content.Context; + +import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.platform.app.InstrumentationRegistry; + import org.junit.Test; import org.junit.runner.RunWith; -import static com.google.common.truth.Truth.assertThat; - @RunWith(AndroidJUnit4.class) public final class ConnectionApiClientTest { @Test public void newBuilderShouldOverrideUserTokenProvider() { UserTokenProvider oldProvider = () -> null; - Context context = InstrumentationRegistry.getInstrumentation().getContext(); + Context context = ApplicationProvider.getApplicationContext(); ConnectionApiClient client = new ConnectionApiClient.Builder(context, oldProvider).build(); UserTokenProvider newProvider = () -> "token"; diff --git a/connect-button/build.gradle b/connect-button/build.gradle index c450d1d6..58336a87 100755 --- a/connect-button/build.gradle +++ b/connect-button/build.gradle @@ -2,7 +2,6 @@ apply plugin: 'com.android.library' android { compileSdkVersion rootProject.compileSdkVersion - buildToolsVersion rootProject.buildToolsVersion defaultConfig { minSdkVersion rootProject.minSdkVersion @@ -22,6 +21,7 @@ android { } testOptions.unitTests.includeAndroidResources = true + namespace 'com.ifttt.connect' } dependencies { diff --git a/connect-button/publish.gradle b/connect-button/publish.gradle index 6375c068..7560fd72 100644 --- a/connect-button/publish.gradle +++ b/connect-button/publish.gradle @@ -79,11 +79,6 @@ afterEvaluate { name = 'Zhe Lu' email = 'zhe@ifttt.com' } - developer { - id = 'priyaashah' - name = 'Priya Shah' - email = 'priya@ifttt.com' - } } scm { connection = gitUrl diff --git a/connect-button/src/main/AndroidManifest.xml b/connect-button/src/main/AndroidManifest.xml index bf568096..d569a4bf 100755 --- a/connect-button/src/main/AndroidManifest.xml +++ b/connect-button/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/connect-button/src/main/java/com/ifttt/connect/ui/CheckMarkDrawable.java b/connect-button/src/main/java/com/ifttt/connect/ui/CheckMarkDrawable.java index 4b08cac4..1d204559 100644 --- a/connect-button/src/main/java/com/ifttt/connect/ui/CheckMarkDrawable.java +++ b/connect-button/src/main/java/com/ifttt/connect/ui/CheckMarkDrawable.java @@ -40,8 +40,8 @@ enum AnimatorType { private final Path dotPath = new Path(); private final Path checkMarkPath = new Path(); - private PathMeasure circlePathMeasure; - private PathMeasure checkMarkPathMeasure; + private PathMeasure circlePathMeasure = new PathMeasure(dotPath, false); + private PathMeasure checkMarkPathMeasure = new PathMeasure(checkMarkPath, false); private boolean drawCheckMark = false; private float scale = 0f; diff --git a/connect-button/src/test/AndroidManifest.xml b/connect-button/src/test/AndroidManifest.xml index f3f63808..235f9f94 100755 --- a/connect-button/src/test/AndroidManifest.xml +++ b/connect-button/src/test/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/connect-button/src/test/java/com/ifttt/connect/ui/BaseConnectButtonTest.java b/connect-button/src/test/java/com/ifttt/connect/ui/BaseConnectButtonTest.java index 848484a6..4ff5ae2b 100644 --- a/connect-button/src/test/java/com/ifttt/connect/ui/BaseConnectButtonTest.java +++ b/connect-button/src/test/java/com/ifttt/connect/ui/BaseConnectButtonTest.java @@ -1,34 +1,40 @@ package com.ifttt.connect.ui; +import static com.google.common.truth.Truth.assertThat; +import static com.ifttt.connect.api.TestUtils.loadConnection; +import static org.junit.Assert.fail; + import android.net.Uri; import android.os.Looper; import android.widget.ImageView; import android.widget.TextSwitcher; import android.widget.TextView; + import androidx.core.content.ContextCompat; -import androidx.test.core.app.ActivityScenario; import androidx.test.ext.junit.runners.AndroidJUnit4; + import com.ifttt.connect.R; import com.ifttt.connect.api.Connection; import com.ifttt.connect.api.ConnectionApiClient; import com.ifttt.connect.api.ErrorResponse; import com.ifttt.connect.api.TestUtils; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.atomic.AtomicReference; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okio.Okio; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.Robolectric; import org.robolectric.Shadows; +import org.robolectric.android.controller.ActivityController; import org.robolectric.annotation.Config; import org.robolectric.annotation.LooperMode; -import static com.google.common.truth.Truth.assertThat; -import static com.ifttt.connect.api.TestUtils.loadConnection; -import static org.junit.Assert.fail; +import java.io.IOException; +import java.io.InputStream; +import java.util.concurrent.atomic.AtomicReference; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okio.Okio; @RunWith(AndroidJUnit4.class) @LooperMode(LooperMode.Mode.PAUSED) @@ -41,11 +47,11 @@ public final class BaseConnectButtonTest { @Before public void setUp() { - ActivityScenario scenario = ActivityScenario.launch(TestActivity.class); - scenario.onActivity(activity -> { - button = activity.findViewById(R.id.ifttt_connect_button_test); - client = new ConnectionApiClient.Builder(activity, () -> null).build(); - }); + ActivityController activity = Robolectric.buildActivity(TestActivity.class); + activity.get().setTheme(R.style.Base_Theme_AppCompat); + activity.create().start().resume(); + button = activity.get().findViewById(R.id.ifttt_connect_button_test); + client = new ConnectionApiClient.Builder(activity.get(), () -> null).build(); credentialsProvider = new CredentialsProvider() { @Override @@ -185,7 +191,12 @@ public void onError(ErrorResponse errorResponse) { }); button.setConnectResult(new ConnectResult(ConnectResult.NextStep.Complete, "token", null)); - Shadows.shadowOf(Looper.getMainLooper()).idle(); + try { + Shadows.shadowOf(Looper.getMainLooper()).idle(); + Thread.sleep(1000L); + } catch (InterruptedException e) { + // Ignore. + } assertThat(currentStateRef.get()).isEqualTo(ConnectButtonState.Enabled); assertThat(prevStateRef.get()).isEqualTo(ConnectButtonState.Initial); diff --git a/connect-button/src/test/java/com/ifttt/connect/ui/ConnectButtonTest.java b/connect-button/src/test/java/com/ifttt/connect/ui/ConnectButtonTest.java index 241489f8..977deca1 100644 --- a/connect-button/src/test/java/com/ifttt/connect/ui/ConnectButtonTest.java +++ b/connect-button/src/test/java/com/ifttt/connect/ui/ConnectButtonTest.java @@ -1,21 +1,36 @@ package com.ifttt.connect.ui; +import static com.google.common.truth.Truth.assertThat; + import android.app.Activity; import android.net.Uri; import android.view.View; + import androidx.test.ext.junit.runners.AndroidJUnit4; + +import com.ifttt.connect.R; + +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.android.controller.ActivityController; import org.robolectric.annotation.Config; -import static com.google.common.truth.Truth.assertThat; - @RunWith(AndroidJUnit4.class) @Config(sdk = 28) public final class ConnectButtonTest { - private final Activity activity = Robolectric.buildActivity(TestActivity.class).create().get(); + private Activity activity; + + @Before + public void setUp() { + ActivityController controller = Robolectric.buildActivity(TestActivity.class); + controller.get().setTheme(R.style.Base_Theme_AppCompat); + controller.create().start(); + + activity = controller.get(); + } @Test public void shouldHideUiWithInvalidEmail() { diff --git a/connect-button/src/test/java/com/ifttt/connect/ui/DisableTrackingTest.java b/connect-button/src/test/java/com/ifttt/connect/ui/DisableTrackingTest.java index be0b232e..05ea3ba4 100644 --- a/connect-button/src/test/java/com/ifttt/connect/ui/DisableTrackingTest.java +++ b/connect-button/src/test/java/com/ifttt/connect/ui/DisableTrackingTest.java @@ -1,29 +1,40 @@ package com.ifttt.connect.ui; -import android.app.Activity; +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; + +import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.work.Configuration; +import androidx.work.testing.SynchronousExecutor; +import androidx.work.testing.WorkManagerTestInitHelper; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.Robolectric; -import org.robolectric.annotation.Config; - -import static com.google.common.truth.Truth.assertThat; +import org.robolectric.annotation.LooperMode; @RunWith(AndroidJUnit4.class) -@Config(sdk = 28) +@LooperMode(LooperMode.Mode.PAUSED) public final class DisableTrackingTest { - private final Activity activity = Robolectric.buildActivity(TestActivity.class).create().get(); private AnalyticsManager analyticsManager; @Before public void setup() { - analyticsManager = AnalyticsManager.getInstance(activity); + Context context = ApplicationProvider.getApplicationContext(); + Configuration config = new Configuration.Builder() + .setExecutor(new SynchronousExecutor()) + .build(); + WorkManagerTestInitHelper.initializeTestWorkManager(context, config); + + analyticsManager = AnalyticsManager.getInstance(context); } @Test public void testAnalyticsDisabled() { + analyticsManager.clearQueue(); assertThat(analyticsManager.performRead().size()).isEqualTo(0); analyticsManager.disableTracking(); diff --git a/connect-button/src/test/java/com/ifttt/connect/ui/LocalizationTest.java b/connect-button/src/test/java/com/ifttt/connect/ui/LocalizationTest.java index 18ea7f11..4de5b9b9 100644 --- a/connect-button/src/test/java/com/ifttt/connect/ui/LocalizationTest.java +++ b/connect-button/src/test/java/com/ifttt/connect/ui/LocalizationTest.java @@ -1,24 +1,38 @@ package com.ifttt.connect.ui; +import static com.google.common.truth.Truth.assertThat; + import android.app.Activity; import android.content.Context; import android.content.res.Configuration; + import androidx.test.ext.junit.runners.AndroidJUnit4; + import com.ifttt.connect.R; -import java.util.Locale; + +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.android.controller.ActivityController; import org.robolectric.annotation.Config; -import org.robolectric.annotation.LooperMode; -import static com.google.common.truth.Truth.assertThat; +import java.util.Locale; @RunWith(AndroidJUnit4.class) @Config(sdk = 28) public final class LocalizationTest { - private final Activity activity = Robolectric.buildActivity(TestActivity.class).create().get(); + private Activity activity; + + @Before + public void setUp() { + ActivityController controller = Robolectric.buildActivity(TestActivity.class); + controller.get().setTheme(R.style.Base_Theme_AppCompat); + controller.create().start(); + + activity = controller.get(); + } @Test public void testNonSupportedLocale() { diff --git a/connect-button/src/test/java/com/ifttt/connect/ui/QueueOperationsTest.java b/connect-button/src/test/java/com/ifttt/connect/ui/QueueOperationsTest.java index ad7701ef..9c381f9b 100644 --- a/connect-button/src/test/java/com/ifttt/connect/ui/QueueOperationsTest.java +++ b/connect-button/src/test/java/com/ifttt/connect/ui/QueueOperationsTest.java @@ -1,26 +1,32 @@ package com.ifttt.connect.ui; -import android.app.Activity; +import static com.google.common.truth.Truth.assertThat; + import androidx.test.ext.junit.runners.AndroidJUnit4; -import java.util.HashMap; + +import com.ifttt.connect.R; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.android.controller.ActivityController; import org.robolectric.annotation.Config; -import static com.google.common.truth.Truth.assertThat; +import java.util.HashMap; @RunWith(AndroidJUnit4.class) @Config(sdk = 28) public final class QueueOperationsTest { - - private final Activity activity = Robolectric.buildActivity(TestActivity.class).create().get(); private AnalyticsManager analyticsManager; @Before public void setup() { - analyticsManager = AnalyticsManager.getInstance(activity); + ActivityController controller = Robolectric.buildActivity(TestActivity.class); + controller.get().setTheme(R.style.Base_Theme_AppCompat); + controller.create().start(); + + analyticsManager = AnalyticsManager.getInstance(controller.get()); analyticsManager.clearQueue(); } diff --git a/connect-location/README.md b/connect-location/README.md index 01ebdad9..a6b1b091 100644 --- a/connect-location/README.md +++ b/connect-location/README.md @@ -23,13 +23,13 @@ IFTTT Connect Location SDK is an add-on library to the [ConnectButton SDK](https ### Gradle ```groovy // Required for Connect API integration. -implementation "com.ifttt:connect-api:2.5.3" +implementation "com.ifttt:connect-api:2.5.4" // Required for Connect Button UI integration. -implementation "com.ifttt:connect-button:2.5.3" +implementation "com.ifttt:connect-button:2.5.4" // Location service integration. -implementation "com.ifttt.connect-location:2.5.3" +implementation "com.ifttt.connect-location:2.5.4" ``` ## Usage diff --git a/connect-location/build.gradle b/connect-location/build.gradle index 888135aa..6279f43e 100644 --- a/connect-location/build.gradle +++ b/connect-location/build.gradle @@ -2,7 +2,6 @@ apply plugin: 'com.android.library' android { compileSdkVersion rootProject.compileSdkVersion - buildToolsVersion rootProject.buildToolsVersion defaultConfig { minSdkVersion rootProject.minSdkVersion @@ -22,6 +21,7 @@ android { } testOptions.unitTests.includeAndroidResources = true + namespace 'com.ifttt.location' } dependencies { diff --git a/connect-location/publish.gradle b/connect-location/publish.gradle index 0e5bb1a7..903c2562 100644 --- a/connect-location/publish.gradle +++ b/connect-location/publish.gradle @@ -83,11 +83,6 @@ afterEvaluate { name = 'Zhe Lu' email = 'zhe@ifttt.com' } - developer { - id = 'priyaashah' - name = 'Priya Shah' - email = 'priya@ifttt.com' - } } scm { connection = gitUrl diff --git a/connect-location/src/main/AndroidManifest.xml b/connect-location/src/main/AndroidManifest.xml index 729b93c6..9c6d7df7 100644 --- a/connect-location/src/main/AndroidManifest.xml +++ b/connect-location/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/connect-location/src/test/AndroidManifest.xml b/connect-location/src/test/AndroidManifest.xml index 00cb4521..5a6c086a 100755 --- a/connect-location/src/test/AndroidManifest.xml +++ b/connect-location/src/test/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/connect-location/src/test/java/com/ifttt/location/CacheUserTokenProviderTest.java b/connect-location/src/test/java/com/ifttt/location/CacheUserTokenProviderTest.java index 3e8efb73..040a5fcf 100644 --- a/connect-location/src/test/java/com/ifttt/location/CacheUserTokenProviderTest.java +++ b/connect-location/src/test/java/com/ifttt/location/CacheUserTokenProviderTest.java @@ -1,22 +1,24 @@ package com.ifttt.location; +import static com.google.common.truth.Truth.assertThat; + import android.content.Context; + +import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.platform.app.InstrumentationRegistry; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import static com.google.common.truth.Truth.assertThat; - @RunWith(AndroidJUnit4.class) public final class CacheUserTokenProviderTest { private Context context; @Before - public void setUp() throws Exception { - context = InstrumentationRegistry.getInstrumentation().getContext(); + public void setUp() { + context = ApplicationProvider.getApplicationContext(); } @Test diff --git a/connect-location/src/test/java/com/ifttt/location/ConnectLocationTest.java b/connect-location/src/test/java/com/ifttt/location/ConnectLocationTest.java index b2b3b225..688f8b3a 100644 --- a/connect-location/src/test/java/com/ifttt/location/ConnectLocationTest.java +++ b/connect-location/src/test/java/com/ifttt/location/ConnectLocationTest.java @@ -1,14 +1,19 @@ package com.ifttt.location; +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.fail; +import static org.robolectric.Shadows.shadowOf; + import android.Manifest; import android.app.Application; import android.content.Context; import android.graphics.Color; import android.net.Uri; + import androidx.annotation.Nullable; -import androidx.test.core.app.ActivityScenario; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; + import com.ifttt.connect.api.Connection; import com.ifttt.connect.api.ConnectionApiClient; import com.ifttt.connect.api.Feature; @@ -21,18 +26,18 @@ import com.ifttt.connect.api.UserFeatureStep; import com.ifttt.connect.ui.ConnectButton; import com.ifttt.connect.ui.CredentialsProvider; -import java.util.Collections; -import java.util.concurrent.atomic.AtomicBoolean; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.android.controller.ActivityController; import org.robolectric.annotation.Config; import org.robolectric.annotation.LooperMode; import org.robolectric.shadows.ShadowApplication; -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.fail; -import static org.robolectric.Shadows.shadowOf; +import java.util.Collections; +import java.util.concurrent.atomic.AtomicBoolean; @RunWith(AndroidJUnit4.class) @LooperMode(LooperMode.Mode.PAUSED) @@ -74,10 +79,10 @@ public class ConnectLocationTest { @Before public void setUp() { - ActivityScenario scenario = ActivityScenario.launch(TestActivity.class); - scenario.onActivity(activity -> { - button = new ConnectButton(activity); - }); + ActivityController activity = Robolectric.buildActivity(TestActivity.class); + activity.get().setTheme(R.style.Base_Theme_AppCompat); + activity.create().start().resume(); + button = new ConnectButton(activity.get()); CredentialsProvider credentialsProvider = new CredentialsProvider() { @Override @@ -90,7 +95,7 @@ public String getUserToken() { return null; } }; - apiClient = new ConnectionApiClient.Builder(button.getContext(), credentialsProvider).build(); + apiClient = new ConnectionApiClient.Builder(activity.get(), credentialsProvider).build(); } @Test(expected = IllegalStateException.class) diff --git a/connect-location/src/test/java/com/ifttt/location/ConnectionRefresherTest.java b/connect-location/src/test/java/com/ifttt/location/ConnectionRefresherTest.java index c22a73c7..6262dc40 100644 --- a/connect-location/src/test/java/com/ifttt/location/ConnectionRefresherTest.java +++ b/connect-location/src/test/java/com/ifttt/location/ConnectionRefresherTest.java @@ -1,23 +1,26 @@ package com.ifttt.location; +import static com.google.common.truth.Truth.assertThat; + import android.content.Context; import android.util.Log; + +import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.platform.app.InstrumentationRegistry; import androidx.work.Configuration; import androidx.work.WorkInfo; import androidx.work.WorkManager; import androidx.work.testing.SynchronousExecutor; import androidx.work.testing.WorkManagerTestInitHelper; -import java.util.Collections; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.ExecutionException; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import static com.google.common.truth.Truth.assertThat; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ExecutionException; @RunWith(AndroidJUnit4.class) public final class ConnectionRefresherTest { @@ -26,7 +29,7 @@ public final class ConnectionRefresherTest { @Before public void setUp() throws Exception { - context = InstrumentationRegistry.getInstrumentation().getContext(); + context = ApplicationProvider.getApplicationContext(); Configuration config = new Configuration.Builder().setMinimumLoggingLevel(Log.DEBUG) .setExecutor(new SynchronousExecutor()) .build(); diff --git a/connect-location/src/test/java/com/ifttt/location/LocationEventHelperTest.java b/connect-location/src/test/java/com/ifttt/location/LocationEventHelperTest.java index 33c52118..46fa4a23 100644 --- a/connect-location/src/test/java/com/ifttt/location/LocationEventHelperTest.java +++ b/connect-location/src/test/java/com/ifttt/location/LocationEventHelperTest.java @@ -1,18 +1,5 @@ package com.ifttt.location; -import android.content.Context; -import androidx.annotation.Nullable; -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.platform.app.InstrumentationRegistry; -import com.ifttt.connect.api.Connection; -import com.ifttt.connect.api.ConnectionApiClient; -import com.ifttt.connect.api.UserTokenProvider; -import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - import static com.google.common.truth.Truth.assertThat; import static com.ifttt.location.LocationEventAttributes.LOCATION_EVENT_DELAY_TO_COMPLETE; import static com.ifttt.location.LocationEventAttributes.LOCATION_EVENT_DELAY_TO_UPLOAD; @@ -24,6 +11,23 @@ import static com.ifttt.location.LocationEventAttributes.LocationDataSource.Awareness; import static com.ifttt.location.LocationEventUploader.EventType.Entry; +import android.content.Context; + +import androidx.annotation.Nullable; +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import com.ifttt.connect.api.Connection; +import com.ifttt.connect.api.ConnectionApiClient; +import com.ifttt.connect.api.UserTokenProvider; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + @RunWith(AndroidJUnit4.class) public class LocationEventHelperTest { @@ -31,7 +35,7 @@ public class LocationEventHelperTest { @Before public void setUp() { - Context context = InstrumentationRegistry.getInstrumentation().getContext(); + Context context = ApplicationProvider.getApplicationContext(); connectLocation = new ConnectLocation(new GeofenceProvider() { @Override public void updateGeofences( diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5e03c964..1a7fbcfc 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip