### Question:
TargetResolverService implements TargetResolver { @Override public Target resolveTarget(URI uri) { ensureInitialized(); if (uri == null) { return new Target(uri, TargetType.UNKNOWN); } if (illegalURItargetDetector != null) { if (illegalURItargetDetector.isIllegal(uri)) { return new Target(uri, TargetType.ILLEGAL); } } Target resolved = null; if (usedUriTargetResolveStrategy != null) { resolved = usedUriTargetResolveStrategy.resolveTargetFor(uri); } if (resolved == null) { resolved = new Target(uri, TargetType.INTERNET); } return resolved; } TargetResolverService(); @Override Target resolveTargetForPath(String path); @Override Target resolveTarget(URI uri); @Override Target resolveTarget(InetAddress inetAdress);  }### Answer:
@Test public void no_strategies_defined_uri_resolved_as_INTRANET() { serviceToTest.definedUriStrategy = null; serviceToTest.definedInetAddressStrategy = null; URI uri = URI.create("https: Target found = serviceToTest.resolveTarget(uri); assertEquals(new Target(uri,TargetType.INTERNET),found); }
@Test public void no_strategies_set_uri_resolved_as_INTRANET() { serviceToTest = new TargetResolverService(); prepareDefinedStrategies(); URI uri = URI.create("https: Target found = serviceToTest.resolveTarget(uri); assertEquals(new Target(uri,TargetType.INTERNET),found); }
@Test public void no_strategies_defined_ip_resolved_as_INTRANET() throws Exception{ serviceToTest.definedUriStrategy = null; serviceToTest.definedInetAddressStrategy = null; InetAddress address = Inet4Address.getByName("172.217.22.99"); Target found = serviceToTest.resolveTarget(address); assertEquals(new Target(address,TargetType.INTERNET),found); }
@Test public void no_strategies_set_ip_resolved_as_INTRANET() throws Exception { serviceToTest = new TargetResolverService(); prepareDefinedStrategies(); InetAddress address = Inet4Address.getByName("172.217.22.99"); Target found = serviceToTest.resolveTarget(address); assertEquals(new Target(address,TargetType.INTERNET),found); }
@Test public void null_URI_is_resolved_as_unknown_without_strategy_call() throws Exception { assertEquals(new Target((URI) null, TargetType.UNKNOWN), serviceToTest.resolveTarget((URI) null)); verify(uriTestStrategy1, never()).resolveTargetFor(any()); }
@Test public void null_IP_address_is_resolved_as_unknown_without_strategy_call() throws Exception { assertEquals(new Target((InetAddress) null, TargetType.UNKNOWN), serviceToTest.resolveTarget((InetAddress) null)); verify(ipTestStrategy1, never()).resolveTargetFor(any()); }
@Test public void when_illegal_uri_target_detector_denies_uri_it_returns_target_but_illegal() throws Exception { URI uri = URI.create("illegal.example.com"); when(illegalURITargetDetector.isIllegal(uri)).thenReturn(true); assertEquals(new Target(uri, TargetType.ILLEGAL), serviceToTest.resolveTarget(uri)); verify(illegalURITargetDetector).isIllegal(uri); }
@Test public void when_illegal_ip_target_detector_denies_ip_it_returns_target_but_illegal() throws Exception { InetAddress inetAddress = mock(InetAddress.class); when(illegalInetAdressTargetDetector.isIllegal(inetAddress)).thenReturn(true); assertEquals(new Target(inetAddress, TargetType.ILLEGAL), serviceToTest.resolveTarget(inetAddress)); }
@Test public void inetaddress_strategy_result_is_used_as_result() throws Exception { assertEquals(inetAddressTarget1, serviceToTest.resolveTarget(mock(InetAddress.class))); }
@Test public void uri_strategy_result_is_used_as_result() throws Exception { assertEquals(uriTarget1, serviceToTest.resolveTarget(URI.create("https: }