Bug 516068 - Cleanup o.e.core.tests.net 

* Convert to JUnit 4
* Generify

Change-Id: Ide2d8aa3f4dbe5654f15164f9ef83cfce5025824
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/Activator.java b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/Activator.java
index d9ee4b8..e32f784 100644
--- a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/Activator.java
+++ b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/Activator.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2005, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -32,19 +32,11 @@
 	public Activator() {
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
-	 */
 	public void start(BundleContext context) throws Exception {
 		super.start(context);
 		plugin = this;
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
-	 */
 	public void stop(BundleContext context) throws Exception {
 		plugin = null;
 		super.stop(context);
@@ -60,9 +52,9 @@
 	}
 
 	public IProxyService getProxyService() {
-		ServiceReference serviceReference = getBundle().getBundleContext().getServiceReference(IProxyService.class.getName());
+		ServiceReference<IProxyService> serviceReference = getBundle().getBundleContext().getServiceReference(IProxyService.class);
 		if (serviceReference != null)
-			return (IProxyService)getBundle().getBundleContext().getService(serviceReference);
+			return getBundle().getBundleContext().getService(serviceReference);
 		return null;
 	}
 
diff --git a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
index 33e9b6e..43eb821 100644
--- a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
+++ b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2013 IBM Corporation and others.
+ * Copyright (c) 2007, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -10,22 +10,13 @@
  *******************************************************************************/
 package org.eclipse.core.tests.net;
 
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
 import junit.framework.*;
 
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ NetTest.class, PreferenceModifyListenerTest.class })
 public class AllNetTests extends TestCase {
 
-	public AllNetTests() {
-		super();
-	}
-
-	public AllNetTests(String name) {
-		super(name);
-	}
-
-	public static Test suite() {
-		TestSuite suite = new TestSuite();
-		suite.addTest(NetTest.suite());
-		suite.addTest(PreferenceModifyListenerTest.suite());
-		return suite;
-	}
 }
diff --git a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/NetTest.java b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/NetTest.java
index 3c3cde1..b1e8a67 100644
--- a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/NetTest.java
+++ b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/NetTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2013 IBM Corporation and others.
+ * Copyright (c) 2007, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -10,47 +10,33 @@
  *******************************************************************************/
 package org.eclipse.core.tests.net;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import java.util.*;
 
 import org.eclipse.core.internal.net.ProxyData;
 import org.eclipse.core.internal.net.ProxyType;
 import org.eclipse.core.net.proxy.IProxyData;
 import org.eclipse.core.net.proxy.IProxyService;
 import org.eclipse.core.runtime.CoreException;
+import org.junit.*;
 
