@Test public void testTokenNotReceived() { TokenRetriever tokenRetrieverMock = Mockito.mock(TokenRetriever.class); when(tokenRetrieverMock.getToken()).thenReturn(null); service.tokenRetriever = tokenRetrieverMock; service.onHandleIntent(serviceIntent); Boolean stored = sharedPreferences.getBoolean(ElloPreferences.SENT_TOKEN_TO_SERVER, true); assertFalse("Mark token NOT sent to sever if token NOT retrieved", stored); }
@Override protected void onHandleIntent(Intent intent) { String token = tokenRetriever.getToken(); Intent registrationComplete = new Intent(ElloPreferences.REGISTRATION_COMPLETE); if(token != null) { registrationComplete.putExtra("GCM_REG_ID", token); sharedPreferences.edit().putBoolean(ElloPreferences.SENT_TOKEN_TO_SERVER, true).apply(); } else { sharedPreferences.edit().putBoolean(ElloPreferences.SENT_TOKEN_TO_SERVER, false).apply(); } sendBroadcast(registrationComplete); }
RegistrationIntentService extends IntentService { @Override protected void onHandleIntent(Intent intent) { String token = tokenRetriever.getToken(); Intent registrationComplete = new Intent(ElloPreferences.REGISTRATION_COMPLETE); if(token != null) { registrationComplete.putExtra("GCM_REG_ID", token); sharedPreferences.edit().putBoolean(ElloPreferences.SENT_TOKEN_TO_SERVER, true).apply(); } else { sharedPreferences.edit().putBoolean(ElloPreferences.SENT_TOKEN_TO_SERVER, false).apply(); } sendBroadcast(registrationComplete); } }
RegistrationIntentService extends IntentService { @Override protected void onHandleIntent(Intent intent) { String token = tokenRetriever.getToken(); Intent registrationComplete = new Intent(ElloPreferences.REGISTRATION_COMPLETE); if(token != null) { registrationComplete.putExtra("GCM_REG_ID", token); sharedPreferences.edit().putBoolean(ElloPreferences.SENT_TOKEN_TO_SERVER, true).apply(); } else { sharedPreferences.edit().putBoolean(ElloPreferences.SENT_TOKEN_TO_SERVER, false).apply(); } sendBroadcast(registrationComplete); } RegistrationIntentService(); }
RegistrationIntentService extends IntentService { @Override protected void onHandleIntent(Intent intent) { String token = tokenRetriever.getToken(); Intent registrationComplete = new Intent(ElloPreferences.REGISTRATION_COMPLETE); if(token != null) { registrationComplete.putExtra("GCM_REG_ID", token); sharedPreferences.edit().putBoolean(ElloPreferences.SENT_TOKEN_TO_SERVER, true).apply(); } else { sharedPreferences.edit().putBoolean(ElloPreferences.SENT_TOKEN_TO_SERVER, false).apply(); } sendBroadcast(registrationComplete); } RegistrationIntentService(); @Override void onCreate(); }
RegistrationIntentService extends IntentService { @Override protected void onHandleIntent(Intent intent) { String token = tokenRetriever.getToken(); Intent registrationComplete = new Intent(ElloPreferences.REGISTRATION_COMPLETE); if(token != null) { registrationComplete.putExtra("GCM_REG_ID", token); sharedPreferences.edit().putBoolean(ElloPreferences.SENT_TOKEN_TO_SERVER, true).apply(); } else { sharedPreferences.edit().putBoolean(ElloPreferences.SENT_TOKEN_TO_SERVER, false).apply(); } sendBroadcast(registrationComplete); } RegistrationIntentService(); @Override void onCreate();  }