private void initializeWithFactory( AppInsightsConfigurationBuilder mockParser, TelemetryConfiguration mockConfiguration) { Field field = null; try { field = ClassDataUtils.class.getDeclaredField("verifier"); field.setAccessible(true); ClassDataVerifier mockVerifier = Mockito.mock(ClassDataVerifier.class); Mockito.doReturn(true).when(mockVerifier).verifyClassExists(anyString()); field.set(ClassDataUtils.INSTANCE, mockVerifier); TelemetryConfigurationFactory.INSTANCE.setBuilder(mockParser); TelemetryConfigurationFactory.INSTANCE.initialize(mockConfiguration); } catch (NoSuchFieldException e) { throw new RuntimeException(); } catch (IllegalAccessException e) { throw new RuntimeException(); } }
@Test public void testPerformanceModules() { AppInsightsConfigurationBuilder mockParser = createMockParser(true, true, true); ApplicationInsightsXmlConfiguration appConf = mockParser.build(null); appConf.setInstrumentationKey(MOCK_IKEY); appConf.getChannel().setDeveloperMode(true); TelemetryConfigurationFactory.INSTANCE.setPerformanceCountersSection( "com.microsoft.applicationinsights.internal.config"); TelemetryConfiguration mockConfiguration = new TelemetryConfiguration(); initializeWithFactory(mockParser, mockConfiguration); assertEquals(mockConfiguration.getTelemetryModules().size(), 1); assertTrue(mockConfiguration.getTelemetryModules().get(0) instanceof MockPerformanceModule); assertTrue( ((MockPerformanceModule) mockConfiguration.getTelemetryModules().get(0)) .initializeWasCalled); assertTrue( ((MockPerformanceModule) mockConfiguration.getTelemetryModules().get(0)) .addConfigurationDataWasCalled); }