Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void reInitIterableApi() {
authHandler = mock(IterableAuthHandler.class);
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testRefreshToken() throws Exception {
IterableApi.initialize(getContext(), "apiKey");
Expand Down Expand Up @@ -95,7 +95,7 @@ public void testRefreshToken() throws Exception {
timer = IterableApi.getInstance().getAuthManager().timer;
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testSetEmailWithToken() throws Exception {
IterableApi.initialize(getContext(), "apiKey");
Expand All @@ -119,7 +119,7 @@ public void testSetEmailWithToken() throws Exception {
shadowOf(getMainLooper()).runToEndOfTasks();
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testSetEmailWithTokenExpired() throws Exception {
IterableApi.initialize(getContext(), "apiKey");
Expand All @@ -133,7 +133,7 @@ public void testSetEmailWithTokenExpired() throws Exception {
assertEquals(IterableApi.getInstance().getAuthToken(), expiredJWT);
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testSetUserIdWithToken() throws Exception {
IterableApi.initialize(getContext(), "apiKey");
Expand All @@ -157,7 +157,7 @@ public void testSetUserIdWithToken() throws Exception {
assertEquals(expiredJWT, IterableApi.getInstance().getAuthToken());
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testSameEmailWithNewToken() throws Exception {
IterableApi.initialize(getContext(), "apiKey");
Expand All @@ -181,7 +181,7 @@ public void testSameEmailWithNewToken() throws Exception {
assertEquals(IterableApi.getInstance().getAuthToken(), newJWT);
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testSameUserIdWithNewToken() throws Exception {
IterableApi.initialize(getContext(), "apiKey");
Expand All @@ -200,7 +200,7 @@ public void testSameUserIdWithNewToken() throws Exception {
assertEquals(IterableApi.getInstance().getAuthToken(), newJWT);
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testSetSameEmailAndRemoveToken() throws Exception {
IterableApi.initialize(getContext(), "apiKey");
Expand All @@ -219,7 +219,7 @@ public void testSetSameEmailAndRemoveToken() throws Exception {
assertNull(IterableApi.getInstance().getAuthToken());
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testSetSameUserIdAndRemoveToken() throws Exception {
IterableApi.initialize(getContext(), "apiKey");
Expand Down Expand Up @@ -277,7 +277,7 @@ public void testSetSameUserId() throws Exception {
assertNull(IterableApi.getInstance().getAuthToken());
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testSetSameEmailWithSameToken() throws Exception {
IterableApi.initialize(getContext(), "apiKey");
Expand All @@ -297,7 +297,7 @@ public void testSetSameEmailWithSameToken() throws Exception {
assertEquals(IterableApi.getInstance().getAuthToken(), token);
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testSetSameUserIdWithSameToken() throws Exception {
IterableApi.initialize(getContext(), "apiKey");
Expand Down Expand Up @@ -352,7 +352,7 @@ public void testUserIdLogOut() throws Exception {
assertNull(IterableApi.getInstance().getAuthToken());
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testAuthTokenPresentInRequest() throws Exception {
// server.enqueue(new MockResponse().setResponseCode(200).setBody("{}"));
Expand Down Expand Up @@ -392,7 +392,7 @@ public void testAuthTokenPresentInRequest() throws Exception {
assertEquals(HEADER_SDK_AUTH_FORMAT + newJWT, getMessagesSet2Request.getHeader("Authorization"));
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testAuthFailureReturns401() throws InterruptedException {
doReturn(expiredJWT).when(authHandler).onAuthTokenRequested();
Expand All @@ -418,7 +418,7 @@ public void testAuthFailureReturns401() throws InterruptedException {
assertEquals(IterableApi.getInstance().getAuthToken(), expiredJWT);
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testAuthRequestedOnSetEmail() throws InterruptedException {
doReturn(expiredJWT).when(authHandler).onAuthTokenRequested();
Expand All @@ -433,7 +433,7 @@ public void testAuthRequestedOnSetEmail() throws InterruptedException {

}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testAuthRequestedOnUpdateEmail() throws InterruptedException {
doReturn(expiredJWT).when(authHandler).onAuthTokenRequested();
Expand All @@ -447,7 +447,7 @@ public void testAuthRequestedOnUpdateEmail() throws InterruptedException {
//TODO: Shouldn't the update call also update the authToken in IterableAPI class?
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testAuthRequestedOnSetUserId() throws InterruptedException {
doReturn(expiredJWT).when(authHandler).onAuthTokenRequested();
Expand All @@ -456,7 +456,7 @@ public void testAuthRequestedOnSetUserId() throws InterruptedException {
assertEquals(IterableApi.getInstance().getAuthToken(), expiredJWT);
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testAuthSetToNullOnLogOut() throws InterruptedException {
doReturn(expiredJWT).when(authHandler).onAuthTokenRequested();
Expand All @@ -469,7 +469,7 @@ public void testAuthSetToNullOnLogOut() throws InterruptedException {
assertNull(IterableApi.getInstance().getAuthToken());
}

@Ignore ("Ignoring the JWT Tests")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testRegisterForPushInvokedAfterTokenRefresh() throws InterruptedException {
doReturn(expiredJWT).when(authHandler).onAuthTokenRequested();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void testPostRequestHeaders() throws Exception {
Assert.assertEquals("fake_key", request.getHeader(IterableConstants.HEADER_API_KEY));
}

@Ignore("Ignoring the JWT related test error")
@Ignore("Blocked: IterableAuthManager.executor is not injectable - auth token requests run on uncontrollable background thread")
@Test
public void testUpdateEmailRequest() throws Exception {
server.enqueue(new MockResponse().setResponseCode(200).setBody("{}"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void testUpdateEmailWithUserId() throws Exception {
assertEquals("testUserId", IterableApi.getInstance().getUserId());
}

@Ignore
@Ignore("handleAppLink performs real HTTP redirect - needs MockWebServer to stub the redirect endpoint")
@Test
public void testHandleUniversalLinkRewrite() throws Exception {
IterableUrlHandler urlHandlerMock = mock(IterableUrlHandler.class);
Expand Down Expand Up @@ -423,7 +423,7 @@ public void testInAppResetOnLogout() throws Exception {
verify(IterableApi.sharedInstance.getInAppManager(), times(2)).reset();
}

@Ignore("Ignoring this test as it fails on CI for some reason")
@Ignore("Fails on CI: likely IterableTaskStorage singleton state leakage between tests - needs investigation")
@Test
public void databaseClearOnLogout() throws Exception {
IterableTaskStorage taskStorage = IterableTaskStorage.sharedInstance(getContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.robolectric.Shadows.shadowOf;
Expand Down Expand Up @@ -90,7 +89,7 @@ public void tearDown() throws IOException {
server = null;
}

@Ignore("Ignoring due to stalling")
@Ignore("Stalls under Robolectric: showIterableFragmentNotificationHTML requires real Activity lifecycle - candidate for androidTest with Espresso")
@Test
public void testDoNotShowMultipleTimes() throws Exception {
ActivityController<FragmentActivity> controller = Robolectric.buildActivity(FragmentActivity.class).create().start().resume();
Expand All @@ -104,7 +103,7 @@ public void testDoNotShowMultipleTimes() throws Exception {
controller.pause().stop().destroy();
}

@Ignore("Ignoring due to stalling")
@Ignore("Stalls under Robolectric: showIterableFragmentNotificationHTML requires real Activity lifecycle - candidate for androidTest with Espresso")
@Test
public void testIfDialogDoesNotDestroysAfterConfigurationChange() throws Exception {
ActivityController<FragmentActivity> controller = Robolectric.buildActivity(FragmentActivity.class).create().start().resume();
Expand All @@ -118,7 +117,7 @@ public void testIfDialogDoesNotDestroysAfterConfigurationChange() throws Excepti
controller.pause().stop().destroy();
}

@Ignore("Ignoring due to stalling")
@Ignore("Stalls under Robolectric: showIterableFragmentNotificationHTML requires real Activity lifecycle - candidate for androidTest with Espresso")
@Test
public void testIfDialogFragmentExistAfterRotation() throws Exception {
ActivityController controller = Robolectric.buildActivity(FragmentActivity.class).create().start().resume();
Expand Down Expand Up @@ -256,7 +255,7 @@ public void run() {
backgroundExecutor.runAll();
shadowOf(getMainLooper()).idle();

verify(listener, timeout(100)).onInboxUpdated();
verify(listener).onInboxUpdated();
}

@Test
Expand All @@ -278,9 +277,13 @@ public IterableConfig.Builder run(IterableConfig.Builder builder) {
});
doReturn(true).when(urlHandler).handleIterableURL(any(Uri.class), any(IterableActionContext.class));

// Flush the looper so the constructor's syncInApp() completes and sets lastSyncTime.
// Without this, the foreground transition triggers a second syncInApp() that clears messages.
shadowOf(getMainLooper()).idle();

// Bring the app into foreground to trigger in-app display
Robolectric.buildActivity(Activity.class).create().start().resume();
Robolectric.flushForegroundThreadScheduler();
shadowOf(getMainLooper()).idle();
ArgumentCaptor<IterableHelper.IterableUrlCallback> callbackCaptor = ArgumentCaptor.forClass(IterableHelper.IterableUrlCallback.class);
verify(inAppDisplayerMock).showMessage(any(IterableInAppMessage.class), eq(IterableInAppLocation.IN_APP), callbackCaptor.capture());
IterableInAppMessage message = inAppManager.getMessages().get(0);
Expand Down Expand Up @@ -342,9 +345,13 @@ public IterableConfig.Builder run(IterableConfig.Builder builder) {
});
doReturn(true).when(urlHandler).handleIterableURL(any(Uri.class), any(IterableActionContext.class));

// Flush the looper so the constructor's syncInApp() completes and sets lastSyncTime.
// Without this, the foreground transition triggers a second syncInApp() that clears messages.
shadowOf(getMainLooper()).idle();

// Bring the app into foreground
Robolectric.buildActivity(Activity.class).create().start().resume();
Robolectric.flushForegroundThreadScheduler();
shadowOf(getMainLooper()).idle();
IterableInAppMessage message = inAppManager.getMessages().get(0);

// Verify that message is not consumed by default if consume = false and iterable://dismiss is clicked
Expand Down Expand Up @@ -379,7 +386,7 @@ public void testInAppAutoDisplayPause() throws Exception {

inAppManager.setAutoDisplayPaused(true);
ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class).create().start().resume();
Robolectric.flushForegroundThreadScheduler();
shadowOf(getMainLooper()).idle();
ArgumentCaptor<IterableInAppMessage> inAppMessageCaptor = ArgumentCaptor.forClass(IterableInAppMessage.class);
verify(inAppHandler, times(0)).onNewInApp(inAppMessageCaptor.capture());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;

import static android.os.Looper.getMainLooper;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
Expand Down Expand Up @@ -50,11 +51,11 @@ private Context getContext() {
return getApplicationContext();
}

private IterableNotificationBuilder postNotification(Bundle notificationData) throws InterruptedException {
private IterableNotificationBuilder postNotification(Bundle notificationData) {
getContext().getApplicationInfo().icon = android.R.drawable.sym_def_app_icon;
IterableNotificationBuilder iterableNotification = IterableNotificationHelper.createNotification(getContext(), notificationData);
IterableNotificationHelper.postNotificationOnDevice(appContext, iterableNotification);
Thread.sleep(1000);
shadowOf(getMainLooper()).idle();
return iterableNotification;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
Expand Down Expand Up @@ -73,7 +72,8 @@ public void testEnableDevice() throws Exception {
new IterablePushRegistrationTask().execute(data);
deviceAttributes.put(DEVICE_ATTRIBUTES_KEY, DEVICE_ATTRIBUTES_VALUE);

verify(apiMock, timeout(100)).registerDeviceToken(eq(IterableTestUtils.userEmail), nullable(String.class), isNull(), eq(INTEGRATION_NAME), eq(TEST_TOKEN), eq(deviceAttributes));
shadowOf(getMainLooper()).idle();
verify(apiMock).registerDeviceToken(eq(IterableTestUtils.userEmail), nullable(String.class), isNull(), eq(INTEGRATION_NAME), eq(TEST_TOKEN), eq(deviceAttributes));

verify(apiMock, never()).disableToken(eq(IterableTestUtils.userEmail), nullable(String.class), nullable(String.class), any(String.class), nullable(IterableHelper.SuccessHandler.class), nullable(IterableHelper.FailureHandler.class));
}
Expand All @@ -87,6 +87,6 @@ public void testDisableDevice() throws Exception {
new IterablePushRegistrationTask().execute(data);
shadowOf(getMainLooper()).idle();

verify(apiMock, timeout(100)).disableToken(eq(IterableTestUtils.userEmail), isNull(), isNull(), eq(TEST_TOKEN), nullable(IterableHelper.SuccessHandler.class), nullable(IterableHelper.FailureHandler.class));
verify(apiMock).disableToken(eq(IterableTestUtils.userEmail), isNull(), isNull(), eq(TEST_TOKEN), nullable(IterableHelper.SuccessHandler.class), nullable(IterableHelper.FailureHandler.class));
}
}
Loading