GoogleAnalyticsTracker implements TrackerAdapter { @Override public void logEvent(Map<String, Object> eventData) { final String category = (String)eventData.get(Constants.EVENT_CATEGORY); final String action = (String)eventData.get(Constants.EVENT_ACTION); final String label = (String)eventData.get(Constants.EVENT_LABEL); final String campaignUrl = (String)eventData.get(Constants.EVENT_CAMPAIGN_URL); final Long value = (Long)eventData.get(Constants.EVENT_VALUE); this.logEvent(category, action, label, value == null ? 0 : value, campaignUrl); } GoogleAnalyticsTracker(Tracker tracker); @Override void logPageView(String name); @Override void logEvent(Map<String, Object> eventData); @Override void setUserProperty(String key, Object value); @Override void logException(Throwable e);  }
@SuppressWarnings("unchecked") @Test public void testLogEvent() { HashMap<String, Object> eventValue = new HashMap<>(); eventValue.put(EVENT_CATEGORY, "testCategory"); eventValue.put(EVENT_ACTION, "testAction"); eventValue.put(EVENT_LABEL, "testLabel"); ArgumentCaptor<HashMap> event = ArgumentCaptor.forClass(HashMap.class); this.subject.logEvent(eventValue); verify(this.tracker).send(event.capture()); eventValue = event.getValue(); assertTrue(eventValue.containsValue("testCategory")); assertTrue(eventValue.containsValue("testLabel")); assertTrue(eventValue.containsValue("testAction")); }