LogListener { protected void processLogEntries(List<String> logs) { if(!wifiOnly || utils.isOnWifi(context)) { for (String log : logs) { if (log != null && log.startsWith("E")) { for (LoggingService service : services) { if (service.isEnabled()) { service.logEvent(log); } } } } } } LogListener(Context context, List<LoggingService> services, boolean wifiOnly); void start();  }
@Test public void testProcessLogEntries() { LoggingService mockService = mock(LoggingService.class); when(mockService.isEnabled()).thenReturn(true); List<LoggingService> mockServices = new ArrayList<>(); mockServices.add(mockService); LogListener logListener = new LogListener(null, mockServices, false); List<String> logs = new ArrayList<>(); logs.add("D/Testing Debug Message"); logs.add("I/Testing Info Message"); logs.add("W/Testing Warning Message"); logs.add("E/Testing Error Message"); logListener.processLogEntries(logs); verify(mockService).logEvent(logs.get(3)); verify(mockService, times(1)).logEvent(anyString()); }