@Test public void testOnUserAttributesReceived() throws Exception { MParticle.setInstance(new MockMParticle()); KitManagerImpl manager = new MockKitManagerImpl(); KitIntegration integration = Mockito.mock( KitIntegration.class, Mockito.withSettings().extraInterfaces(KitIntegration.AttributeListener.class) ); KitIntegration integration2 = Mockito.mock( KitIntegration.class, Mockito.withSettings().extraInterfaces(KitIntegration.AttributeListener.class) ); Mockito.when(((KitIntegration.AttributeListener)integration).supportsAttributeLists()).thenReturn(true); Mockito.when(((KitIntegration.AttributeListener)integration2).supportsAttributeLists()).thenReturn(false); Mockito.when(integration.getConfiguration()).thenReturn(MockKitConfiguration.createKitConfiguration()); Mockito.when(integration2.getConfiguration()).thenReturn(MockKitConfiguration.createKitConfiguration()); manager.providers.put(5, integration); manager.providers.put(6, integration2); Map<String, String> userAttributeSingles = new HashMap<>(); userAttributeSingles.put("test", "whatever"); userAttributeSingles.put("test 2", "whatever 2"); Map<String, List<String>> userAttributeLists = new HashMap<>(); List<String> attributeList = new LinkedList<>(); attributeList.add("1"); attributeList.add("2"); attributeList.add("3"); userAttributeLists.put("test 3", attributeList); manager.onUserAttributesReceived(userAttributeSingles, userAttributeLists, 1L); Mockito.verify(((KitIntegration.AttributeListener)integration), Mockito.times(1)).setAllUserAttributes(userAttributeSingles, userAttributeLists); Map<String, String> userAttributesCombined = new HashMap<>(); userAttributesCombined.put("test", "whatever"); userAttributesCombined.put("test 2", "whatever 2"); userAttributesCombined.put("test 3", "1,2,3"); Map<String, List<String>> clearedOutList = new HashMap<>(); Mockito.verify(((KitIntegration.AttributeListener)integration2), Mockito.times(1)).setAllUserAttributes(userAttributesCombined, clearedOutList); }
@Override public void onUserAttributesReceived(Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists, Long mpid) { for (KitIntegration provider : providers.values()) { try { if ((provider instanceof KitIntegration.AttributeListener || provider instanceof KitIntegration.UserAttributeListener) && !provider.isDisabled()) { Map<String, String> filteredAttributeSingles = (Map<String, String>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(), userAttributes); Map<String, List<String>> filteredAttributeLists = (Map<String, List<String>>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(), userAttributeLists); if (provider instanceof KitIntegration.AttributeListener) { if (((KitIntegration.AttributeListener) provider).supportsAttributeLists()) { ((KitIntegration.AttributeListener) provider).setAllUserAttributes(filteredAttributeSingles, filteredAttributeLists); } else { Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles); for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) { singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue())); } ((KitIntegration.AttributeListener) provider).setAllUserAttributes(singlesCopy, new HashMap<String, List<String>>()); } } if (provider instanceof KitIntegration.UserAttributeListener) { if (((KitIntegration.UserAttributeListener) provider).supportsAttributeLists()) { ((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(filteredAttributeSingles, filteredAttributeLists, FilteredMParticleUser.getInstance(mpid, provider)); } else { Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles); for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) { singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue())); } ((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(singlesCopy, new HashMap<String, List<String>>(), FilteredMParticleUser.getInstance(mpid, provider)); } } } } catch (Exception e) { Logger.warning("Failed to call setUserAttributes for kit: " + provider.getName() + ": " + e.getMessage()); } } }
KitManagerImpl implements KitManager, AttributionListener, UserAttributeListener, IdentityStateListener { @Override public void onUserAttributesReceived(Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists, Long mpid) { for (KitIntegration provider : providers.values()) { try { if ((provider instanceof KitIntegration.AttributeListener || provider instanceof KitIntegration.UserAttributeListener) && !provider.isDisabled()) { Map<String, String> filteredAttributeSingles = (Map<String, String>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(), userAttributes); Map<String, List<String>> filteredAttributeLists = (Map<String, List<String>>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(), userAttributeLists); if (provider instanceof KitIntegration.AttributeListener) { if (((KitIntegration.AttributeListener) provider).supportsAttributeLists()) { ((KitIntegration.AttributeListener) provider).setAllUserAttributes(filteredAttributeSingles, filteredAttributeLists); } else { Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles); for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) { singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue())); } ((KitIntegration.AttributeListener) provider).setAllUserAttributes(singlesCopy, new HashMap<String, List<String>>()); } } if (provider instanceof KitIntegration.UserAttributeListener) { if (((KitIntegration.UserAttributeListener) provider).supportsAttributeLists()) { ((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(filteredAttributeSingles, filteredAttributeLists, FilteredMParticleUser.getInstance(mpid, provider)); } else { Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles); for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) { singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue())); } ((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(singlesCopy, new HashMap<String, List<String>>(), FilteredMParticleUser.getInstance(mpid, provider)); } } } } catch (Exception e) { Logger.warning("Failed to call setUserAttributes for kit: " + provider.getName() + ": " + e.getMessage()); } } } }
KitManagerImpl implements KitManager, AttributionListener, UserAttributeListener, IdentityStateListener { @Override public void onUserAttributesReceived(Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists, Long mpid) { for (KitIntegration provider : providers.values()) { try { if ((provider instanceof KitIntegration.AttributeListener || provider instanceof KitIntegration.UserAttributeListener) && !provider.isDisabled()) { Map<String, String> filteredAttributeSingles = (Map<String, String>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(), userAttributes); Map<String, List<String>> filteredAttributeLists = (Map<String, List<String>>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(), userAttributeLists); if (provider instanceof KitIntegration.AttributeListener) { if (((KitIntegration.AttributeListener) provider).supportsAttributeLists()) { ((KitIntegration.AttributeListener) provider).setAllUserAttributes(filteredAttributeSingles, filteredAttributeLists); } else { Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles); for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) { singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue())); } ((KitIntegration.AttributeListener) provider).setAllUserAttributes(singlesCopy, new HashMap<String, List<String>>()); } } if (provider instanceof KitIntegration.UserAttributeListener) { if (((KitIntegration.UserAttributeListener) provider).supportsAttributeLists()) { ((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(filteredAttributeSingles, filteredAttributeLists, FilteredMParticleUser.getInstance(mpid, provider)); } else { Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles); for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) { singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue())); } ((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(singlesCopy, new HashMap<String, List<String>>(), FilteredMParticleUser.getInstance(mpid, provider)); } } } } catch (Exception e) { Logger.warning("Failed to call setUserAttributes for kit: " + provider.getName() + ": " + e.getMessage()); } } } KitManagerImpl(Context context, ReportingManager reportingManager, CoreCallbacks coreCallbacks, BackgroundTaskHandler backgroundTaskHandler); }
KitManagerImpl implements KitManager, AttributionListener, UserAttributeListener, IdentityStateListener { @Override public void onUserAttributesReceived(Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists, Long mpid) { for (KitIntegration provider : providers.values()) { try { if ((provider instanceof KitIntegration.AttributeListener || provider instanceof KitIntegration.UserAttributeListener) && !provider.isDisabled()) { Map<String, String> filteredAttributeSingles = (Map<String, String>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(), userAttributes); Map<String, List<String>> filteredAttributeLists = (Map<String, List<String>>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(), userAttributeLists); if (provider instanceof KitIntegration.AttributeListener) { if (((KitIntegration.AttributeListener) provider).supportsAttributeLists()) { ((KitIntegration.AttributeListener) provider).setAllUserAttributes(filteredAttributeSingles, filteredAttributeLists); } else { Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles); for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) { singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue())); } ((KitIntegration.AttributeListener) provider).setAllUserAttributes(singlesCopy, new HashMap<String, List<String>>()); } } if (provider instanceof KitIntegration.UserAttributeListener) { if (((KitIntegration.UserAttributeListener) provider).supportsAttributeLists()) { ((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(filteredAttributeSingles, filteredAttributeLists, FilteredMParticleUser.getInstance(mpid, provider)); } else { Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles); for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) { singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue())); } ((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(singlesCopy, new HashMap<String, List<String>>(), FilteredMParticleUser.getInstance(mpid, provider)); } } } } catch (Exception e) { Logger.warning("Failed to call setUserAttributes for kit: " + provider.getName() + ": " + e.getMessage()); } } } KitManagerImpl(Context context, ReportingManager reportingManager, CoreCallbacks coreCallbacks, BackgroundTaskHandler backgroundTaskHandler); void setKitFactory(KitIntegrationFactory kitIntegrationFactory); boolean isBackgrounded(); int getUserBucket(); boolean isOptedOut(); Uri getLaunchUri(); String getLaunchAction(); @Override void updateKits(final JSONArray kitConfigs); @Override String getActiveModuleIds(); @Override boolean isKitActive(int serviceProviderId); @Override Object getKitInstance(int kitId); @Override void setLocation(Location location); @Override void logNetworkPerformance(String url, long startTime, String method, long length, long bytesSent, long bytesReceived, String requestString, int responseCode); @Override Uri getSurveyUrl(int serviceId, Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists); @Override void setOptOut(boolean optOutStatus); @Override Set<Integer> getSupportedKits(); @Override void logEvent(BaseEvent event); @Override boolean onMessageReceived(Context context, Intent intent); @Override boolean onPushRegistration(String token, String senderId); @Override void onUserAttributesReceived(Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists, Long mpid); @Override void setUserAttribute(String attributeKey, String attributeValue, long mpid); @Override void setUserAttributeList(String attributeKey, List<String> valuesList, long mpid); @Override void removeUserAttribute(String key, long mpid); @Override void incrementUserAttribute(String key, int incrementedBy, String newValue, long mpid); @Override void setUserTag(String tag, long mpid); @Override void setUserIdentity(String id, MParticle.IdentityType identityType); @Override void removeUserIdentity(MParticle.IdentityType identityType); @Override void logout(); Context getContext(); @Override WeakReference<Activity> getCurrentActivity(); @Override void leaveBreadcrumb(String breadcrumb); @Override void logError(String message, Map<String, String> eventData); @Override void logException(Exception exception, Map<String, String> eventData, String message); @Override void logScreen(MPEvent screenEvent); @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 onApplicationForeground(); @Override void onApplicationBackground(); @Override Map<Integer, AttributionResult> getAttributionResults(); @Override void onResult(AttributionResult result); @Override void onError(AttributionError error); @Override void installReferrerUpdated(); @Override void onUserIdentified(MParticleUser mParticleUser, MParticleUser previousUser); @Override void onIdentifyCompleted(MParticleUser mParticleUser, IdentityApiRequest identityApiRequest); @Override void onLoginCompleted(MParticleUser mParticleUser, IdentityApiRequest identityApiRequest); @Override void onLogoutCompleted(MParticleUser mParticleUser, IdentityApiRequest identityApiRequest); @Override void onModifyCompleted(MParticleUser mParticleUser, IdentityApiRequest identityApiRequest); @Override void onConsentStateUpdated(final ConsentState oldState, final ConsentState newState, final long mpid); @Override void reset(); void executeNetworkRequest(Runnable runnable); boolean isPushEnabled(); String getPushSenderId(); String getPushInstanceId(); }
KitManagerImpl implements KitManager, AttributionListener, UserAttributeListener, IdentityStateListener { @Override public void onUserAttributesReceived(Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists, Long mpid) { for (KitIntegration provider : providers.values()) { try { if ((provider instanceof KitIntegration.AttributeListener || provider instanceof KitIntegration.UserAttributeListener) && !provider.isDisabled()) { Map<String, String> filteredAttributeSingles = (Map<String, String>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(), userAttributes); Map<String, List<String>> filteredAttributeLists = (Map<String, List<String>>) KitConfiguration.filterAttributes(provider.getConfiguration().getUserAttributeFilters(), userAttributeLists); if (provider instanceof KitIntegration.AttributeListener) { if (((KitIntegration.AttributeListener) provider).supportsAttributeLists()) { ((KitIntegration.AttributeListener) provider).setAllUserAttributes(filteredAttributeSingles, filteredAttributeLists); } else { Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles); for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) { singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue())); } ((KitIntegration.AttributeListener) provider).setAllUserAttributes(singlesCopy, new HashMap<String, List<String>>()); } } if (provider instanceof KitIntegration.UserAttributeListener) { if (((KitIntegration.UserAttributeListener) provider).supportsAttributeLists()) { ((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(filteredAttributeSingles, filteredAttributeLists, FilteredMParticleUser.getInstance(mpid, provider)); } else { Map<String, String> singlesCopy = new HashMap<>(filteredAttributeSingles); for (Map.Entry<String, List<String>> entry : filteredAttributeLists.entrySet()) { singlesCopy.put(entry.getKey(), KitUtils.join(entry.getValue())); } ((KitIntegration.UserAttributeListener) provider).onSetAllUserAttributes(singlesCopy, new HashMap<String, List<String>>(), FilteredMParticleUser.getInstance(mpid, provider)); } } } } catch (Exception e) { Logger.warning("Failed to call setUserAttributes for kit: " + provider.getName() + ": " + e.getMessage()); } } } KitManagerImpl(Context context, ReportingManager reportingManager, CoreCallbacks coreCallbacks, BackgroundTaskHandler backgroundTaskHandler); void setKitFactory(KitIntegrationFactory kitIntegrationFactory); boolean isBackgrounded(); int getUserBucket(); boolean isOptedOut(); Uri getLaunchUri(); String getLaunchAction(); @Override void updateKits(final JSONArray kitConfigs); @Override String getActiveModuleIds(); @Override boolean isKitActive(int serviceProviderId); @Override Object getKitInstance(int kitId); @Override void setLocation(Location location); @Override void logNetworkPerformance(String url, long startTime, String method, long length, long bytesSent, long bytesReceived, String requestString, int responseCode); @Override Uri getSurveyUrl(int serviceId, Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists); @Override void setOptOut(boolean optOutStatus); @Override Set<Integer> getSupportedKits(); @Override void logEvent(BaseEvent event); @Override boolean onMessageReceived(Context context, Intent intent); @Override boolean onPushRegistration(String token, String senderId); @Override void onUserAttributesReceived(Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists, Long mpid); @Override void setUserAttribute(String attributeKey, String attributeValue, long mpid); @Override void setUserAttributeList(String attributeKey, List<String> valuesList, long mpid); @Override void removeUserAttribute(String key, long mpid); @Override void incrementUserAttribute(String key, int incrementedBy, String newValue, long mpid); @Override void setUserTag(String tag, long mpid); @Override void setUserIdentity(String id, MParticle.IdentityType identityType); @Override void removeUserIdentity(MParticle.IdentityType identityType); @Override void logout(); Context getContext(); @Override WeakReference<Activity> getCurrentActivity(); @Override void leaveBreadcrumb(String breadcrumb); @Override void logError(String message, Map<String, String> eventData); @Override void logException(Exception exception, Map<String, String> eventData, String message); @Override void logScreen(MPEvent screenEvent); @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 onApplicationForeground(); @Override void onApplicationBackground(); @Override Map<Integer, AttributionResult> getAttributionResults(); @Override void onResult(AttributionResult result); @Override void onError(AttributionError error); @Override void installReferrerUpdated(); @Override void onUserIdentified(MParticleUser mParticleUser, MParticleUser previousUser); @Override void onIdentifyCompleted(MParticleUser mParticleUser, IdentityApiRequest identityApiRequest); @Override void onLoginCompleted(MParticleUser mParticleUser, IdentityApiRequest identityApiRequest); @Override void onLogoutCompleted(MParticleUser mParticleUser, IdentityApiRequest identityApiRequest); @Override void onModifyCompleted(MParticleUser mParticleUser, IdentityApiRequest identityApiRequest); @Override void onConsentStateUpdated(final ConsentState oldState, final ConsentState newState, final long mpid); @Override void reset(); void executeNetworkRequest(Runnable runnable); boolean isPushEnabled(); String getPushSenderId(); String getPushInstanceId();  }