@Test public void testGetPushHashFromIntentEmptyIntent() throws Exception { Intent intent = new Intent(); Bundle bundle = new Bundle(); JSONObject json = new JSONObject(); json.put("push_hash_wrong_key", "test"); bundle.putString("data_wrong_key", json.toString()); intent.putExtras(bundle); String pushHash = ParseAnalytics.getPushHashFromIntent(intent); assertEquals(null, pushHash); }
@Test public void testGetPushHashFromIntentEmptyPushHashIntent() throws Exception { Intent intent = new Intent(); Bundle bundle = new Bundle(); JSONObject json = new JSONObject(); json.put("push_hash_wrong_key", "test"); bundle.putString(ParsePushBroadcastReceiver.KEY_PUSH_DATA, json.toString()); intent.putExtras(bundle); String pushHash = ParseAnalytics.getPushHashFromIntent(intent); assertEquals("", pushHash); }
@Test public void testGetPushHashFromIntentWrongPushHashIntent() { Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putString(ParsePushBroadcastReceiver.KEY_PUSH_DATA, "error_data"); intent.putExtras(bundle); String pushHash = ParseAnalytics.getPushHashFromIntent(intent); assertEquals(null, pushHash); }
/** * Tracks this application being launched (and if this happened as the result of the user opening * a push notification, this method sends along information to correlate this open with that * push). * * @param intent The {@code Intent} that started an {@code Activity}, if any. Can be null. * @return A Task that is resolved when the event has been tracked by Parse. */ public static Task<Void> trackAppOpenedInBackground(Intent intent) { String pushHashStr = getPushHashFromIntent(intent); final Capture<String> pushHash = new Capture<>(); if (pushHashStr != null && pushHashStr.length() > 0) { synchronized (lruSeenPushes) { if (lruSeenPushes.containsKey(pushHashStr)) { return Task.forResult(null); } else { lruSeenPushes.put(pushHashStr, true); pushHash.set(pushHashStr); } } } return ParseUser.getCurrentSessionTokenAsync().onSuccessTask(new Continuation<String, Task<Void>>() { @Override public Task<Void> then(Task<String> task) { String sessionToken = task.getResult(); return getAnalyticsController().trackAppOpenedInBackground(pushHash.get(), sessionToken); } }); }
@Test public void testGetPushHashFromIntentNullIntent() { String pushHash = ParseAnalytics.getPushHashFromIntent(null); assertEquals(null, pushHash); }
@Test public void testGetPushHashFromIntentNormalIntent() throws Exception { Intent intent = makeIntentWithParseData("test"); String pushHash = ParseAnalytics.getPushHashFromIntent(intent); assertEquals("test", pushHash); }