-public class NetTest extends TestCase {
+public class NetTest {
 
-	private static final boolean BUG_338097= true;
+	private static final boolean BUG_338097 = true;
 
 	private boolean isSetEnabled;
 	private boolean isProxiesDefault;
 	private boolean isSystemProxiesDefault;
-	private Map dataCache = new HashMap();
+	private Map<String, IProxyData> dataCache = new HashMap<>();
 
-	public NetTest() {
-		super();
-	}
-
-	public NetTest(String name) {
-		super(name);
-	}
-
-	public static Test suite() {
-		return new TestSuite(NetTest.class);
-	}
-
-	protected void setUp() throws Exception {
-		super.setUp();
+	@Before
+	public void setUp() throws Exception {
 		isSystemProxiesDefault = isSystemProxiesEnabled();
 		setSystemProxiesEnabled(false);
 		isProxiesDefault = isProxiesEnabled();
@@ -60,8 +46,8 @@
 		ProxyType.socksSystemPropertySetting = ProxyType.ALWAYS_SET;
 	}
 
-	protected void tearDown() throws Exception {
-		super.tearDown();
+	@After
+	public void tearDown() throws Exception {
 		setProxiesEnabled(isProxiesDefault);
 		setSystemProxiesEnabled(isSystemProxiesDefault);
 		IProxyData[] data = getProxyManager().getProxyData();
@@ -78,8 +64,7 @@
 
 	private void assertProxyDataEqual(IProxyData expected) {
 		ProxyData expectedData = (ProxyData) expected;
-		ProxyData data = (ProxyData) getProxyManager().getProxyData(
-				expectedData.getType());
+		ProxyData data = (ProxyData) getProxyManager().getProxyData(expectedData.getType());
 		assertEquals(expectedData.getType(), data.getType());
 		assertEquals(expectedData.getHost(), data.getHost());
 		assertEquals(expectedData.getPort(), data.getPort());
@@ -105,15 +90,16 @@
 
 		if (this.getProxyManager().isProxiesEnabled()) {
 			boolean isSet = Boolean.getBoolean(keyPrefix + ".proxySet");
-			assertEquals(proxyData.getHost() != null, isSet); //$NON-NLS-1$
+			assertEquals(proxyData.getHost() != null, isSet); // $NON-NLS-1$
 			assertEquals(proxyData.getHost(), sysProps.get(keyPrefix + ".proxyHost")); //$NON-NLS-1$
-			String portString = (String)sysProps.get(keyPrefix + ".proxyPort"); //$NON-NLS-1$
+			String portString = (String) sysProps.get(keyPrefix + ".proxyPort"); //$NON-NLS-1$
 			int port = -1;
 			if (portString != null)
 				port = Integer.parseInt(portString);
 			assertEquals(proxyData.getPort(), port);
 			if (isSet)
-				assertEquals(ProxyType.convertHostsToPropertyString(this.getProxyManager().getNonProxiedHosts()), sysProps.get(keyPrefix + ".nonProxyHosts")); //$NON-NLS-1$
+				assertEquals(ProxyType.convertHostsToPropertyString(this.getProxyManager().getNonProxiedHosts()),
+						sysProps.get(keyPrefix + ".nonProxyHosts")); //$NON-NLS-1$
 			else
 				assertNull(sysProps.get(keyPrefix + ".nonProxyHosts"));
 			assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix + ".proxyUser")); //$NON-NLS-1$
@@ -134,7 +120,7 @@
 		Properties sysProps = System.getProperties();
 		if (this.getProxyManager().isProxiesEnabled()) {
 			assertEquals(proxyData.getHost(), sysProps.get("socksProxyHost")); //$NON-NLS-1$
-			String portString = (String)sysProps.get("socksProxyPort"); //$NON-NLS-1$
+			String portString = (String) sysProps.get("socksProxyPort"); //$NON-NLS-1$
 			int port = -1;
 			if (portString != null)
 				port = Integer.parseInt(portString);
@@ -146,7 +132,7 @@
 	}
 
 	private IProxyData getProxyData(String type) {
-		IProxyData data = (IProxyData)dataCache.get(type);
+		IProxyData data = (IProxyData) dataCache.get(type);
 		if (data == null) {
 			data = this.getProxyManager().getProxyData(type);
 			assertProxyDataEqual(data);
@@ -168,8 +154,7 @@
 		setProxyData(proxyData);
 	}
 
-	private void changeProxyData(IProxyData oldData, IProxyData data)
-			throws CoreException {
+	private void changeProxyData(IProxyData oldData, IProxyData data) throws CoreException {
 		// Make sure that setting the host doesn't change the persisted settings
 		if (isSetEnabled)
 			assertProxyDataEqual(oldData);
@@ -220,8 +205,7 @@
 
 	private void setProxiesEnabled(boolean enabled) {
 		this.getProxyManager().setProxiesEnabled(enabled);
-		if (enabled && this.getProxyManager().isSystemProxiesEnabled()
-				&& !this.getProxyManager().hasSystemProxies()) {
+		if (enabled && this.getProxyManager().isSystemProxiesEnabled() && !this.getProxyManager().hasSystemProxies()) {
 			assertEquals(false, this.getProxyManager().isProxiesEnabled());
 		} else {
 			assertEquals(enabled, this.getProxyManager().isProxiesEnabled());
@@ -248,6 +232,7 @@
 		dataCache.clear();
 	}
 
+	@Test
 	public void testIndividualSetAndClear() throws CoreException {
 		setDataTest(IProxyData.HTTP_PROXY_TYPE);
 		setDataTest(IProxyData.HTTPS_PROXY_TYPE);
@@ -259,6 +244,7 @@
 		}
 	}
 
+	@Test
 	public void testAllSetAndClear() throws CoreException {
 		delaySettingData();
 		setDataTest(IProxyData.HTTP_PROXY_TYPE);
@@ -275,12 +261,14 @@
 		performSettingData();
 	}
 
+	@Test
 	public void testSetWhenDisabled() throws CoreException {
 		setProxiesEnabled(false);
 		String type = IProxyData.HTTP_PROXY_TYPE;
 		setHost(type);
 	}
 
+	@Test
 	public void testDisableAfterSet() throws CoreException {
 		String type = IProxyData.HTTP_PROXY_TYPE;
 		setHost(type);
@@ -289,7 +277,9 @@
 		assertProxyDataEqual(data);
 	}
 
-	//TODO test disabled, see Bug 403311
+	// TODO test disabled, see Bug 403311
+	@Test
+	@Ignore
 	public void _testSimpleHost() throws CoreException {
 
 		setDataTest(IProxyData.HTTP_PROXY_TYPE);
@@ -309,6 +299,7 @@
 		assertNull(data);
 	}
 
+	@Test
 	public void testHostPattern() throws CoreException {
 		setDataTest(IProxyData.HTTP_PROXY_TYPE);
 		setDataTest(IProxyData.HTTPS_PROXY_TYPE);
@@ -338,6 +329,7 @@
 		this.getProxyManager().setNonProxiedHosts(oldHosts);
 	}
 
+	@Test
 	public void testHostPatternBug505906() throws CoreException {
 		setDataTest(IProxyData.HTTP_PROXY_TYPE);
 		setDataTest(IProxyData.HTTPS_PROXY_TYPE);
@@ -349,7 +341,8 @@
 		IProxyData[] allData = this.getProxyManager().getProxyDataForHost("ignore.com.randomhot.com");
 		assertEquals(3, allData.length);
 
-		IProxyData data = this.getProxyManager().getProxyDataForHost("ignore.com.randomhot.com", IProxyData.HTTP_PROXY_TYPE);
+		IProxyData data = this.getProxyManager().getProxyDataForHost("ignore.com.randomhot.com",
+				IProxyData.HTTP_PROXY_TYPE);
 		assertNotNull(data);
 
 		allData = this.getProxyManager().getProxyDataForHost("www.ignore.com");
@@ -367,6 +360,7 @@
 		this.getProxyManager().setNonProxiedHosts(oldHosts);
 	}
 
+	@Test
 	public void testBug238796() throws CoreException {
 		setDataTest(IProxyData.HTTP_PROXY_TYPE);
 		setDataTest(IProxyData.HTTPS_PROXY_TYPE);
@@ -374,39 +368,34 @@
 
 		String[] oldHosts = this.getProxyManager().getNonProxiedHosts();
 
-		this.getProxyManager().setNonProxiedHosts(
-				new String[] { "nonexisting.com" });
+		this.getProxyManager().setNonProxiedHosts(new String[] { "nonexisting.com" });
 
-		IProxyData[] allData = this.getProxyManager().getProxyDataForHost(
-				"NONEXISTING.COM");
+		IProxyData[] allData = this.getProxyManager().getProxyDataForHost("NONEXISTING.COM");
 		assertEquals(0, allData.length);
-		IProxyData data = this.getProxyManager().getProxyDataForHost(
-				"NONEXISTING.COM", IProxyData.HTTP_PROXY_TYPE);
+		IProxyData data = this.getProxyManager().getProxyDataForHost("NONEXISTING.COM", IProxyData.HTTP_PROXY_TYPE);
 		assertNull(data);
 
 		this.getProxyManager().setNonProxiedHosts(oldHosts);
 	}
 
+	@Test
 	public void testBug247408() throws CoreException, URISyntaxException {
 		setDataTest(IProxyData.HTTP_PROXY_TYPE);
 		setDataTest(IProxyData.HTTPS_PROXY_TYPE);
 		setDataTest(IProxyData.SOCKS_PROXY_TYPE);
 
-		IProxyData data1 = this.getProxyManager().getProxyDataForHost(
-				"randomhost.com", IProxyData.HTTP_PROXY_TYPE);
-		IProxyData[] data2 = this.getProxyManager().select(
-				new URI("http://randomhost.com"));
+		IProxyData data1 = this.getProxyManager().getProxyDataForHost("randomhost.com", IProxyData.HTTP_PROXY_TYPE);
+		IProxyData[] data2 = this.getProxyManager().select(new URI("http://randomhost.com"));
 		assertEquals(data2.length, 1);
 		assertEquals(data1, data2[0]);
 
-		IProxyData data3 = this.getProxyManager().getProxyDataForHost(
-				"randomhost.com", null);
-		IProxyData[] data4 = this.getProxyManager().select(
-				new URI(null, "randomhost.com", null, null));
+		IProxyData data3 = this.getProxyManager().getProxyDataForHost("randomhost.com", null);
+		IProxyData[] data4 = this.getProxyManager().select(new URI(null, "randomhost.com", null, null));
 		assertNull(data3);
 		assertEquals(data4.length, 0);
 	}
 
+	@Test
 	public void testBug255981() throws CoreException, URISyntaxException {
 		setDataTest(IProxyData.HTTP_PROXY_TYPE);
 		setDataTest(IProxyData.HTTPS_PROXY_TYPE);
@@ -414,19 +403,17 @@
 
 		this.getProxyManager().setProxiesEnabled(false);
 
-		IProxyData data = this.getProxyManager().getProxyDataForHost(
-				"randomhost.com", IProxyData.HTTP_PROXY_TYPE);
+		IProxyData data = this.getProxyManager().getProxyDataForHost("randomhost.com", IProxyData.HTTP_PROXY_TYPE);
 		assertNull(data);
 
-		IProxyData[] data2 = this.getProxyManager().select(
-				new URI("http://randomhost.com"));
+		IProxyData[] data2 = this.getProxyManager().select(new URI("http://randomhost.com"));
 		assertEquals(data2.length, 0);
 
-		IProxyData data3[] = this.getProxyManager().getProxyDataForHost(
-				"http://randomhost.com");
+		IProxyData data3[] = this.getProxyManager().getProxyDataForHost("http://randomhost.com");
 		assertEquals(data3.length, 0);
 	}
 
+	@Test
 	public void testBug257503() throws CoreException {
 		if (BUG_338097)
 			return;
@@ -443,6 +430,7 @@
 
 	}
 
+	@Test
 	public void testNonProxyHosts() throws CoreException {
 		setDataTest(IProxyData.HTTP_PROXY_TYPE);
 		setDataTest(IProxyData.HTTPS_PROXY_TYPE);
@@ -452,17 +440,17 @@
 
 		// add new host to the nonProxiedHosts list
 		String testHost = "bug284540.com";
-		ArrayList hostsList = new ArrayList();
+		ArrayList<String> hostsList = new ArrayList<>();
 		hostsList.addAll(Arrays.asList(oldHosts));
 		hostsList.add(testHost);
-		String[] newHosts = (String[]) hostsList.toArray(new String[] {});
+		String[] newHosts = hostsList.toArray(new String[] {});
 
 		this.getProxyManager().setNonProxiedHosts(newHosts);
 
 		// check if system properties are updated
 		String sysPropNonProxyHosts = System.getProperty("http.nonProxyHosts");
-		String assertMessage = "http.nonProxyHost should contain '" + testHost
-				+ "', but its current value is '" + sysPropNonProxyHosts + "'";
+		String assertMessage = "http.nonProxyHost should contain '" + testHost + "', but its current value is '"
+				+ sysPropNonProxyHosts + "'";
 		assertTrue(assertMessage, sysPropNonProxyHosts.indexOf(testHost) > -1);
 
 		this.getProxyManager().setNonProxiedHosts(oldHosts);
@@ -489,8 +477,7 @@
 
 	private void validateProperty(String key, String expected, boolean equals) {
 		String actual = System.getProperties().getProperty(key);
-		assertTrue((equals && expected.equals(actual))
-				|| (!equals && !expected.equals(actual)));
+		assertTrue((equals && expected.equals(actual)) || (!equals && !expected.equals(actual)));
 	}
 
 }
diff --git a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java
index 96fc9eb..09a35b3 100644
--- a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java
+++ b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others.
+ * Copyright (c) 2013, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -10,12 +10,11 @@
  *******************************************************************************/
 package org.eclipse.core.tests.net;
 
+import static org.junit.Assert.*;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 
-import junit.framework.Test;
-import junit.framework.TestCase;
-
 import org.eclipse.core.internal.preferences.EclipsePreferences;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.Platform;
@@ -23,21 +22,15 @@
 import org.eclipse.core.runtime.preferences.IExportedPreferences;
 import org.eclipse.core.runtime.preferences.IPreferencesService;
 import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.junit.Test;
 import org.osgi.service.prefs.BackingStoreException;
 
-public class PreferenceModifyListenerTest extends TestCase {
+public class PreferenceModifyListenerTest  {
 	private static final String NODE_NAME = "bug419228";
 	private static final String KEY = "someKey";
 	private static final String VALUE = "someValue";
 
-	public static Test suite() {
-		return new PreferenceModifyListenerTest("testPreApply");
-	}
-
-	public PreferenceModifyListenerTest(String name) {
-		super(name);
-	}
-
+	@Test
 	public void testPreApply() throws BackingStoreException, CoreException {
 		// create a dummy node and export it to a stream
 		IEclipsePreferences toExport = InstanceScope.INSTANCE.getNode(NODE_NAME);
diff --git a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/SystemProxyTest.java b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/SystemProxyTest.java
index cc65967..73a3249 100644
--- a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/SystemProxyTest.java
+++ b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/SystemProxyTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -29,7 +29,7 @@
 	private boolean isProxiesDefault;
 	private boolean isSystemProxiesDefault;
 
-	private Map proxyDataMap = new HashMap();
+	private Map<String, IProxyData> proxyDataMap = new HashMap<>();
 
 	public SystemProxyTest() {
 		super();
@@ -114,7 +114,7 @@
 		IProxyData[] proxiesData = getProxyManager().getProxyDataForHost(host);
 		assertNotNull(proxiesData);
 
-		Map typeMap = new HashMap();
+		Map<String, String> typeMap = new HashMap<>();
 		for (int i = 0; i < proxiesData.length; i++) {
 			assertProxyDataEqual(proxiesData[i], (IProxyData) proxyDataMap
 					.get(proxiesData[i].getType()));
@@ -128,7 +128,7 @@
 		IProxyData[] proxiesData = ProxySelector.getProxyData("Native");
 		assertNotNull(proxiesData);
 
-		Map typeMap = new HashMap();
+		Map<String, String> typeMap = new HashMap<>();
 		for (int i = 0; i < proxiesData.length; i++) {
 			assertProxyDataEqual(proxiesData[i], (IProxyData) proxyDataMap
 					.get(proxiesData[i].getType()));