AnalyticsManager { public void logEvent(Map<String, Object> data, String eventName, Action action, String context) { analyticsLogger.logDebug(TAG, "logEvent() called with: " + "eventName = [" + eventName + "], data = [" + data + "], action = [" + action + "], context = [" + context + "]"); int eventsSent = 0; data = analyticsNormalizer.normalize(data); for (Map.Entry<EventLogger, Collection<String>> loggerEntry : eventLoggers.entrySet()) { if (loggerEntry.getValue() .contains(eventName)) { loggerEntry.getKey() .log(eventName, data, action, context); eventsSent++; } } if (eventsSent <= 0) { analyticsLogger.logWarningDebug(TAG, eventName + " event not sent "); } } private  AnalyticsManager(KnockEventLogger knockLogger,
      Map<EventLogger, Collection<String>> eventLoggers, List<SessionLogger> sessionLoggers,
      KeyValueNormalizer analyticsNormalizer, AnalyticsLogger analyticsLogger); void logEvent(Map<String, Object> data, String eventName, Action action, String context); void logEvent(String url); void setup(); void startSession(); void endSession();  }
@Test public void sendSupportedEvent() { String eventName = "TestEvent"; EventLogger eventLogger = Mockito.mock(EventLogger.class); KnockEventLogger knockEventLogger = Mockito.mock(KnockEventLogger.class); KeyValueNormalizer analyticsNormalizer = Mockito.mock(KeyValueNormalizer.class); AnalyticsLogger debugLogger = Mockito.mock(AnalyticsLogger.class); AnalyticsManager analyticsManager = new AnalyticsManager.Builder().addLogger(eventLogger, Arrays.asList(eventName)) .setKnockLogger(knockEventLogger) .setAnalyticsNormalizer(analyticsNormalizer) .setDebugLogger(debugLogger) .build(); Map<String, Object> data = new HashMap<>(); AnalyticsManager.Action action = AnalyticsManager.Action.OPEN; String context = "timeline"; analyticsManager.logEvent(data, eventName, action, context); Mockito.verify(eventLogger) .log(eventName, data, action, context); }
@Test public void sendUnsupportedEvent() { String eventName = "TestEvent"; EventLogger eventLogger = Mockito.mock(EventLogger.class); KnockEventLogger knockEventLogger = Mockito.mock(KnockEventLogger.class); KeyValueNormalizer analyticsNormalizer = Mockito.mock(KeyValueNormalizer.class); AnalyticsLogger debugLogger = Mockito.mock(AnalyticsLogger.class); AnalyticsManager analyticsManager = new AnalyticsManager.Builder().addLogger(eventLogger, Arrays.asList(eventName)) .setKnockLogger(knockEventLogger) .setAnalyticsNormalizer(analyticsNormalizer) .setDebugLogger(debugLogger) .build(); Map<String, Object> data = new HashMap<>(); AnalyticsManager.Action action = AnalyticsManager.Action.OPEN; String context = "timeline"; analyticsManager.logEvent(data, "Unsupported event", action, context); Mockito.verify(eventLogger, Mockito.times(0)) .log(eventName, data, action, context); }