@Override public Task<Void> then(Task<String> task) { String sessionToken = task.getResult(); return getAnalyticsController().trackAppOpenedInBackground(pushHash.get(), sessionToken); } });
@Test public void testTrackAppOpenedInBackgroundDuplicatedIntent() throws Exception { Intent intent = makeIntentWithParseData("test"); ParseTaskUtils.wait(ParseAnalytics.trackAppOpenedInBackground(intent)); verify(controller, times(1)).trackAppOpenedInBackground(eq("test"), isNull(String.class)); ParseTaskUtils.wait(ParseAnalytics.trackAppOpenedInBackground(intent)); verify(controller, times(1)).trackAppOpenedInBackground(eq("test"), isNull(String.class)); }
@Test public void testTrackAppOpenedInBackgroundNullCallback() throws Exception { Intent intent = makeIntentWithParseData("test"); ParseAnalytics.trackAppOpenedInBackground(intent, null); verify(controller, times(1)).trackAppOpenedInBackground(eq("test"), isNull(String.class)); }
@Test public void testTrackAppOpenedInBackgroundNormalCallback() throws Exception { Intent intent = makeIntentWithParseData("test"); final Semaphore done = new Semaphore(0); ParseAnalytics.trackAppOpenedInBackground(intent, new SaveCallback() { @Override public void done(ParseException e) { assertNull(e); done.release(); } }); // Make sure the callback is called assertTrue(done.tryAcquire(1, 10, TimeUnit.SECONDS)); verify(controller, times(1)).trackAppOpenedInBackground(eq("test"), isNull(String.class)); }
@Before public void setUp() { ParseTestUtils.setTestParseUser(); // Mock ParseAnalyticsController controller = mock(ParseAnalyticsController.class); when(controller.trackEventInBackground( anyString(), anyMapOf(String.class, String.class), anyString())).thenReturn(Task.<Void>forResult(null)); when(controller.trackAppOpenedInBackground( anyString(), anyString())).thenReturn(Task.<Void>forResult(null)); ParseCorePlugins.getInstance().registerAnalyticsController(controller); }
@Test public void testTrackAppOpenedInBackgroundEmptyIntent() throws Exception { Intent intent = new Intent(); ParseTaskUtils.wait(ParseAnalytics.trackAppOpenedInBackground(intent)); verify(controller, times(1)).trackAppOpenedInBackground(isNull(String.class), isNull(String.class)); }
@Test public void testTrackAppOpenedInBackgroundNormalIntent() throws Exception { Intent intent = makeIntentWithParseData("test"); ParseTaskUtils.wait(ParseAnalytics.trackAppOpenedInBackground(intent)); verify(controller, times(1)).trackAppOpenedInBackground(eq("test"), isNull(String.class)); }
@Test public void testTrackAppOpened() throws Exception { // Mock eventually queue ParseEventuallyQueue queue = mock(ParseEventuallyQueue.class); when(queue.enqueueEventuallyAsync(any(ParseRESTCommand.class), any(ParseObject.class))) .thenReturn(Task.forResult(new JSONObject())); // Execute ParseAnalyticsController controller = new ParseAnalyticsController(queue); ParseTaskUtils.wait(controller.trackAppOpenedInBackground("pushHash", "sessionToken")); // Verify eventuallyQueue.enqueueEventuallyAsync ArgumentCaptor<ParseRESTCommand> command = ArgumentCaptor.forClass(ParseRESTCommand.class); ArgumentCaptor<ParseObject> object = ArgumentCaptor.forClass(ParseObject.class); verify(queue, times(1)).enqueueEventuallyAsync(command.capture(), object.capture()); // Verify eventuallyQueue.enqueueEventuallyAsync object parameter assertNull(object.getValue()); // Verify eventuallyQueue.enqueueEventuallyAsync command parameter assertTrue(command.getValue() instanceof ParseRESTAnalyticsCommand); assertTrue(command.getValue().httpPath.contains(ParseRESTAnalyticsCommand.EVENT_APP_OPENED)); assertEquals("sessionToken", command.getValue().getSessionToken()); assertEquals("pushHash", command.getValue().jsonParameters.get("push_hash")); }
@Test public void testTrackAppOpenedInBackgroundNullIntent() throws Exception { ParseTaskUtils.wait(ParseAnalytics.trackAppOpenedInBackground(null)); verify(controller, times(1)).trackAppOpenedInBackground(isNull(String.class), isNull(String.class)); }