FoamMain { void initializeServices() { for (Map.Entry<ServiceType, Service> entry : services.entrySet()) { ServiceType serviceType = entry.getKey(); Service service = entry.getValue(); String apiKey = null; if (serviceType == ServiceType.PAGERDUTY) { apiKey = foamApiKeys.pagerDuty(); } else if (serviceType == ServiceType.HOCKEYAPP) { apiKey = foamApiKeys.hockeyApp(); } else if (serviceType == ServiceType.PAPERTRAIL) { apiKey = foamApiKeys.papertrail(); } else if (serviceType == ServiceType.LOGENTRIES) { apiKey = foamApiKeys.logentries(); } else if (serviceType == ServiceType.MIXPANEL) { apiKey = foamApiKeys.mixpanel(); } else if (serviceType == ServiceType.GOOGLE_ANALYTICS) { apiKey = foamApiKeys.googleAnalytics(); } else if (serviceType == ServiceType.FLURRY) { if (((Flurry) service).checkForJar()) { apiKey = foamApiKeys.flurry(); } } else if(serviceType == ServiceType.GRAPHITE){ apiKey = foamApiKeys.graphite(); } if(new Utils().isNotBlank(apiKey)){ service.enable(apiKey); } } } FoamMain(Context context);   }
@Test public void testInitializeServices() { Flurry flurryMock = mock(Flurry.class); when(flurryMock.checkForJar()).thenReturn(true); Map<ServiceType, Service> mockServices = new HashMap<>(); mockServices.put(ServiceType.PAGERDUTY, mock(PagerDuty.class)); mockServices.put(ServiceType.HOCKEYAPP, mock(HockeyApp.class)); mockServices.put(ServiceType.PAPERTRAIL, mock(PaperTrail.class)); mockServices.put(ServiceType.MIXPANEL, mock(Mixpanel.class)); mockServices.put(ServiceType.GOOGLE_ANALYTICS, mock(GoogleAnalytics.class)); mockServices.put(ServiceType.FLURRY, flurryMock); mockServices.put(ServiceType.LOGENTRIES, mock(LogEntries.class)); mockServices.put(ServiceType.GRAPHITE, mock(Graphite.class)); FoamApiKeys mockApiKeys = mock(FoamApiKeys.class); when(mockApiKeys.pagerDuty()).thenReturn("test_pagerDuty_key"); when(mockApiKeys.hockeyApp()).thenReturn("test_hockeyApp_key"); when(mockApiKeys.papertrail()).thenReturn("test_papertrail_key"); when(mockApiKeys.mixpanel()).thenReturn("test_mixpanel_key"); when(mockApiKeys.googleAnalytics()).thenReturn("test_googleAnalytics_key"); when(mockApiKeys.flurry()).thenReturn("test_flurry_key"); when(mockApiKeys.logentries()).thenReturn("test_logentries_key"); when(mockApiKeys.graphite()).thenReturn("test_graphite_key"); FoamMain foamMain = new FoamMain(null); foamMain.foamApiKeys = mockApiKeys; foamMain.services.putAll(mockServices); foamMain.initializeServices(); verify(mockServices.get(ServiceType.PAGERDUTY)).enable("test_pagerDuty_key"); verify(mockServices.get(ServiceType.HOCKEYAPP)).enable("test_hockeyApp_key"); verify(mockServices.get(ServiceType.PAPERTRAIL)).enable("test_papertrail_key"); verify(mockServices.get(ServiceType.MIXPANEL)).enable("test_mixpanel_key"); verify(mockServices.get(ServiceType.GOOGLE_ANALYTICS)).enable("test_googleAnalytics_key"); verify(mockServices.get(ServiceType.FLURRY)).enable("test_flurry_key"); verify(mockServices.get(ServiceType.LOGENTRIES)).enable("test_logentries_key"); verify(mockServices.get(ServiceType.GRAPHITE)).enable("test_graphite_key"); }
@Test public void testStartNoFlurryJar() { Flurry flurryMock = mock(Flurry.class); when(flurryMock.checkForJar()).thenReturn(false); FoamApiKeys mockApiKeys = mock(FoamApiKeys.class); when(mockApiKeys.flurry()).thenReturn("test_flurry_key"); FoamMain foamMain = new FoamMain(null); foamMain.foamApiKeys = mockApiKeys; foamMain.services.put(ServiceType.FLURRY, flurryMock); foamMain.initializeServices(); verify(flurryMock, never()).enable("test_flurry_key"); }