### Question:
ConfigCenter { @Bean("governanceConfiguration") GovernanceConfiguration getDynamicConfiguration() { GovernanceConfiguration dynamicConfiguration = null; if (StringUtils.isNotEmpty(configCenter)) { configCenterUrl = formUrl(configCenter, configCenterGroup, username, password); dynamicConfiguration = ExtensionLoader.getExtensionLoader(GovernanceConfiguration.class).getExtension(configCenterUrl.getProtocol()); dynamicConfiguration.setUrl(configCenterUrl); dynamicConfiguration.init(); String config = dynamicConfiguration.getConfig(Constants.GLOBAL_CONFIG_PATH); if (StringUtils.isNotEmpty(config)) { Arrays.stream(config.split("\n")).forEach( s -> { if(s.startsWith(Constants.REGISTRY_ADDRESS)) { String registryAddress = s.split("=")[1].trim(); registryUrl = formUrl(registryAddress, configCenterGroup, username, password); } else if (s.startsWith(Constants.METADATA_ADDRESS)) { metadataUrl = formUrl(s.split("=")[1].trim(), configCenterGroup, username, password); } }); } } if (dynamicConfiguration == null) { if (StringUtils.isNotEmpty(registryAddress)) { registryUrl = formUrl(registryAddress, registryGroup, username, password); dynamicConfiguration = ExtensionLoader.getExtensionLoader(GovernanceConfiguration.class).getExtension(registryUrl.getProtocol()); dynamicConfiguration.setUrl(registryUrl); dynamicConfiguration.init(); logger.warn("you are using dubbo.registry.address, which is not recommend, please refer to: https: } else { throw new ConfigurationException("Either config center or registry address is needed, please refer to https: } } return dynamicConfiguration; }    }### Answer:
@Test public void testGetDynamicConfiguration() throws Exception { ReflectionTestUtils.setField(configCenter, "configCenter", zkAddress); ReflectionTestUtils.setField(configCenter, "configCenterGroup", "dubbo"); ReflectionTestUtils.setField(configCenter, "username", "username"); ReflectionTestUtils.setField(configCenter, "password", "password"); configCenter.getDynamicConfiguration(); zkClient.createContainers("/dubbo/config/dubbo/dubbo.properties"); zkClient.setData().forPath("/dubbo/config/dubbo/dubbo.properties", "dubbo.registry.address=zookeeper: configCenter.getDynamicConfiguration(); Object registryUrl = ReflectionTestUtils.getField(configCenter, "registryUrl"); assertNotNull(registryUrl); assertEquals("test-registry.com", ((URL) registryUrl).getHost()); zkClient.setData().forPath("/dubbo/config/dubbo/dubbo.properties", "dubbo.metadata-report.address=zookeeper: configCenter.getDynamicConfiguration(); Object metadataUrl = ReflectionTestUtils.getField(configCenter, "metadataUrl"); assertNotNull(metadataUrl); assertEquals("test-metadata.com", ((URL) metadataUrl).getHost()); zkClient.setData().forPath("/dubbo/config/dubbo/dubbo.properties", "".getBytes()); ReflectionTestUtils.setField(configCenter, "registryUrl", null); ReflectionTestUtils.setField(configCenter, "metadataUrl", null); configCenter.getDynamicConfiguration(); assertNull(ReflectionTestUtils.getField(configCenter, "registryUrl")); assertNull(ReflectionTestUtils.getField(configCenter, "metadataUrl")); ReflectionTestUtils.setField(configCenter, "configCenter", null); ReflectionTestUtils.setField(configCenter, "registryAddress", zkAddress); configCenter.getDynamicConfiguration(); registryUrl = ReflectionTestUtils.getField(configCenter, "registryUrl"); assertNotNull(registryUrl); assertEquals("127.0.0.1", ((URL) registryUrl).getHost()); try { ReflectionTestUtils.setField(configCenter, "configCenter", null); ReflectionTestUtils.setField(configCenter, "registryAddress", null); configCenter.getDynamicConfiguration(); fail("should throw exception when configCenter, registryAddress are all null"); } catch (ConfigurationException e) { } }