### Question:
SwrveFirebaseMessagingService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); try { if (remoteMessage.getData() != null) { SwrveLogger.i("Received Firebase notification: %s" + remoteMessage.getData().toString()); Bundle extras = new Bundle(); for (String key : remoteMessage.getData().keySet()) { extras.putString(key, remoteMessage.getData().get(key)); } if (!SwrveHelper.isSwrvePush(extras)) { SwrveLogger.i("Received Push: but not processing as it doesn't contain: %s or %s", SwrveNotificationConstants.SWRVE_TRACKING_KEY, SwrveNotificationConstants.SWRVE_SILENT_TRACKING_KEY); return; } getSwrvePushServiceManager().processMessage(extras); } } catch (Exception ex) { SwrveLogger.e("Swrve exception: ", ex); } }  @Override void onNewToken(String token); @Override void onMessageReceived(RemoteMessage remoteMessage);  }### Answer:
@Test public void testOnMessageReceived() { SwrveFirebaseMessagingService service = Robolectric.setupService(SwrveFirebaseMessagingService.class); SwrveFirebaseMessagingService serviceSpy = Mockito.spy(service); serviceSpy.onCreate(); SwrvePushServiceManager mockSwrvePushServiceManager = Mockito.mock(SwrvePushServiceManager.class); Mockito.doNothing().when(mockSwrvePushServiceManager).processMessage(Mockito.any(Bundle.class)); Mockito.doReturn(mockSwrvePushServiceManager).when(serviceSpy).getSwrvePushServiceManager(); RemoteMessage.Builder invalidPushBundle = new RemoteMessage.Builder("dest"); invalidPushBundle.addData("text", "hello"); invalidPushBundle.addData("key1", "value1"); serviceSpy.onMessageReceived(invalidPushBundle.build()); ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); Mockito.verify(mockSwrvePushServiceManager, never()).processMessage(bundleCaptor.capture()); RemoteMessage.Builder validPushBundle = new RemoteMessage.Builder("dest"); validPushBundle.addData(SwrveNotificationConstants.TEXT_KEY, "validBundle"); validPushBundle.addData(SwrveNotificationConstants.SWRVE_TRACKING_KEY, "1"); serviceSpy.onMessageReceived(validPushBundle.build()); bundleCaptor = ArgumentCaptor.forClass(Bundle.class); Mockito.verify(mockSwrvePushServiceManager, Mockito.atLeastOnce()).processMessage(bundleCaptor.capture()); Bundle actualBundle = bundleCaptor.getAllValues().get(0); assertEquals(2, actualBundle.size()); assertEquals("validBundle", actualBundle.getString("text")); assertEquals("1", actualBundle.getString("_p")); }