@Test public void replaceMacros_urlContainsMacrosAndTrackingInfo_returnUrlWithoutMacros() { TrackEventInfo trackEventInfo = new TrackEventInfo(); trackEventInfo.finishTimeMs = 2000; String urlWithMacros = "http: "BM_EVENT_CODE=${BM_EVENT_CODE}&" + "BM_EVENT_CODE=%24%7BBM_EVENT_CODE%7D&" + "BM_ACTION_CODE=${BM_ACTION_CODE}&" + "BM_ACTION_CODE=%24%7BBM_ACTION_CODE%7D&" + "BM_ERROR_REASON=${BM_ERROR_REASON}&" + "BM_ERROR_REASON=%24%7BBM_ERROR_REASON%7D&" + "BM_ACTION_START=${BM_ACTION_START}&" + "BM_ACTION_START=%24%7BBM_ACTION_START%7D&" + "BM_ACTION_FINISH=${BM_ACTION_FINISH}&" + "BM_ACTION_FINISH=%24%7BBM_ACTION_FINISH%7D"; String urlWithoutMacros = "http: "BM_EVENT_CODE=100&" + "BM_EVENT_CODE=100&" + "BM_ACTION_CODE=100&" + "BM_ACTION_CODE=100&" + "BM_ERROR_REASON=500&" + "BM_ERROR_REASON=500&" + "BM_ACTION_START=" + trackEventInfo.startTimeMs + "&" + "BM_ACTION_START=" + trackEventInfo.startTimeMs + "&" + "BM_ACTION_FINISH=" + trackEventInfo.finishTimeMs + "&" + "BM_ACTION_FINISH=" + trackEventInfo.finishTimeMs; assertEquals( urlWithoutMacros, SessionTracker.replaceMacros( urlWithMacros, trackEventInfo, 100, 500)); }
@Nullable @VisibleForTesting static String replaceMacros(@Nullable String url, @Nullable TrackEventInfo info, int processCode, int errorCode) { if (TextUtils.isEmpty(url)) return null; assert url != null; String outUrl = url; outUrl = replaceMacros(outUrl, "BM_EVENT_CODE", processCode); outUrl = replaceMacros(outUrl, "BM_ACTION_CODE", processCode); outUrl = replaceMacros(outUrl, "BM_ERROR_REASON", errorCode); if (info != null) { outUrl = replaceMacros(outUrl, "BM_ACTION_START", info.startTimeMs); outUrl = replaceMacros(outUrl, "BM_ACTION_FINISH", info.finishTimeMs); Map<String, Object> eventParameters = info.getEventParameters(); if (eventParameters != null) { for (Map.Entry<String, Object> parameter : eventParameters.entrySet()) { outUrl = replaceMacros(outUrl, parameter.getKey(), parameter.getValue()); } } } return outUrl; }
SessionTracker { @Nullable @VisibleForTesting static String replaceMacros(@Nullable String url, @Nullable TrackEventInfo info, int processCode, int errorCode) { if (TextUtils.isEmpty(url)) return null; assert url != null; String outUrl = url; outUrl = replaceMacros(outUrl, "BM_EVENT_CODE", processCode); outUrl = replaceMacros(outUrl, "BM_ACTION_CODE", processCode); outUrl = replaceMacros(outUrl, "BM_ERROR_REASON", errorCode); if (info != null) { outUrl = replaceMacros(outUrl, "BM_ACTION_START", info.startTimeMs); outUrl = replaceMacros(outUrl, "BM_ACTION_FINISH", info.finishTimeMs); Map<String, Object> eventParameters = info.getEventParameters(); if (eventParameters != null) { for (Map.Entry<String, Object> parameter : eventParameters.entrySet()) { outUrl = replaceMacros(outUrl, parameter.getKey(), parameter.getValue()); } } } return outUrl; } }
SessionTracker { @Nullable @VisibleForTesting static String replaceMacros(@Nullable String url, @Nullable TrackEventInfo info, int processCode, int errorCode) { if (TextUtils.isEmpty(url)) return null; assert url != null; String outUrl = url; outUrl = replaceMacros(outUrl, "BM_EVENT_CODE", processCode); outUrl = replaceMacros(outUrl, "BM_ACTION_CODE", processCode); outUrl = replaceMacros(outUrl, "BM_ERROR_REASON", errorCode); if (info != null) { outUrl = replaceMacros(outUrl, "BM_ACTION_START", info.startTimeMs); outUrl = replaceMacros(outUrl, "BM_ACTION_FINISH", info.finishTimeMs); Map<String, Object> eventParameters = info.getEventParameters(); if (eventParameters != null) { for (Map.Entry<String, Object> parameter : eventParameters.entrySet()) { outUrl = replaceMacros(outUrl, parameter.getKey(), parameter.getValue()); } } } return outUrl; }  }
SessionTracker { @Nullable @VisibleForTesting static String replaceMacros(@Nullable String url, @Nullable TrackEventInfo info, int processCode, int errorCode) { if (TextUtils.isEmpty(url)) return null; assert url != null; String outUrl = url; outUrl = replaceMacros(outUrl, "BM_EVENT_CODE", processCode); outUrl = replaceMacros(outUrl, "BM_ACTION_CODE", processCode); outUrl = replaceMacros(outUrl, "BM_ERROR_REASON", errorCode); if (info != null) { outUrl = replaceMacros(outUrl, "BM_ACTION_START", info.startTimeMs); outUrl = replaceMacros(outUrl, "BM_ACTION_FINISH", info.finishTimeMs); Map<String, Object> eventParameters = info.getEventParameters(); if (eventParameters != null) { for (Map.Entry<String, Object> parameter : eventParameters.entrySet()) { outUrl = replaceMacros(outUrl, parameter.getKey(), parameter.getValue()); } } } return outUrl; }   }
SessionTracker { @Nullable @VisibleForTesting static String replaceMacros(@Nullable String url, @Nullable TrackEventInfo info, int processCode, int errorCode) { if (TextUtils.isEmpty(url)) return null; assert url != null; String outUrl = url; outUrl = replaceMacros(outUrl, "BM_EVENT_CODE", processCode); outUrl = replaceMacros(outUrl, "BM_ACTION_CODE", processCode); outUrl = replaceMacros(outUrl, "BM_ERROR_REASON", errorCode); if (info != null) { outUrl = replaceMacros(outUrl, "BM_ACTION_START", info.startTimeMs); outUrl = replaceMacros(outUrl, "BM_ACTION_FINISH", info.finishTimeMs); Map<String, Object> eventParameters = info.getEventParameters(); if (eventParameters != null) { for (Map.Entry<String, Object> parameter : eventParameters.entrySet()) { outUrl = replaceMacros(outUrl, parameter.getKey(), parameter.getValue()); } } } return outUrl; }    }