### Question:
XRaySDKConfiguration { public void init(@Nullable URL configFile) { if (configFile == null) { this.agentConfiguration = new AgentConfiguration(); } else { try { log.info("Reading X-Ray Agent config file at: " + configFile.getPath()); this.agentConfiguration = parseConfig(configFile); } catch (IOException e) { throw new InvalidAgentConfigException("Failed to read X-Ray Agent configuration file " + configFile.getPath(), e); } } if (log.isDebugEnabled()) { log.debug("Starting the X-Ray Agent with the following properties:\n" + agentConfiguration.toString()); } init(AWSXRayRecorderBuilder.standard()); } XRaySDKConfiguration(); int getAwsSdkVersion(); @Nullable URL getAwsServiceHandlerManifest(); boolean isEnabled(); boolean shouldCollectSqlQueries(); boolean isTraceIncomingRequests(); static XRaySDKConfiguration getInstance(); void init(@Nullable URL configFile); void init();  }### Answer:
@Test(expected = InvalidAgentConfigException.class) public void testInitWithNonexistentFile() throws MalformedURLException { config.init(new File("/some/nonexistent/file").toURI().toURL()); }
@Test(expected = InvalidAgentConfigException.class) public void testInitWithMalformedFile() { config.init(XRaySDKConfigurationTest.class.getResource("/com/amazonaws/xray/agent/malformedAgentConfig.json")); }
@Test public void testEnvTracingDisabled() { AWSXRayRecorderBuilder builderMock = mock(AWSXRayRecorderBuilder.class); environmentVariables.set(XRaySDKConfiguration.ENABLED_ENVIRONMENT_VARIABLE_KEY, "false"); System.setProperty(XRaySDKConfiguration.ENABLED_SYSTEM_PROPERTY_KEY, "true"); config.init(builderMock); Assert.assertNull(XRayTransactionState.getServiceName()); verify(builderMock, never()).build(); }
@Test public void testSysTracingDisabled() { AWSXRayRecorderBuilder builderMock = mock(AWSXRayRecorderBuilder.class); System.setProperty(XRaySDKConfiguration.ENABLED_SYSTEM_PROPERTY_KEY, "false"); config.init(builderMock); Assert.assertNull(XRayTransactionState.getServiceName()); verify(builderMock, never()).build(); }
@Test public void testDefaultServiceName() { config.init(); Assert.assertEquals(AgentConfiguration.DEFAULT_SERVICE_NAME, XRayTransactionState.getServiceName()); }
@Test public void testPluginsEnabledByDefault() { AWSXRayRecorderBuilder builderMock = mock(AWSXRayRecorderBuilder.class); config.init(builderMock); verify(builderMock).withDefaultPlugins(); }
@Test public void testDefaultContextMissingStrategy() { config.init(); Assert.assertTrue(AWSXRay.getGlobalRecorder().getContextMissingStrategy() instanceof LogErrorContextMissingStrategy); }
@Test public void testDefaultSamplingStrategy() { config.init(); Assert.assertTrue(AWSXRay.getGlobalRecorder().getSamplingStrategy() instanceof CentralizedSamplingStrategy); }
@Test public void testTraceIdInjection() { config.init(AWSXRayRecorderBuilder.standard()); Log4JSegmentListener listener = (Log4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0); Assert.assertEquals(2, AWSXRay.getGlobalRecorder().getSegmentListeners().size()); Assert.assertEquals("", listener.getPrefix()); }
@Test public void testDefaultContextPropagation() { config.init(); Assert.assertTrue(AWSXRay.getGlobalRecorder().getSegmentContextResolverChain().resolve() instanceof XRayTransactionContext); }