@Override public void onAspectSuperAttributeAdded(String key, Object value) { addSuperAttribute(key, value); }
@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 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"); }