### Question:
ProviderDelegatingRegister { public void register() throws Exception { String parentNode = String.join("/", Constants.STORE_ROOT, application.getServerGroup()); ProviderInfo providerInfo = Optional.ofNullable(application.getProviderInfo()) .orElse(new ProviderInfo()); if (providerInfo.getIp() == null) { InetAddress address = HostUtil.getLocalIv4Address(); if (address != null) providerInfo.setIp(address.getHostAddress()); else throw new IllegalStateException("cannot get local host IP address"); } if (providerInfo.getPort() == 0 || providerInfo.getName() == null) { throw new IllegalArgumentException("please check you provider info"); } String storeValue = String.format("%s/%s/%s", providerInfo.getIp(), providerInfo.getPort(), providerInfo.getWeight()); String storeKey = String.join("/", parentNode, providerInfo.getName()); store.createParentNode(parentNode); long reversion = store.put(storeKey, storeValue, true); log.info(String.format("registered server: `%s` in node: `%s`, reversion: %s", storeKey, storeValue, reversion)); } ProviderDelegatingRegister(KVStore store, Application application); void register();  }### Answer:
@Test public void testInitIp() throws Exception { ProviderInfo providerInfo = new ProviderInfo("test-name", 22); assertNull(providerInfo.getIp()); Application application = new Application(null, providerInfo, "test-group"); DemoKvStore store = new DemoKvStore(); new ProviderDelegatingRegister(store, application).register(); assertNotNull(providerInfo.getIp()); }
@Test public void testIllegal() throws Exception { ProviderInfo providerInfo = new ProviderInfo("test-name", 0); Application application = new Application(null, providerInfo, "test-group"); DemoKvStore store = new DemoKvStore(); try { new ProviderDelegatingRegister(store, application).register(); fail(); } catch (Throwable ignored) { } providerInfo.setPort(22); new ProviderDelegatingRegister(store, application).register(); application.setServerGroup(null); try { new ProviderDelegatingRegister(store, application).register(); fail(); } catch (Throwable ignored) { } }
@Test public void register() throws Exception { ProviderInfo providerInfo = new ProviderInfo("test-name", "test-ip", 22); assertEquals(0, providerInfo.getWeight()); DemoKvStore store = new DemoKvStore(); Application application = new Application(null, providerInfo, "test-group"); ProviderDelegatingRegister register = new ProviderDelegatingRegister(store, application); register.register(); String key = Constants.STORE_ROOT + "/test-group/test-name"; Node node = store.get(key); ProviderInfo newProviderInfo = MapperUtil.node2Provider(node); assertEquals(providerInfo, newProviderInfo); assertTrue(store.keyEphemeral.get(key)); }