use of com.onesignal.OSSMSSubscriptionObserver in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method shouldFireSMSSubscriptionObserverOnSetSMS.
@Test
public void shouldFireSMSSubscriptionObserverOnSetSMS() throws Exception {
OneSignalInit();
OSSMSSubscriptionObserver subscriptionObserver = stateChanges -> lastSMSSubscriptionStateChanges = stateChanges;
OneSignal.addSMSSubscriptionObserver(subscriptionObserver);
OneSignal.setSMSNumber(ONESIGNAL_SMS_NUMBER);
threadAndTaskWait();
assertNull(lastSMSSubscriptionStateChanges.getFrom().getSmsUserId());
assertEquals(SMS_USER_ID, lastSMSSubscriptionStateChanges.getTo().getSmsUserId());
assertEquals(ONESIGNAL_SMS_NUMBER, lastSMSSubscriptionStateChanges.getTo().getSMSNumber());
assertTrue(lastSMSSubscriptionStateChanges.getTo().isSubscribed());
}
use of com.onesignal.OSSMSSubscriptionObserver in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method shouldAddSMSSubscriptionObserverIfConsentNotGranted.
@Test
public void shouldAddSMSSubscriptionObserverIfConsentNotGranted() throws Exception {
ShadowOneSignalRestClient.setRemoteParamsRequirePrivacyConsent(true);
OneSignalInit();
threadAndTaskWait();
OSSMSSubscriptionObserver subscriptionObserver = stateChanges -> lastSMSSubscriptionStateChanges = stateChanges;
OneSignal.addSMSSubscriptionObserver(subscriptionObserver);
OneSignal.provideUserConsent(true);
threadAndTaskWait();
assertNull(lastSMSSubscriptionStateChanges);
OneSignal.setSMSNumber(ONESIGNAL_SMS_NUMBER);
threadAndTaskWait();
// make sure the sms subscription observer was fired
assertEquals(ONESIGNAL_SMS_NUMBER, lastSMSSubscriptionStateChanges.getFrom().getSMSNumber());
assertNull(lastSMSSubscriptionStateChanges.getFrom().getSmsUserId());
assertFalse(lastSMSSubscriptionStateChanges.getFrom().isSubscribed());
assertEquals(ShadowOneSignalRestClient.smsUserId, lastSMSSubscriptionStateChanges.getTo().getSmsUserId());
assertEquals(ONESIGNAL_SMS_NUMBER, lastSMSSubscriptionStateChanges.getTo().getSMSNumber());
assertTrue(lastSMSSubscriptionStateChanges.getTo().isSubscribed());
}
use of com.onesignal.OSSMSSubscriptionObserver in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method shouldNotFireSMSSubscriptionObserverOnAppRestart.
@Test
public void shouldNotFireSMSSubscriptionObserverOnAppRestart() throws Exception {
OneSignalInit();
OneSignal.setSMSNumber(ONESIGNAL_SMS_NUMBER);
threadAndTaskWait();
OSSMSSubscriptionObserver subscriptionObserver = stateChanges -> lastSMSSubscriptionStateChanges = stateChanges;
OneSignal.addSMSSubscriptionObserver(subscriptionObserver);
threadAndTaskWait();
assertNotNull(lastSMSSubscriptionStateChanges);
restartAppAndElapseTimeToNextSession(time);
lastSMSSubscriptionStateChanges = null;
OneSignalInit();
threadAndTaskWait();
OneSignal.addSMSSubscriptionObserver(subscriptionObserver);
threadAndTaskWait();
assertNull(lastSMSSubscriptionStateChanges);
}
Aggregations