@Test public void ignoreNullValuesOnTrackable() throws Throwable { class Bar implements Trackable { @Override public Map<String, Object> getTrackableAttributes() { return null; } } class Foo { @TrackEvent("title") public void foo(@TrackableAttribute Bar bar) { } } when(joinPoint.getArgs()).thenReturn(new Object[]{new Bar()}); invokeMethod(Foo.class, "foo", Bar.class); assertTrack() .event("title") .noFilters() .noTags() .noAttributes(); }
@Test public void trackEventWithoutAttributes() throws Throwable { class Foo { @TrackEvent("title") public void foo() { } } invokeMethod(Foo.class, "foo"); ArgumentCaptor<Map> argument = ArgumentCaptor.forClass(Map.class); assertTrack() .event("title") .noFilters() .noTags() .noAttributes(); }
@Test public void doNotUseTrackableAttributesWhenTrackableAttributeNotExists() throws Throwable { class Foo implements Trackable { @Override public Map<String, Object> getTrackableAttributes() { Map<String, Object> map = new HashMap<>(); map.put("key", "value"); return map; } @TrackEvent("event") public void foo() { } } when(joinPoint.getThis()).thenReturn(new Foo()); invokeMethod(Foo.class, "foo"); assertTrack() .event("event") .noFilters() .noTags() .noAttributes(); }
@Test public void ignoreNullValueOnTrackableAttributeForCurrentClass() throws Throwable { class Foo implements Trackable { @Override public Map<String, Object> getTrackableAttributes() { return null; } @TrackEvent("event") @TrackableAttribute public void foo() { } } initMethod(Foo.class, "foo"); when(joinPoint.getThis()).thenReturn(new Foo()); aspect.weaveJoinPointTrackEvent(joinPoint); assertTrack() .event("event") .noFilters() .noTags() .noAttributes(); }
@Test public void filters() throws Throwable { class Foo { @TrackEvent(value = "event", filters = {100, 200}) public void foo() { } } invokeMethod(Foo.class, "foo"); int[] tags = {100, 200}; assertTrack() .event("event") .noTags() .filters(100, 200) .noAttributes(); }
@Test public void tags() throws Throwable { class Foo { @TrackEvent(value = "event", tags = {"abc", "123"}) public void foo() { } } invokeMethod(Foo.class, "foo"); int[] tags = {100, 200}; assertTrack() .event("event") .noFilters() .tags("abc", "123") .noAttributes(); }