CustomEvent extends Event implements JsonSerializable { @NonNull public static Builder newBuilder(@NonNull String name) { return new Builder(name); } private  CustomEvent(@NonNull Builder builder); @NonNull static Builder newBuilder(@NonNull String name); @NonNull String getEventName(); @Nullable BigDecimal getEventValue(); @Nullable String getTransactionId(); @Nullable String getInteractionType(); @Nullable String getInteractionId(); @NonNull JsonMap getProperties(); @NonNull @Override final String getType(); @NonNull @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) final JsonMap getEventData(); @NonNull @Override JsonValue toJsonValue(); @Override boolean isValid(); @NonNull CustomEvent track(); @NonNull
    static final String INTERACTION_ID; @NonNull
    static final String INTERACTION_TYPE; @NonNull
    static final String EVENT_NAME; @NonNull
    static final String EVENT_VALUE; @NonNull
    static final String TRANSACTION_ID; @NonNull
    static final String MCRAP_TRANSACTION_TYPE; @NonNull
    static final String CONVERSION_SEND_ID; @NonNull
    static final String CONVERSION_METADATA; @NonNull
    static final String LAST_RECEIVED_METADATA; @NonNull
    static final String TEMPLATE_TYPE; @NonNull
    static final String PROPERTIES; static final int MAX_CHARACTER_LENGTH; static final int MAX_TOTAL_PROPERTIES_SIZE; }
