Skip to content

Update Robolectric usage #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This SDK helps you integrate your Android apps with Iterable.

## Supported Android versions

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

## Installation

Expand Down Expand Up @@ -66,7 +66,7 @@ Questions? Contact your Iterable customer success manager.

## License

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

## Want to contribute?

Expand Down
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ dependencies {
testImplementation 'androidx.test:rules:1.6.1'
testImplementation 'org.mockito:mockito-core:4.8.0'
testImplementation 'org.robolectric:robolectric:4.14.1'
testImplementation 'org.robolectric:shadows-playservices:4.14.1'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.3'
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
androidTestImplementation 'androidx.test:runner:1.6.2'
Expand Down Expand Up @@ -167,4 +166,4 @@ task jacocoDebugAndroidTestReport(type: JacocoReport, dependsOn: ['connectedChec
additionalSourceDirs.from = files([sdkSrc, sdkUiSrc])
additionalClassDirs.from = files([sdkTree, sdkUiTree])
executionData.from = fileTree(dir: "$buildDir", include: "outputs/code_coverage/debugAndroidTest/connected/**/*.ec")
}
}
3 changes: 1 addition & 2 deletions iterableapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ dependencies {
testImplementation 'org.mockito:mockito-core:4.8.0'
testImplementation 'org.mockito:mockito-inline:4.8.0'
testImplementation 'org.robolectric:robolectric:4.14.1'
testImplementation 'org.robolectric:shadows-playservices:4.14.1'
testImplementation 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.3'
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
Expand Down Expand Up @@ -118,4 +117,4 @@ afterEvaluate {
javadoc.classpath += files(android.libraryVariants.collect { variant -> variant.javaCompile.classpath.files })
javadoc.classpath += files(android.libraryVariants.collect { variant -> "build/generated/source/r/${variant.flavorName}/${variant.buildType.name}" })
javadoc.classpath += files(android.libraryVariants.collect { variant -> "build/generated/source/buildConfig/${variant.flavorName}/${variant.buildType.name}" })
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.iterable.iterableapi;

import android.app.Application;
import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.core.app.RemoteInput;
import androidx.test.core.app.ApplicationProvider;

import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.robolectric.RuntimeEnvironment;

import java.util.concurrent.TimeUnit;

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

// This must not crash
iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent);
iterablePushActionReceiver.onReceive(ApplicationProvider.getApplicationContext(), intent);
}

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

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

iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent);
iterablePushActionReceiver.onReceive(application, intent);

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

// Verify that the main app activity was launched
Intent activityIntent = shadowOf(RuntimeEnvironment.application).peekNextStartedActivity();
Intent activityIntent = shadowOf(application).peekNextStartedActivity();
assertNotNull(activityIntent);
assertEquals(Intent.ACTION_MAIN, activityIntent.getAction());

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

@Test
public void testPushActionWithSilentAction() throws Exception {
Application application = ApplicationProvider.getApplicationContext();
stubAnyRequestReturningStatusCode(server, 200, "{}");
IterablePushActionReceiver iterablePushActionReceiver = new IterablePushActionReceiver();
Intent intent = new Intent(IterableConstants.ACTION_PUSH_ACTION);
intent.putExtra(IterableConstants.ITERABLE_DATA_ACTION_IDENTIFIER, "silentButton");
intent.putExtra(IterableConstants.ITERABLE_DATA_KEY, IterableTestUtils.getResourceString("push_payload_silent_action.json"));

iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent);
iterablePushActionReceiver.onReceive(application, intent);

// Verify that the main app activity was NOT launched
Intent activityIntent = shadowOf(RuntimeEnvironment.application).peekNextStartedActivity();
Intent activityIntent = shadowOf(application).peekNextStartedActivity();
assertNull(activityIntent);
}

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

iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent);
iterablePushActionReceiver.onReceive(ApplicationProvider.getApplicationContext(), intent);

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

iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent);
iterablePushActionReceiver.onReceive(ApplicationProvider.getApplicationContext(), intent);

// Verify that IterableActionRunner was called with openUrl action
ArgumentCaptor<IterableAction> capturedAction = ArgumentCaptor.forClass(IterableAction.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import android.os.Bundle;

import androidx.test.core.app.ApplicationProvider;

import org.json.JSONException;
import org.json.JSONObject;
import org.robolectric.RuntimeEnvironment;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -48,7 +49,7 @@ public static void createIterableApiNew(ConfigBuilderExtender extender, String e
builder = extender.run(builder);
}

IterableApi.initialize(RuntimeEnvironment.application, apiKey, builder.build());
IterableApi.initialize(ApplicationProvider.getApplicationContext(), apiKey, builder.build());
IterableApi.getInstance().setEmail(email);
}

Expand All @@ -60,7 +61,7 @@ public static String getResourceString(String fileName) throws IOException {
InputStream inputStream = IterableTestUtils.class.getClassLoader().getResourceAsStream(fileName);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String receiveString = "";
String receiveString;
StringBuilder stringBuilder = new StringBuilder();

while ((receiveString = bufferedReader.readLine()) != null) {
Expand Down
Loading