Event { @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull public String createEventPayload(@NonNull String sessionId) { JsonMap.Builder object = JsonMap.newBuilder(); JsonMap data = getEventData(); data = JsonMap.newBuilder() .putAll(data) .put(SESSION_ID_KEY, sessionId) .build(); object.put(TYPE_KEY, getType()) .put(EVENT_ID_KEY, eventId) .put(TIME_KEY, time) .put(DATA_KEY, data); return object.build().toString(); } Event(long timeMS);  Event(); @NonNull String getEventId(); @NonNull String getTime(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull String createEventPayload(@NonNull String sessionId); @NonNull abstract String getType(); @NonNull @VisibleForTesting @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) abstract JsonMap getEventData(); @NonNull String getConnectionType(); @NonNull String getConnectionSubType(); boolean isValid(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull static String millisecondsToSecondsString(long milliseconds); @Priority int getPriority(); static final int LOW_PRIORITY; static final int NORMAL_PRIORITY; static final int HIGH_PRIORITY; }
@Test public void testCreateEventPayload() throws JsonException { JsonMap body = JsonValue.parseString(event.createEventPayload("session id")).optMap(); assertEquals(body.get(Event.TYPE_KEY).getString(), event.getType()); assertEquals(body.get(Event.EVENT_ID_KEY).getString(), event.getEventId()); assertEquals(body.get(Event.TIME_KEY).getString(), event.getTime()); assertEquals(body.get(Event.DATA_KEY).optMap().get(Event.SESSION_ID_KEY).getString(), "session id"); assertEquals(body.get(Event.DATA_KEY).optMap().get("some key").getString(), "some value"); }