Skip to content

Commit 72e2035

Browse files
authored
Merge pull request #903 from Iterable/contributions/robolectric-fixes
Contributions/robolectric fixes
2 parents 45245fe + c7dec96 commit 72e2035

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This SDK helps you integrate your Android apps with Iterable.
1515

1616
## Supported Android versions
1717

18-
Iterable's Android SDK supports Android versions 4.1.2 (API level 16) and higher.
18+
Iterable's Android SDK supports Android versions 5.0 (API level 21) and higher.
1919

2020
## Installation
2121

@@ -66,7 +66,7 @@ Questions? Contact your Iterable customer success manager.
6666

6767
## License
6868

69-
This SDK is released under the MIT License. For more information, read [LICENSE](LICENSE.md).
69+
This SDK is released under the MIT License. For more information, read [LICENSE](LICENSE).
7070

7171
## Want to contribute?
7272

app/build.gradle

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ dependencies {
6161
testImplementation 'androidx.test:rules:1.6.1'
6262
testImplementation 'org.mockito:mockito-core:4.8.0'
6363
testImplementation 'org.robolectric:robolectric:4.14.1'
64-
testImplementation 'org.robolectric:shadows-playservices:4.14.1'
6564
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.3'
6665
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
6766
androidTestImplementation 'androidx.test:runner:1.6.2'
@@ -167,4 +166,4 @@ task jacocoDebugAndroidTestReport(type: JacocoReport, dependsOn: ['connectedChec
167166
additionalSourceDirs.from = files([sdkSrc, sdkUiSrc])
168167
additionalClassDirs.from = files([sdkTree, sdkUiTree])
169168
executionData.from = fileTree(dir: "$buildDir", include: "outputs/code_coverage/debugAndroidTest/connected/**/*.ec")
170-
}
169+
}

iterableapi/build.gradle

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ dependencies {
7171
testImplementation 'org.mockito:mockito-core:4.8.0'
7272
testImplementation 'org.mockito:mockito-inline:4.8.0'
7373
testImplementation 'org.robolectric:robolectric:4.14.1'
74-
testImplementation 'org.robolectric:shadows-playservices:4.14.1'
7574
testImplementation 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
7675
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.3'
7776
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
@@ -118,4 +117,4 @@ afterEvaluate {
118117
javadoc.classpath += files(android.libraryVariants.collect { variant -> variant.javaCompile.classpath.files })
119118
javadoc.classpath += files(android.libraryVariants.collect { variant -> "build/generated/source/r/${variant.flavorName}/${variant.buildType.name}" })
120119
javadoc.classpath += files(android.libraryVariants.collect { variant -> "build/generated/source/buildConfig/${variant.flavorName}/${variant.buildType.name}" })
121-
}
120+
}

iterableapi/src/test/java/com/iterable/iterableapi/IterablePushActionReceiverTest.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package com.iterable.iterableapi;
22

3+
import android.app.Application;
34
import android.content.ClipData;
45
import android.content.Context;
56
import android.content.Intent;
67
import android.os.Bundle;
78
import androidx.core.app.RemoteInput;
9+
import androidx.test.core.app.ApplicationProvider;
810

911
import org.json.JSONObject;
1012
import org.junit.After;
1113
import org.junit.Before;
1214
import org.junit.Test;
1315
import org.mockito.ArgumentCaptor;
14-
import org.robolectric.RuntimeEnvironment;
1516

1617
import java.util.concurrent.TimeUnit;
1718

@@ -63,11 +64,12 @@ public void testPushOpenWithNonInitializedSDK() throws Exception {
6364
intent.putExtra(IterableConstants.ITERABLE_DATA_KEY, IterableTestUtils.getResourceString("push_payload_silent_action.json"));
6465

6566
// This must not crash
66-
iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent);
67+
iterablePushActionReceiver.onReceive(ApplicationProvider.getApplicationContext(), intent);
6768
}
6869

