public void trackEvent(String eventName) { trackEvent(new Event(eventName, null, null, null, superAttributes)); }
@Override public void onAspectEventTriggered(TrackEvent trackEvent, Map<String, Object> attributes) { trackEvent(new Event(trackEvent, attributes, superAttributes)); }
public void trackEvent(String eventName, Map<String, Object> attributes) { trackEvent(new Event(eventName, null, null, attributes, superAttributes)); }
@Test public void trackWithoutAnnotation() { Map<String, Object> attributes = new HashMap<>(); attributes.put("key", "value"); tracklytics.trackEvent("event_name", attributes); verify(eventSubscriber).onEventTracked(eventCaptor.capture()); assertThat(eventCaptor.getValue().name).isEqualTo("event_name"); assertThat(eventCaptor.getValue().attributes).containsExactly("key", "value"); }
@Test public void log() throws Throwable { EventLogListener logger = mock(EventLogListener.class); tracklytics.setEventLogListener(logger); Map<String, Object> attributes = new HashMap<>(); attributes.put("key", "value"); tracklytics.trackEvent("event", attributes); verify(logger).log("event-> {key=value}, super attrs: {}, filters: null"); } }
@Test public void trackWithEvent() { tracklytics.trackEvent("event_name"); verify(eventSubscriber).onEventTracked(eventCaptor.capture()); assertThat(eventCaptor.getValue().name).isEqualTo("event_name"); assertThat(eventCaptor.getValue().attributes).isNull(); }
@Test public void addSuperAttributesToEvent() { tracklytics.addSuperAttribute("key1", "value1"); tracklytics.addSuperAttribute("key2", "value2"); Map<String, Object> attributes = new HashMap<>(); attributes.put("key3", "value3"); tracklytics.trackEvent("event_name", attributes); verify(eventSubscriber).onEventTracked(eventCaptor.capture()); assertThat(eventCaptor.getValue().name).isEqualTo("event_name"); assertThat(eventCaptor.getValue().attributes).containsExactly("key3", "value3"); assertThat(eventCaptor.getValue().superAttributes).containsExactly("key1", "value1", "key2", "value2"); }
@Test public void addSuperAttributeFromAspects() { tracklytics.onAspectSuperAttributeAdded("key1", "value1"); tracklytics.trackEvent("event_name"); verify(eventSubscriber).onEventTracked(eventCaptor.capture()); assertThat(eventCaptor.getValue().name).isEqualTo("event_name"); assertThat(eventCaptor.getValue().superAttributes).containsExactly("key1", "value1"); }
@Test public void removeSuperAttributeFromAspects() { tracklytics.addSuperAttribute("key1", "value1"); tracklytics.addSuperAttribute("key2", "value2"); tracklytics.onAspectSuperAttributeRemoved("key1"); tracklytics.trackEvent("event_name"); verify(eventSubscriber).onEventTracked(eventCaptor.capture()); assertThat(eventCaptor.getValue().name).isEqualTo("event_name"); assertThat(eventCaptor.getValue().superAttributes).containsExactly("key2", "value2"); }
@Test public void removeSuperAttributes() { tracklytics.addSuperAttribute("key1", "value1"); tracklytics.addSuperAttribute("key2", "value2"); tracklytics.addSuperAttribute("key3", "value3"); tracklytics.removeSuperAttribute("key1"); tracklytics.removeSuperAttribute("key2"); Map<String, Object> attributes = new HashMap<>(); attributes.put("key4", "value4"); tracklytics.trackEvent("event_name", attributes); verify(eventSubscriber).onEventTracked(eventCaptor.capture()); assertThat(eventCaptor.getValue().name).isEqualTo("event_name"); assertThat(eventCaptor.getValue().attributes).containsExactly("key4", "value4"); assertThat(eventCaptor.getValue().superAttributes).containsExactly("key3", "value3"); }