Generics in test cases

git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@603871 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2007-12-13 10:33:25 +00:00
parent 4d8e798156
commit 08bf8e8e50
6 changed files with 41 additions and 43 deletions

View File

@ -1,7 +1,7 @@
/*
* $HeadURL:$
* $Revision:$
* $Date:$
* $HeadURL$
* $Revision$
* $Date$
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@ -68,7 +68,7 @@ public class TestHttpOptions extends TestCase {
resp.addHeader("Allow", "GET");
HttpOptions opt = new HttpOptions();
Set methodsName = opt.getAllowedMethods(resp);
Set<String> methodsName = opt.getAllowedMethods(resp);
assertTrue(methodsName.contains("POST"));
assertTrue(methodsName.contains("GET"));

View File

@ -647,7 +647,7 @@ public class TestRedirects extends ServerTestBase {
DefaultHttpClient client = new DefaultHttpClient();
HttpContext context = client.getDefaultContext();
List defaultHeaders = new ArrayList(1);
List<Header> defaultHeaders = new ArrayList<Header>(1);
defaultHeaders.add(new BasicHeader(HTTP.USER_AGENT, "my-test-client"));
client.getParams().setParameter(ClientPNames.DEFAULT_HEADERS, defaultHeaders);

View File

@ -198,7 +198,7 @@ public class TestHttpRoute extends TestCase {
assertTrue ("routettt.layer" , routettt.isLayered());
HashSet routes = new HashSet();
HashSet<HttpRoute> routes = new HashSet<HttpRoute>();
routes.add(routefff);
routes.add(routefft);
routes.add(routeftf);
@ -211,7 +211,7 @@ public class TestHttpRoute extends TestCase {
// we can't test hashCode in general due to it's dependency
// on InetAddress and HttpHost, but we can check for the flags
HashSet routecodes = new HashSet();
HashSet<Integer> routecodes = new HashSet<Integer>();
routecodes.add(new Integer(routefff.hashCode()));
routecodes.add(new Integer(routefft.hashCode()));
routecodes.add(new Integer(routeftf.hashCode()));
@ -223,7 +223,7 @@ public class TestHttpRoute extends TestCase {
assertEquals("some flagged routes have same hashCode",
8, routecodes.size());
HashSet routestrings = new HashSet();
HashSet<String> routestrings = new HashSet<String>();
routestrings.add(routefff.toString());
routestrings.add(routefft.toString());
routestrings.add(routeftf.toString());
@ -390,7 +390,7 @@ public class TestHttpRoute extends TestCase {
// now check that all of the routes are different from eachother
// except for those that aren't :-)
HashSet routes = new HashSet();
HashSet<HttpRoute> routes = new HashSet<HttpRoute>();
routes.add(route1a);
routes.add(route2a);
routes.add(route2b);
@ -406,16 +406,16 @@ public class TestHttpRoute extends TestCase {
assertEquals("some routes are equal", 11, routes.size());
// and a run of cloning over the set
Iterator iter = routes.iterator();
Iterator<HttpRoute> iter = routes.iterator();
while (iter.hasNext()) {
HttpRoute origin = (HttpRoute) iter.next();
HttpRoute origin = iter.next();
HttpRoute cloned = (HttpRoute) origin.clone();
assertEquals("clone of " + origin, origin, cloned);
assertTrue("clone of " + origin, routes.contains(cloned));
}
// and don't forget toString
HashSet routestrings = new HashSet();
HashSet<String> routestrings = new HashSet<String>();
routestrings.add(route1a.toString());
routestrings.add(route2a.toString());
routestrings.add(route2b.toString());

View File

@ -33,7 +33,7 @@ package org.apache.http.conn;
import java.net.InetAddress;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import junit.framework.Test;
import junit.framework.TestCase;
@ -414,14 +414,14 @@ public class TestRouteTracker extends TestCase {
// rt0 -> direct connection
// rt1 -> via single proxy
// rt2 -> via proxy chain
HashSet hs = new HashSet();
Set<RouteTracker> hs = new HashSet<RouteTracker>();
// we also collect hashcodes for the different paths
// since we can't guarantee what influence the HttpHost hashcodes have,
// we keep separate sets here
HashSet hc0 = new HashSet();
HashSet hc4 = new HashSet();
HashSet hc6 = new HashSet();
Set<Integer> hc0 = new HashSet<Integer>();
Set<Integer> hc4 = new HashSet<Integer>();
Set<Integer> hc6 = new HashSet<Integer>();
RouteTracker rt = null;
@ -447,106 +447,104 @@ public class TestRouteTracker extends TestCase {
// proxy (insecure) -> tunnel (insecure) -> layer (secure)
rt = (RouteTracker) rt4.clone();
rt.connectProxy(PROXY1, false);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc4.add(new Integer(rt.hashCode())));
rt.tunnelTarget(false);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc4.add(new Integer(rt.hashCode())));
rt.layerProtocol(true);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc4.add(new Integer(rt.hashCode())));
// proxy (secure) -> tunnel (secure) -> layer (insecure)
rt = (RouteTracker) rt4.clone();
rt.connectProxy(PROXY1, true);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc4.add(new Integer(rt.hashCode())));
rt.tunnelTarget(true);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc4.add(new Integer(rt.hashCode())));
rt.layerProtocol(false);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc4.add(new Integer(rt.hashCode())));
// PROXY1/i -> PROXY2/i -> tunnel/i -> layer/s
rt = (RouteTracker) rt6.clone();
rt.connectProxy(PROXY1, false);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc6.add(new Integer(rt.hashCode())));
rt.tunnelProxy(PROXY2, false);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc6.add(new Integer(rt.hashCode())));
rt.tunnelTarget(false);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc6.add(new Integer(rt.hashCode())));
rt.layerProtocol(true);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc6.add(new Integer(rt.hashCode())));
// PROXY1/s -> PROXY2/s -> tunnel/s -> layer/i
rt = (RouteTracker) rt6.clone();
rt.connectProxy(PROXY1, true);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc6.add(new Integer(rt.hashCode())));
rt.tunnelProxy(PROXY2, true);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc6.add(new Integer(rt.hashCode())));
rt.tunnelTarget(true);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc6.add(new Integer(rt.hashCode())));
rt.layerProtocol(false);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc6.add(new Integer(rt.hashCode())));
// PROXY2/i -> PROXY1/i -> tunnel/i -> layer/s
rt = (RouteTracker) rt6.clone();
rt.connectProxy(PROXY2, false);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc6.add(new Integer(rt.hashCode())));
rt.tunnelProxy(PROXY1, false);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
// proxy chain sequence does not affect hashcode, so duplicate:
// assertTrue(hc6.add(new Integer(rt.hashCode())));
rt.tunnelTarget(false);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
// proxy chain sequence does not affect hashcode, so duplicate:
// assertTrue(hc6.add(new Integer(rt.hashCode())));
rt.layerProtocol(true);
assertTrue(hs.add(rt.clone()));
assertTrue(hs.add((RouteTracker) rt.clone()));
// proxy chain sequence does not affect hashcode, so duplicate:
// assertTrue(hc6.add(new Integer(rt.hashCode())));
// check that all toString are OK and different
HashSet rtstrings = new HashSet();
Iterator iter = hs.iterator();
while (iter.hasNext()) {
rt = (RouteTracker) iter.next();
final String rts = checkToString(rt);
Set<String> rtstrings = new HashSet<String>();
for (RouteTracker current: hs) {
final String rts = checkToString(current);
assertTrue("duplicate toString: " + rts, rtstrings.add(rts));
}
}

View File

@ -150,7 +150,7 @@ public class TestScheme extends TestCase {
public void testIterator() {
SchemeRegistry schmreg = new SchemeRegistry();
List names = schmreg.getSchemeNames();
List<String> names = schmreg.getSchemeNames();
assertNotNull(names);
assertTrue(names.isEmpty());

View File

@ -285,8 +285,8 @@ public class LocalTestServer {
public class RequestListener implements Runnable {
/** The workers launched from here. */
private Set workerThreads =
Collections.synchronizedSet(new HashSet());
private Set<Thread> workerThreads =
Collections.synchronizedSet(new HashSet<Thread>());
public void run() {