MessageListenerService extends GcmListenerService { @Override public void onMessageReceived(String from, Bundle data) { final int type = Integer.valueOf(data.getString("type", "-1")); if (type == MSG_ERROR_TYPE) { Timber.e("Invalid message format " + data.toString()); return; } final int mainType = type / CATEGORY_MASK; final int subType = type % CATEGORY_MASK; switch (mainType) { case MessageTypes.SERVICE: handleServiceSubType(subType, data); break; case MessageTypes.NEWS: final String title = data.getString(NewsMessagesKeys.TITLE); final String url = data.getString(NewsMessagesKeys.URL); final String country = data.getString(NewsMessagesKeys.COUNTRY); final String lang = data.getString(NewsMessagesKeys.LANGUAGE); sendNewsNotification(subType, title, url, country, lang); telemetry.sendNotificationSignal(TelemetryKeys.RECEIVE, "news", true); break; case MessageTypes.SPORT: handleSportSubtype(subType, data); telemetry.sendNotificationSignal(TelemetryKeys.RECEIVE, "subscription", false); break; default: unknownMessageType(mainType, subType); break; } }  @Override void onCreate(); @Override void onMessageReceived(String from, Bundle data);  }
@Test public void generateNewsNotification() { final Bundle data = new Bundle(); data.putString(MessageListenerService.MessagesKeys.TYPE, "20000"); data.putString(MessageListenerService.NewsMessagesKeys.TITLE, NOTIFICATION_TITLE); data.putString(MessageListenerService.NewsMessagesKeys.URL, NOTIFICATION_URL); final MessageListenerService service = mServiceController.get(); service.onMessageReceived("TEST", data); final List<Notification> notifications = shadowOf(mNotificationManager) .getAllNotifications(); assertEquals(1, notifications.size()); final Notification notification = notifications.get(0); final Intent intent = shadowOf(notification.contentIntent).getSavedIntents()[0]; final ShadowNotification shadowNotification = shadowOf(notification); assertEquals(NOTIFICATION_HOST, shadowNotification.getContentTitle()); assertEquals(NOTIFICATION_TITLE, shadowNotification.getContentText()); assertEquals(NOTIFICATION_URL, intent.getData().toString()); assertEquals(Intent.ACTION_VIEW, intent.getAction()); assertEquals(MainActivity.class, shadowOf(intent).getIntentClass()); }