6970
@Test
7071
public void testTrackPushOpenWithCustomAction() throws Exception {
72+
Application application = ApplicationProvider.getApplicationContext();
7173
final JSONObject responseData = new JSONObject("{\"key\":\"value\"}");
7274
stubAnyRequestReturningStatusCode(server, 200, responseData);
7375

@@ -76,15 +78,15 @@ public void testTrackPushOpenWithCustomAction() throws Exception {
7678
intent.putExtra(IterableConstants.ITERABLE_DATA_ACTION_IDENTIFIER, IterableConstants.ITERABLE_ACTION_DEFAULT);
7779
intent.putExtra(IterableConstants.ITERABLE_DATA_KEY, IterableTestUtils.getResourceString("push_payload_custom_action.json"));
7880

79-
iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent);
81+
iterablePushActionReceiver.onReceive(application, intent);
8082

8183
// Verify that IterableActionRunner was called with the proper action
8284
ArgumentCaptor<IterableAction> capturedAction = ArgumentCaptor.forClass(IterableAction.class);
8385
verify(actionRunnerMock).executeAction(any(Context.class), capturedAction.capture(), eq(IterableActionSource.PUSH));
8486
assertEquals("customAction", capturedAction.getValue().getType());
8587

8688
// Verify that the main app activity was launched
87-
Intent activityIntent = shadowOf(RuntimeEnvironment.application).peekNextStartedActivity();
89+
Intent activityIntent = shadowOf(application).peekNextStartedActivity();
8890
assertNotNull(activityIntent);
8991
assertEquals(Intent.ACTION_MAIN, activityIntent.getAction());
9092

@@ -102,16 +104,17 @@ public void testTrackPushOpenWithCustomAction() throws Exception {
102104

103105
@Test
104106
public void testPushActionWithSilentAction() throws Exception {
107+
Application application = ApplicationProvider.getApplicationContext();
105108
stubAnyRequestReturningStatusCode(server, 200, "{}");
106109
IterablePushActionReceiver iterablePushActionReceiver = new IterablePushActionReceiver();
107110
Intent intent = new Intent(IterableConstants.ACTION_PUSH_ACTION);
108111
intent.putExtra(IterableConstants.ITERABLE_DATA_ACTION_IDENTIFIER, "silentButton");
109112
intent.putExtra(IterableConstants.ITERABLE_DATA_KEY, IterableTestUtils.getResourceString("push_payload_silent_action.json"));
110113

111-
iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent);
114+
iterablePushActionReceiver.onReceive(application, intent);
112115

113116
// Verify that the main app activity was NOT launched
114-
Intent activityIntent = shadowOf(RuntimeEnvironment.application).peekNextStartedActivity();
117+
Intent activityIntent = shadowOf(application).peekNextStartedActivity();
115118
assertNull(activityIntent);
116119
}
117120

@@ -129,7 +132,7 @@ public void testPushActionWithTextInput() throws Exception {
129132
clipDataIntent.putExtra(RemoteInput.EXTRA_RESULTS_DATA, resultsBundle);
130133
intent.setClipData(ClipData.newIntent(RESULTS_CLIP_LABEL, clipDataIntent));
131134

132-
iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent);
135+
iterablePushActionReceiver.onReceive(ApplicationProvider.getApplicationContext(), intent);
133136

134137
// Verify that IterableActionRunner was called with the proper action
135138
ArgumentCaptor<IterableAction> actionCaptor = ArgumentCaptor.forClass(IterableAction.class);
@@ -147,7 +150,7 @@ public void testLegacyDeepLinkPayload() throws Exception {
147150
intent.putExtras(IterableTestUtils.getBundleFromJsonResource("push_payload_legacy_deep_link.json"));
148151
intent.putExtra(IterableConstants.ITERABLE_DATA_ACTION_IDENTIFIER, IterableConstants.ITERABLE_ACTION_DEFAULT);
149152

150-
iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent);
153+
iterablePushActionReceiver.onReceive(ApplicationProvider.getApplicationContext(), intent);
151154

152155
// Verify that IterableActionRunner was called with openUrl action
153156
ArgumentCaptor<IterableAction> capturedAction = ArgumentCaptor.forClass(IterableAction.class);

iterableapi/src/test/java/com/iterable/iterableapi/IterableTestUtils.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import android.os.Bundle;
44

5+
import androidx.test.core.app.ApplicationProvider;
6+
57
import org.json.JSONException;
68
import org.json.JSONObject;
7-
import org.robolectric.RuntimeEnvironment;
89

910
import java.io.BufferedReader;
1011
import java.io.IOException;
@@ -48,7 +49,7 @@ public static void createIterableApiNew(ConfigBuilderExtender extender, String e
4849
builder = extender.run(builder);
4950
}
5051

51-
IterableApi.initialize(RuntimeEnvironment.application, apiKey, builder.build());
52+
IterableApi.initialize(ApplicationProvider.getApplicationContext(), apiKey, builder.build());
5253
IterableApi.getInstance().setEmail(email);
5354
}
5455

@@ -60,7 +61,7 @@ public static String getResourceString(String fileName) throws IOException {
6061
InputStream inputStream = IterableTestUtils.class.getClassLoader().getResourceAsStream(fileName);
6162
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
6263
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
63-
String receiveString = "";
64+
String receiveString;
6465
StringBuilder stringBuilder = new StringBuilder();
6566

6667
while ((receiveString = bufferedReader.readLine()) != null) {

0 commit comments

Comments
 (0)