@Test @PrepareForTest({CommerceEvent.class}) public void testReplayEvents() throws Exception { KitFrameworkWrapper wrapper = new KitFrameworkWrapper(Mockito.mock(Context.class), Mockito.mock(ReportingManager.class), Mockito.mock(ConfigManager.class), Mockito.mock(AppStateManager.class), mockBackgroundTaskHandler, true); Mockito.when(wrapper.mCoreCallbacks.getPushInstanceId()).thenReturn("instanceId"); Mockito.when(wrapper.mCoreCallbacks.getPushSenderId()).thenReturn("1234545"); MParticle.setInstance(new MockMParticle()); wrapper.replayEvents(); KitManager mockKitManager = Mockito.mock(KitManager.class); wrapper.setKitManager(mockKitManager); PushRegistrationHelper.PushRegistration registration = new PushRegistrationHelper.PushRegistration("instance id", "1234545"); Mockito.when( MParticle.getInstance().Internal().getConfigManager().getPushRegistration() ).thenReturn(registration); wrapper.replayEvents(); Mockito.verify( mockKitManager, Mockito.times(0) ).onPushRegistration(Mockito.anyString(), Mockito.anyString()); wrapper.onPushRegistration("whatever", "whatever"); wrapper.replayEvents(); Mockito.verify( mockKitManager, Mockito.times(1) ).onPushRegistration(Mockito.anyString(), Mockito.anyString()); wrapper.replayEvents(); wrapper.setKitsLoaded(false); MPEvent event = new MPEvent.Builder("example").build(); MPEvent screenEvent = Mockito.mock(MPEvent.class); CommerceEvent commerceEvent = PowerMockito.mock(CommerceEvent.class); Mockito.when(screenEvent.isScreenEvent()).thenReturn(true); wrapper.logEvent(event); wrapper.logEvent(screenEvent); wrapper.setUserAttribute("a key", "a value", 1); wrapper.logEvent(commerceEvent); Mockito.verify( mockKitManager, Mockito.times(0) ).logEvent(Mockito.any(MPEvent.class)); Mockito.verify( mockKitManager, Mockito.times(0) ).logScreen(Mockito.any(MPEvent.class)); Mockito.verify( mockKitManager, Mockito.times(0) ).logEvent(Mockito.any(CommerceEvent.class)); Mockito.verify( mockKitManager, Mockito.times(0) ).setUserAttribute(Mockito.anyString(), Mockito.anyString(), Mockito.anyLong()); wrapper.replayEvents(); Mockito.verify( mockKitManager, Mockito.times(1) ).logEvent(Mockito.any(MPEvent.class)); Mockito.verify( mockKitManager, Mockito.times(1) ).logScreen(Mockito.any(MPEvent.class)); Mockito.verify( mockKitManager, Mockito.times(1) ).logEvent(Mockito.any(CommerceEvent.class)); Mockito.verify( mockKitManager, Mockito.times(1) ).setUserAttribute(Mockito.eq("a key"), Mockito.eq("a value"), Mockito.anyLong()); }
void replayEvents() { if (mKitManager == null) { return; } mKitManager.onSessionStart(); if (registerForPush) { String instanceId = mCoreCallbacks.getPushInstanceId(); String senderId = mCoreCallbacks.getPushSenderId(); if (!MPUtility.isEmpty(instanceId)) { mKitManager.onPushRegistration(instanceId, senderId); } } if (eventQueue != null && eventQueue.size() > 0) { Logger.debug("Replaying events after receiving first kit configuration."); for (Object event : eventQueue) { if (event instanceof MPEvent) { MPEvent mpEvent = (MPEvent) event; if (mpEvent.isScreenEvent()) { mKitManager.logScreen(mpEvent); } else { mKitManager.logEvent(mpEvent); } } else if (event instanceof BaseEvent) { mKitManager.logEvent((BaseEvent) event); } } } if (attributeQueue != null && attributeQueue.size() > 0) { Logger.debug("Replaying user attributes after receiving first kit configuration."); for (AttributeChange attributeChange : attributeQueue) { switch (attributeChange.type) { case AttributeChange.SET_ATTRIBUTE: if (attributeChange.value == null) { mKitManager.setUserAttribute(attributeChange.key, null, attributeChange.mpid); } else if (attributeChange.value instanceof String) { mKitManager.setUserAttribute(attributeChange.key, (String) attributeChange.value, attributeChange.mpid); } else if (attributeChange.value instanceof List) { mKitManager.setUserAttributeList(attributeChange.key, (List<String>) attributeChange.value, attributeChange.mpid); } break; case AttributeChange.REMOVE_ATTRIBUTE: mKitManager.removeUserAttribute(attributeChange.key, attributeChange.mpid); break; case AttributeChange.INCREMENT_ATTRIBUTE: if (attributeChange.value instanceof String) { mKitManager.incrementUserAttribute(attributeChange.key, attributeChange.incrementedBy, (String)attributeChange.value, attributeChange.mpid); } break; case AttributeChange.TAG: mKitManager.setUserTag(attributeChange.key, attributeChange.mpid); break; } } } }
KitFrameworkWrapper implements KitManager { void replayEvents() { if (mKitManager == null) { return; } mKitManager.onSessionStart(); if (registerForPush) { String instanceId = mCoreCallbacks.getPushInstanceId(); String senderId = mCoreCallbacks.getPushSenderId(); if (!MPUtility.isEmpty(instanceId)) { mKitManager.onPushRegistration(instanceId, senderId); } } if (eventQueue != null && eventQueue.size() > 0) { Logger.debug("Replaying events after receiving first kit configuration."); for (Object event : eventQueue) { if (event instanceof MPEvent) { MPEvent mpEvent = (MPEvent) event; if (mpEvent.isScreenEvent()) { mKitManager.logScreen(mpEvent); } else { mKitManager.logEvent(mpEvent); } } else if (event instanceof BaseEvent) { mKitManager.logEvent((BaseEvent) event); } } } if (attributeQueue != null && attributeQueue.size() > 0) { Logger.debug("Replaying user attributes after receiving first kit configuration."); for (AttributeChange attributeChange : attributeQueue) { switch (attributeChange.type) { case AttributeChange.SET_ATTRIBUTE: if (attributeChange.value == null) { mKitManager.setUserAttribute(attributeChange.key, null, attributeChange.mpid); } else if (attributeChange.value instanceof String) { mKitManager.setUserAttribute(attributeChange.key, (String) attributeChange.value, attributeChange.mpid); } else if (attributeChange.value instanceof List) { mKitManager.setUserAttributeList(attributeChange.key, (List<String>) attributeChange.value, attributeChange.mpid); } break; case AttributeChange.REMOVE_ATTRIBUTE: mKitManager.removeUserAttribute(attributeChange.key, attributeChange.mpid); break; case AttributeChange.INCREMENT_ATTRIBUTE: if (attributeChange.value instanceof String) { mKitManager.incrementUserAttribute(attributeChange.key, attributeChange.incrementedBy, (String)attributeChange.value, attributeChange.mpid); } break; case AttributeChange.TAG: mKitManager.setUserTag(attributeChange.key, attributeChange.mpid); break; } } } } }
KitFrameworkWrapper implements KitManager { void replayEvents() { if (mKitManager == null) { return; } mKitManager.onSessionStart(); if (registerForPush) { String instanceId = mCoreCallbacks.getPushInstanceId(); String senderId = mCoreCallbacks.getPushSenderId(); if (!MPUtility.isEmpty(instanceId)) { mKitManager.onPushRegistration(instanceId, senderId); } } if (eventQueue != null && eventQueue.size() > 0) { Logger.debug("Replaying events after receiving first kit configuration."); for (Object event : eventQueue) { if (event instanceof MPEvent) { MPEvent mpEvent = (MPEvent) event; if (mpEvent.isScreenEvent()) { mKitManager.logScreen(mpEvent); } else { mKitManager.logEvent(mpEvent); } } else if (event instanceof BaseEvent) { mKitManager.logEvent((BaseEvent) event); } } } if (attributeQueue != null && attributeQueue.size() > 0) { Logger.debug("Replaying user attributes after receiving first kit configuration."); for (AttributeChange attributeChange : attributeQueue) { switch (attributeChange.type) { case AttributeChange.SET_ATTRIBUTE: if (attributeChange.value == null) { mKitManager.setUserAttribute(attributeChange.key, null, attributeChange.mpid); } else if (attributeChange.value instanceof String) { mKitManager.setUserAttribute(attributeChange.key, (String) attributeChange.value, attributeChange.mpid); } else if (attributeChange.value instanceof List) { mKitManager.setUserAttributeList(attributeChange.key, (List<String>) attributeChange.value, attributeChange.mpid); } break; case AttributeChange.REMOVE_ATTRIBUTE: mKitManager.removeUserAttribute(attributeChange.key, attributeChange.mpid); break; case AttributeChange.INCREMENT_ATTRIBUTE: if (attributeChange.value instanceof String) { mKitManager.incrementUserAttribute(attributeChange.key, attributeChange.incrementedBy, (String)attributeChange.value, attributeChange.mpid); } break; case AttributeChange.TAG: mKitManager.setUserTag(attributeChange.key, attributeChange.mpid); break; } } } } KitFrameworkWrapper(Context context, ReportingManager reportingManager, ConfigManager configManager, AppStateManager appStateManager, BackgroundTaskHandler backgroundTaskHandler);  KitFrameworkWrapper(Context context, ReportingManager reportingManager, ConfigManager configManager, AppStateManager appStateManager, BackgroundTaskHandler backgroundTaskHandler, boolean testing); }
KitFrameworkWrapper implements KitManager { void replayEvents() { if (mKitManager == null) { return; } mKitManager.onSessionStart(); if (registerForPush) { String instanceId = mCoreCallbacks.getPushInstanceId(); String senderId = mCoreCallbacks.getPushSenderId(); if (!MPUtility.isEmpty(instanceId)) { mKitManager.onPushRegistration(instanceId, senderId); } } if (eventQueue != null && eventQueue.size() > 0) { Logger.debug("Replaying events after receiving first kit configuration."); for (Object event : eventQueue) { if (event instanceof MPEvent) { MPEvent mpEvent = (MPEvent) event; if (mpEvent.isScreenEvent()) { mKitManager.logScreen(mpEvent); } else { mKitManager.logEvent(mpEvent); } } else if (event instanceof BaseEvent) { mKitManager.logEvent((BaseEvent) event); } } } if (attributeQueue != null && attributeQueue.size() > 0) { Logger.debug("Replaying user attributes after receiving first kit configuration."); for (AttributeChange attributeChange : attributeQueue) { switch (attributeChange.type) { case AttributeChange.SET_ATTRIBUTE: if (attributeChange.value == null) { mKitManager.setUserAttribute(attributeChange.key, null, attributeChange.mpid); } else if (attributeChange.value instanceof String) { mKitManager.setUserAttribute(attributeChange.key, (String) attributeChange.value, attributeChange.mpid); } else if (attributeChange.value instanceof List) { mKitManager.setUserAttributeList(attributeChange.key, (List<String>) attributeChange.value, attributeChange.mpid); } break; case AttributeChange.REMOVE_ATTRIBUTE: mKitManager.removeUserAttribute(attributeChange.key, attributeChange.mpid); break; case AttributeChange.INCREMENT_ATTRIBUTE: if (attributeChange.value instanceof String) { mKitManager.incrementUserAttribute(attributeChange.key, attributeChange.incrementedBy, (String)attributeChange.value, attributeChange.mpid); } break; case AttributeChange.TAG: mKitManager.setUserTag(attributeChange.key, attributeChange.mpid); break; } } } } KitFrameworkWrapper(Context context, ReportingManager reportingManager, ConfigManager configManager, AppStateManager appStateManager, BackgroundTaskHandler backgroundTaskHandler);  KitFrameworkWrapper(Context context, ReportingManager reportingManager, ConfigManager configManager, AppStateManager appStateManager, BackgroundTaskHandler backgroundTaskHandler, boolean testing); void loadKitLibrary(); static boolean getKitsLoaded(); static void setKitsLoadedListener(KitsLoadedListener listener); synchronized void replayAndDisableQueue(); WeakReference<Activity> getCurrentActivity(); @Override void logEvent(BaseEvent event); @Override void logScreen(MPEvent screenEvent); @Override void leaveBreadcrumb(String breadcrumb); @Override void logError(String message, Map<String, String> eventData); @Override void logNetworkPerformance(String url, long startTime, String method, long length, long bytesSent, long bytesReceived, String requestString, int responseCode); @Override void logException(Exception exception, Map<String, String> eventData, String message); @Override void setLocation(Location location); @Override void logout(); @Override void setUserAttribute(String key, String value, long mpid); @Override void setUserAttributeList(String key, List<String> value, long mpid); @Override void removeUserAttribute(String key, long mpid); @Override void setUserTag(String tag, long mpid); @Override void incrementUserAttribute(String key, int incrementValue, String newValue, long mpid); @Override void setUserIdentity(String id, MParticle.IdentityType identityType); @Override void removeUserIdentity(MParticle.IdentityType id); @Override void setOptOut(boolean optOutStatus); @Override Uri getSurveyUrl(int kitId, Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists); @Override boolean onMessageReceived(Context context, Intent intent); @Override boolean onPushRegistration(String instanceId, String senderId); @Override boolean isKitActive(int kitId); @Override Object getKitInstance(int kitId); @Override Set<Integer> getSupportedKits(); @Override void updateKits(JSONArray kitConfiguration); @Override String getActiveModuleIds(); @Override void onActivityCreated(Activity activity, Bundle savedInstanceState); @Override void onActivityStarted(Activity activity); @Override void onActivityResumed(Activity activity); @Override void onActivityPaused(Activity activity); @Override void onActivityStopped(Activity activity); @Override void onActivitySaveInstanceState(Activity activity, Bundle outState); @Override void onActivityDestroyed(Activity activity); @Override void onSessionEnd(); @Override void onSessionStart(); @Override void installReferrerUpdated(); @Override void onApplicationForeground(); @Override void onApplicationBackground(); @Override Map<Integer, AttributionResult> getAttributionResults(); @Override void onIdentifyCompleted(MParticleUser user, IdentityApiRequest request); @Override void onLoginCompleted(MParticleUser user, IdentityApiRequest request); @Override void onLogoutCompleted(MParticleUser user, IdentityApiRequest request); @Override void onModifyCompleted(MParticleUser user, IdentityApiRequest request); @Override void onConsentStateUpdated(ConsentState oldState, ConsentState newState, long mpid); @Override void reset(); }
KitFrameworkWrapper implements KitManager { void replayEvents() { if (mKitManager == null) { return; } mKitManager.onSessionStart(); if (registerForPush) { String instanceId = mCoreCallbacks.getPushInstanceId(); String senderId = mCoreCallbacks.getPushSenderId(); if (!MPUtility.isEmpty(instanceId)) { mKitManager.onPushRegistration(instanceId, senderId); } } if (eventQueue != null && eventQueue.size() > 0) { Logger.debug("Replaying events after receiving first kit configuration."); for (Object event : eventQueue) { if (event instanceof MPEvent) { MPEvent mpEvent = (MPEvent) event; if (mpEvent.isScreenEvent()) { mKitManager.logScreen(mpEvent); } else { mKitManager.logEvent(mpEvent); } } else if (event instanceof BaseEvent) { mKitManager.logEvent((BaseEvent) event); } } } if (attributeQueue != null && attributeQueue.size() > 0) { Logger.debug("Replaying user attributes after receiving first kit configuration."); for (AttributeChange attributeChange : attributeQueue) { switch (attributeChange.type) { case AttributeChange.SET_ATTRIBUTE: if (attributeChange.value == null) { mKitManager.setUserAttribute(attributeChange.key, null, attributeChange.mpid); } else if (attributeChange.value instanceof String) { mKitManager.setUserAttribute(attributeChange.key, (String) attributeChange.value, attributeChange.mpid); } else if (attributeChange.value instanceof List) { mKitManager.setUserAttributeList(attributeChange.key, (List<String>) attributeChange.value, attributeChange.mpid); } break; case AttributeChange.REMOVE_ATTRIBUTE: mKitManager.removeUserAttribute(attributeChange.key, attributeChange.mpid); break; case AttributeChange.INCREMENT_ATTRIBUTE: if (attributeChange.value instanceof String) { mKitManager.incrementUserAttribute(attributeChange.key, attributeChange.incrementedBy, (String)attributeChange.value, attributeChange.mpid); } break; case AttributeChange.TAG: mKitManager.setUserTag(attributeChange.key, attributeChange.mpid); break; } } } } KitFrameworkWrapper(Context context, ReportingManager reportingManager, ConfigManager configManager, AppStateManager appStateManager, BackgroundTaskHandler backgroundTaskHandler);  KitFrameworkWrapper(Context context, ReportingManager reportingManager, ConfigManager configManager, AppStateManager appStateManager, BackgroundTaskHandler backgroundTaskHandler, boolean testing); void loadKitLibrary(); static boolean getKitsLoaded(); static void setKitsLoadedListener(KitsLoadedListener listener); synchronized void replayAndDisableQueue(); WeakReference<Activity> getCurrentActivity(); @Override void logEvent(BaseEvent event); @Override void logScreen(MPEvent screenEvent); @Override void leaveBreadcrumb(String breadcrumb); @Override void logError(String message, Map<String, String> eventData); @Override void logNetworkPerformance(String url, long startTime, String method, long length, long bytesSent, long bytesReceived, String requestString, int responseCode); @Override void logException(Exception exception, Map<String, String> eventData, String message); @Override void setLocation(Location location); @Override void logout(); @Override void setUserAttribute(String key, String value, long mpid); @Override void setUserAttributeList(String key, List<String> value, long mpid); @Override void removeUserAttribute(String key, long mpid); @Override void setUserTag(String tag, long mpid); @Override void incrementUserAttribute(String key, int incrementValue, String newValue, long mpid); @Override void setUserIdentity(String id, MParticle.IdentityType identityType); @Override void removeUserIdentity(MParticle.IdentityType id); @Override void setOptOut(boolean optOutStatus); @Override Uri getSurveyUrl(int kitId, Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists); @Override boolean onMessageReceived(Context context, Intent intent); @Override boolean onPushRegistration(String instanceId, String senderId); @Override boolean isKitActive(int kitId); @Override Object getKitInstance(int kitId); @Override Set<Integer> getSupportedKits(); @Override void updateKits(JSONArray kitConfiguration); @Override String getActiveModuleIds(); @Override void onActivityCreated(Activity activity, Bundle savedInstanceState); @Override void onActivityStarted(Activity activity); @Override void onActivityResumed(Activity activity); @Override void onActivityPaused(Activity activity); @Override void onActivityStopped(Activity activity); @Override void onActivitySaveInstanceState(Activity activity, Bundle outState); @Override void onActivityDestroyed(Activity activity); @Override void onSessionEnd(); @Override void onSessionStart(); @Override void installReferrerUpdated(); @Override void onApplicationForeground(); @Override void onApplicationBackground(); @Override Map<Integer, AttributionResult> getAttributionResults(); @Override void onIdentifyCompleted(MParticleUser user, IdentityApiRequest request); @Override void onLoginCompleted(MParticleUser user, IdentityApiRequest request); @Override void onLogoutCompleted(MParticleUser user, IdentityApiRequest request); @Override void onModifyCompleted(MParticleUser user, IdentityApiRequest request); @Override void onConsentStateUpdated(ConsentState oldState, ConsentState newState, long mpid); @Override void reset();  }