### Question:
PacUtils { static List<Proxy> getProxiesFromPacResult(final String pacString) { if (pacString == null) { return Collections.singletonList(Proxy.NO_PROXY); } final String[] tokens = pacString.split(";"); return Stream.of(tokens) .map(token -> token.trim()) .map(token -> { if (token.startsWith(PROXY)) { return getInetSocketAddress(token) .map(sa -> new Proxy(Proxy.Type.HTTP, sa)) .orElseThrow(() -> new IllegalArgumentException("HTTP Proxy must be specified with valid address")); } else if (token.startsWith(SOCKS)) { return getInetSocketAddress(token) .map(sa -> new Proxy(Proxy.Type.SOCKS, sa)) .orElseThrow(() -> new IllegalArgumentException("SOCKS Proxy must be specified with valid address")); } else if (token.startsWith(DIRECT)) { return Proxy.NO_PROXY; } else { throw new IllegalArgumentException("Unrecognized proxy token: " + token); } }).collect(Collectors.toList()); }    }### Answer:
@Test void getProxiesFromPacResultTest() { final String pacResult = "PROXY proxy.example.com:8080"; final List<Proxy> proxiesFromPacResult = PacUtils.getProxiesFromPacResult(pacResult); Assertions.assertNotNull(proxiesFromPacResult); Assertions.assertEquals(1, proxiesFromPacResult.size()); Assertions.assertEquals(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.example.com", 8080)), proxiesFromPacResult.get(0)); }
@Test void getProxiesFromPacResultTest2() { final String pacResult = "DIRECT"; final List<Proxy> proxiesFromPacResult = PacUtils.getProxiesFromPacResult(pacResult); Assertions.assertNotNull(proxiesFromPacResult); Assertions.assertEquals(1, proxiesFromPacResult.size()); Assertions.assertEquals(Proxy.NO_PROXY, proxiesFromPacResult.get(0)); }
@Test void getProxiesFromPacResultTest3() { final String pacResult = "PROXY proxy.example.com:8080; DIRECT"; final List<Proxy> proxiesFromPacResult = PacUtils.getProxiesFromPacResult(pacResult); Assertions.assertNotNull(proxiesFromPacResult); Assertions.assertEquals(2, proxiesFromPacResult.size()); Assertions.assertEquals(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.example.com", 8080)), proxiesFromPacResult.get(0)); Assertions.assertEquals(Proxy.NO_PROXY, proxiesFromPacResult.get(1)); }
@Test void getProxiesFromPacResultTest4() { final String pacResult = null; final List<Proxy> proxiesFromPacResult = PacUtils.getProxiesFromPacResult(pacResult); Assertions.assertNotNull(proxiesFromPacResult); Assertions.assertEquals(1, proxiesFromPacResult.size()); Assertions.assertEquals(Proxy.NO_PROXY, proxiesFromPacResult.get(0)); }
@Test void getProxiesFromPacResultTest5() { final String pacResult = "INVALID"; Assertions.assertThrows(IllegalArgumentException.class, () -> PacUtils.getProxiesFromPacResult(pacResult)); }