ResolutionEvent extends InAppMessageEvent { static ResolutionEvent messageResolution(@NonNull String scheduleId, @NonNull InAppMessage message, ResolutionInfo resolutionInfo, long displayMilliseconds) { displayMilliseconds = displayMilliseconds > 0 ? displayMilliseconds : 0; JsonMap.Builder resolutionDataBuilder = JsonMap.newBuilder() .put(RESOLUTION_TYPE, resolutionInfo.getType()) .put(DISPLAY_TIME, millisecondsToSecondsString(displayMilliseconds)); if (ResolutionInfo.RESOLUTION_BUTTON_CLICK.equals(resolutionInfo.getType()) && resolutionInfo.getButtonInfo() != null) { String description = resolutionInfo.getButtonInfo().getLabel().getText(); if (description != null && description.length() > MAX_BUTTON_DESCRIPTION_LENGTH) { description = description.substring(0, MAX_BUTTON_DESCRIPTION_LENGTH); } resolutionDataBuilder.put(BUTTON_ID, resolutionInfo.getButtonInfo().getId()) .put(BUTTON_DESCRIPTION, description); } return new ResolutionEvent(scheduleId, message, resolutionDataBuilder.build()); } ResolutionEvent(@NonNull String scheduleId, @NonNull InAppMessage message, @NonNull JsonMap resolutionData);   ResolutionEvent(@NonNull JsonValue eventId, @NonNull String source, @NonNull JsonMap resolutionData); @NonNull @Override final String getType(); @NonNull @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) JsonMap getEventData();  }
@Test public void testButtonClickResolutionEvent() throws JSONException { ButtonInfo buttonInfo = ButtonInfo.newBuilder() .setId("button id") .setLabel(TextInfo.newBuilder() .setText("hi") .build()) .build(); ResolutionEvent event = ResolutionEvent.messageResolution("schedule ID", message, ResolutionInfo.buttonPressed(buttonInfo), 3500); JsonMap expectedResolutionInfo = JsonMap.newBuilder() .put("type", "button_click") .put("button_id", "button id") .put("button_description", "hi") .put("display_time", Event.millisecondsToSecondsString(3500)) .build(); verifyEvent(expectedResolutionInfo, event); }
@Test public void testButtonClickResolutionEventLargeLabel() throws JSONException { String largeLabel = UAStringUtil.repeat("a", 100, ""); ButtonInfo buttonInfo = ButtonInfo.newBuilder() .setId("button id") .setLabel(TextInfo.newBuilder() .setText(largeLabel) .build()) .build(); ResolutionEvent event = ResolutionEvent.messageResolution("schedule ID", message, ResolutionInfo.buttonPressed(buttonInfo), 3500); JsonMap expectedResolutionInfo = JsonMap.newBuilder() .put("type", "button_click") .put("button_id", "button id") .put("button_description", largeLabel.substring(0, 30)) .put("display_time", Event.millisecondsToSecondsString(3500)) .build(); verifyEvent(expectedResolutionInfo, event); }
@Test public void testClickedResolutionEvent() throws JSONException { ResolutionEvent event = ResolutionEvent.messageResolution("schedule ID", message, ResolutionInfo.messageClicked(), 5500); JsonMap expectedResolutionInfo = JsonMap.newBuilder() .put("type", "message_click") .put("display_time", Event.millisecondsToSecondsString(5500)) .build(); verifyEvent(expectedResolutionInfo, event); }
@Test public void testUserDismissedResolutionEvent() throws JSONException { ResolutionEvent event = ResolutionEvent.messageResolution("schedule ID", message, ResolutionInfo.dismissed(), 3500); JsonMap expectedResolutionInfo = JsonMap.newBuilder() .put("type", "user_dismissed") .put("display_time", Event.millisecondsToSecondsString(3500)) .build(); verifyEvent(expectedResolutionInfo, event); }
@Test public void testTimedOutResolutionEvent() throws JSONException { ResolutionEvent event = ResolutionEvent.messageResolution("schedule ID", message, ResolutionInfo.timedOut(), 15000); JsonMap expectedResolutionInfo = JsonMap.newBuilder() .put("type", "timed_out") .put("display_time", Event.millisecondsToSecondsString(15000)) .build(); verifyEvent(expectedResolutionInfo, event); }