use of com.onesignal.ShadowOneSignalRestClient.setRemoteParamsGetHtmlResponse in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method shouldFirePermissionObserverWhenUserDisablesNotifications.
@Test
public void shouldFirePermissionObserverWhenUserDisablesNotifications() throws Exception {
ShadowOneSignalRestClient.setRemoteParamsGetHtmlResponse(new JSONObject().put("unsubscribe_on_notifications_disabled", false));
OneSignalInit();
threadAndTaskWait();
OSPermissionObserver permissionObserver = stateChanges -> {
lastPermissionStateChanges = stateChanges;
currentPermission = stateChanges.getTo().areNotificationsEnabled();
};
OneSignal.addPermissionObserver(permissionObserver);
lastPermissionStateChanges = null;
// Make sure garbage collection doesn't nuke any observers.
Runtime.getRuntime().gc();
stopActivity(blankActivityController);
ShadowNotificationManagerCompat.enabled = false;
blankActivityController.resume();
assertTrue(lastPermissionStateChanges.getFrom().areNotificationsEnabled());
assertFalse(lastPermissionStateChanges.getTo().areNotificationsEnabled());
// Test to make sure object was correct at the time of firing.
assertFalse(currentPermission);
// unsubscribeWhenNotificationsAreDisabled is not set so don't send notification_types.
assertFalse(ShadowOneSignalRestClient.lastPost.has("notification_types"));
}
Aggregations