@Test public void testHardConversionId() throws JSONException { CustomEvent event = CustomEvent.newBuilder("event name").build(); when(analytics.getConversionSendId()).thenReturn("send id"); EventTestUtils.validateEventValue(event, "conversion_send_id", "send id"); }
@Test public void testHardConversionMetadata() throws JSONException { CustomEvent event = CustomEvent.newBuilder("event name").build(); when(analytics.getConversionMetadata()).thenReturn("metadata"); EventTestUtils.validateEventValue(event, "conversion_metadata", "metadata"); }
@Test public void testLastMetadata() throws JSONException { when(pushManager.getLastReceivedMetadata()).thenReturn("last metadata"); CustomEvent event = CustomEvent.newBuilder("event name").build(); EventTestUtils.validateEventValue(event, "last_received_metadata", "last metadata"); }
@Test public void testHardConversionMetadataAndLastMetadata() throws JSONException { when(analytics.getConversionMetadata()).thenReturn("metadata"); when(pushManager.getLastReceivedMetadata()).thenReturn("last metadata"); CustomEvent event = CustomEvent.newBuilder("event name").build(); EventTestUtils.validateEventValue(event, "last_received_metadata", null); EventTestUtils.validateEventValue(event, "conversion_metadata", "metadata"); }
@Test public void testInteractionFromMessage() throws JSONException { CustomEvent event = CustomEvent.newBuilder("event name") .setMessageCenterInteraction("message id") .build(); EventTestUtils.validateEventValue(event, "interaction_id", "message id"); EventTestUtils.validateEventValue(event, "interaction_type", "ua_mcrap"); }
@Test public void testCustomInteraction() throws JSONException { CustomEvent event = CustomEvent.newBuilder("event name") .setInteraction("interaction type", "interaction id") .build(); EventTestUtils.validateEventValue(event, "interaction_id", "interaction id"); EventTestUtils.validateEventValue(event, "interaction_type", "interaction type"); }
@Test public void testCustomInteractionNullID() throws JSONException { CustomEvent event = CustomEvent.newBuilder("event name") .setInteraction("interaction type", null) .build(); EventTestUtils.validateEventValue(event, "interaction_id", null); EventTestUtils.validateEventValue(event, "interaction_type", "interaction type"); }
@Test public void testCustomInteractionNullType() throws JSONException { CustomEvent event = CustomEvent.newBuilder("event name") .setInteraction(null, "interaction id") .build(); EventTestUtils.validateEventValue(event, "interaction_type", null); EventTestUtils.validateEventValue(event, "interaction_id", "interaction id"); }
@Test public void testCustomInteractionEmpty() throws JSONException { when(pushManager.getLastReceivedMetadata()).thenReturn("last metadata"); CustomEvent event = CustomEvent.newBuilder("event name") .build(); EventTestUtils.validateEventValue(event, "interaction_type", null); EventTestUtils.validateEventValue(event, "interaction_id", null); EventTestUtils.validateEventValue(event, "template_type", null); }
@Test public void testSetEventValue() throws JSONException { CustomEvent event; event = CustomEvent.newBuilder("event name").setEventValue(Integer.MAX_VALUE).build(); EventTestUtils.validateEventValue(event, "event_value", 2147483647000000L); event = CustomEvent.newBuilder("event name").setEventValue(Integer.MIN_VALUE).build(); EventTestUtils.validateEventValue(event, "event_value", -2147483648000000L); event = CustomEvent.newBuilder("event name").setEventValue(0).build(); EventTestUtils.validateEventValue(event, "event_value", 0); event = CustomEvent.newBuilder("event name").setEventValue(Double.MIN_VALUE).build(); EventTestUtils.validateEventValue(event, "event_value", 0); event = CustomEvent.newBuilder("event name").setEventValue((double) Integer.MAX_VALUE).build(); EventTestUtils.validateEventValue(event, "event_value", 2147483647000000L); event = CustomEvent.newBuilder("event name").setEventValue((double) Integer.MIN_VALUE).build(); EventTestUtils.validateEventValue(event, "event_value", -2147483648000000L); event = CustomEvent.newBuilder("event name").setEventValue(String.valueOf(Integer.MAX_VALUE)).build(); EventTestUtils.validateEventValue(event, "event_value", 2147483647000000L); event = CustomEvent.newBuilder("event name").setEventValue(String.valueOf(Integer.MIN_VALUE)).build(); EventTestUtils.validateEventValue(event, "event_value", -2147483648000000L); event = CustomEvent.newBuilder("event name").setEventValue("0").build(); EventTestUtils.validateEventValue(event, "event_value", 0); event = CustomEvent.newBuilder("event name").setEventValue((String) null).build(); EventTestUtils.validateEventValue(event, "event_value", null); event = CustomEvent.newBuilder("event name").setEventValue(new BigDecimal(123)).build(); EventTestUtils.validateEventValue(event, "event_value", 123000000L); BigDecimal maxDecimal = new BigDecimal(Integer.MAX_VALUE); event = CustomEvent.newBuilder("event name").setEventValue(maxDecimal).build(); EventTestUtils.validateEventValue(event, "event_value", 2147483647000000L); BigDecimal minDecimal = new BigDecimal(Integer.MIN_VALUE); event = CustomEvent.newBuilder("event name").setEventValue(minDecimal).build(); EventTestUtils.validateEventValue(event, "event_value", -2147483648000000L); event = CustomEvent.newBuilder("event name").setEventValue((BigDecimal) null).build(); EventTestUtils.validateEventValue(event, "event_value", null); }
@Test public void testSetEventValuePositiveInfinity() { exception.expect(NumberFormatException.class); CustomEvent.newBuilder("event name").setEventValue(Double.POSITIVE_INFINITY); }
@Test public void testSetEventValueNegativeInfiinty() { exception.expect(NumberFormatException.class); CustomEvent.newBuilder("event name").setEventValue(Double.NEGATIVE_INFINITY); }
@Test public void testSetEventValueDoubleNAN() { exception.expect(NumberFormatException.class); CustomEvent.newBuilder("event name").setEventValue(Double.NaN); }
@Test public void testEventValueStringNAN() { exception.expect(NumberFormatException.class); CustomEvent.newBuilder("event name").setEventValue("not a number!"); }
@Test public void testAttributionFromPushMessage() throws JSONException { Bundle pushBundle = new Bundle(); pushBundle.putString(PushMessage.EXTRA_SEND_ID, "send id"); PushMessage pushMessage = new PushMessage(pushBundle); CustomEvent event = CustomEvent.newBuilder("event name") .setAttribution(pushMessage) .build(); EventTestUtils.validateEventValue(event, "conversion_send_id", "send id"); }