Path: blob/master/test/jdk/sun/net/spi/DefaultProxySelectorTest.java
41152 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import org.testng.Assert;24import org.testng.annotations.Test;25import sun.net.spi.DefaultProxySelector;2627import java.net.ProxySelector;28import java.net.URI;2930/**31* @test32* @bug 6563286 6797318 817764833* @summary Tests sun.net.spi.DefaultProxySelector#select(URI)34* @run testng DefaultProxySelectorTest35* @modules java.base/sun.net.spi:+open36*/37public class DefaultProxySelectorTest {3839/**40* Tests that {@link DefaultProxySelector#select(URI)} throws41* {@link IllegalArgumentException} when passed {@code null}42*/43@Test44public void testIllegalArgForNull() {45final ProxySelector selector = new DefaultProxySelector();46try {47selector.select(null);48Assert.fail("select() was expected to fail for null URI");49} catch (IllegalArgumentException iae) {50// expected51}52}5354/**55* Tests that {@link DefaultProxySelector} throws a {@link IllegalArgumentException}56* for URIs that don't have host information57*58* @throws Exception59*/60@Test61public void testIllegalArgForNoHost() throws Exception {62final ProxySelector selector = new DefaultProxySelector();63assertFailsWithIAE(selector, new URI("http", "/test", null));64assertFailsWithIAE(selector, new URI("https", "/test2", null));65assertFailsWithIAE(selector, new URI("ftp", "/test3", null));66}676869/**70* Tests that {@link DefaultProxySelector} throws a {@link IllegalArgumentException}71* for URIs that don't have protocol/scheme information72*73* @throws Exception74*/75@Test76public void testIllegalArgForNoScheme() throws Exception {77final ProxySelector selector = new DefaultProxySelector();78assertFailsWithIAE(selector, new URI(null, "/test", null));79}8081private static void assertFailsWithIAE(final ProxySelector selector, final URI uri) {82try {83selector.select(uri);84Assert.fail("select() was expected to fail for URI " + uri);85} catch (IllegalArgumentException iae) {86// expected87}88}89}909192