// Suppress non relevant warning due to mockito internal stuff @SuppressWarnings("unchecked") private AppInsightsConfigurationBuilder createMockParser( boolean withChannel, boolean setChannel, boolean withPerformanceModules) { AppInsightsConfigurationBuilder mockParser = Mockito.mock(AppInsightsConfigurationBuilder.class); ApplicationInsightsXmlConfiguration appConf = new ApplicationInsightsXmlConfiguration(); appConf.setSdkLogger(new SDKLoggerXmlElement()); if (withChannel) { ChannelXmlElement channelXmlElement = new ChannelXmlElement(); channelXmlElement.setEndpointAddress(MOCK_ENDPOINT); String channelType = null; if (setChannel) { channelType = "com.microsoft.applicationinsights.internal.channel.stdout.StdOutChannel"; channelXmlElement.setType(channelType); } appConf.setChannel(channelXmlElement); } if (withPerformanceModules) { PerformanceCountersXmlElement performanceCountersXmlElement = new PerformanceCountersXmlElement(); appConf.setPerformance(performanceCountersXmlElement); } Mockito.doReturn(appConf).when(mockParser).build(any(InputStream.class)); return mockParser; }
@Test public void testDefaultChannelWithBadData() { AppInsightsConfigurationBuilder mockParser = createMockParserWithDefaultChannel(true); ApplicationInsightsXmlConfiguration appConf = mockParser.build(null); appConf.setInstrumentationKey(MOCK_IKEY); ChannelXmlElement channelXmlElement = appConf.getChannel(); channelXmlElement.setEndpointAddress(NON_VALID_URL); channelXmlElement.setDeveloperMode(true); TelemetryConfiguration mockConfiguration = new TelemetryConfiguration(); initializeWithFactory(mockParser, mockConfiguration); assertEquals(mockConfiguration.getChannel().isDeveloperMode(), false); }