Rename or inline local variables to avoid variable hiding

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1571371 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2014-02-24 18:03:43 +00:00
parent 56e6a6c853
commit fe360e7b3d
14 changed files with 92 additions and 89 deletions

View File

@ -116,12 +116,12 @@ public class TestCacheInvalidator {
@Test @Test
public void testInvalidatesUrisInContentLocationHeadersOnPUTs() throws Exception { public void testInvalidatesUrisInContentLocationHeadersOnPUTs() throws Exception {
final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1); final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
request.setEntity(HttpTestUtils.makeBody(128)); putRequest.setEntity(HttpTestUtils.makeBody(128));
request.setHeader("Content-Length","128"); putRequest.setHeader("Content-Length","128");
final String contentLocation = "http://foo.example.com/content"; final String contentLocation = "http://foo.example.com/content";
request.setHeader("Content-Location", contentLocation); putRequest.setHeader("Content-Location", contentLocation);
final String theUri = "http://foo.example.com:80/"; final String theUri = "http://foo.example.com:80/";
cacheEntryHasVariantMap(new HashMap<String,String>()); cacheEntryHasVariantMap(new HashMap<String,String>());
@ -132,19 +132,19 @@ public class TestCacheInvalidator {
replayMocks(); replayMocks();
impl.flushInvalidatedCacheEntries(host, request); impl.flushInvalidatedCacheEntries(host, putRequest);
verifyMocks(); verifyMocks();
} }
@Test @Test
public void testInvalidatesUrisInLocationHeadersOnPUTs() throws Exception { public void testInvalidatesUrisInLocationHeadersOnPUTs() throws Exception {
final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1); final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
request.setEntity(HttpTestUtils.makeBody(128)); putRequest.setEntity(HttpTestUtils.makeBody(128));
request.setHeader("Content-Length","128"); putRequest.setHeader("Content-Length","128");
final String contentLocation = "http://foo.example.com/content"; final String contentLocation = "http://foo.example.com/content";
request.setHeader("Location",contentLocation); putRequest.setHeader("Location",contentLocation);
final String theUri = "http://foo.example.com:80/"; final String theUri = "http://foo.example.com:80/";
cacheEntryHasVariantMap(new HashMap<String,String>()); cacheEntryHasVariantMap(new HashMap<String,String>());
@ -155,19 +155,19 @@ public class TestCacheInvalidator {
replayMocks(); replayMocks();
impl.flushInvalidatedCacheEntries(host, request); impl.flushInvalidatedCacheEntries(host, putRequest);
verifyMocks(); verifyMocks();
} }
@Test @Test
public void testInvalidatesRelativeUrisInContentLocationHeadersOnPUTs() throws Exception { public void testInvalidatesRelativeUrisInContentLocationHeadersOnPUTs() throws Exception {
final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1); final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
request.setEntity(HttpTestUtils.makeBody(128)); putRequest.setEntity(HttpTestUtils.makeBody(128));
request.setHeader("Content-Length","128"); putRequest.setHeader("Content-Length","128");
final String relativePath = "/content"; final String relativePath = "/content";
request.setHeader("Content-Location",relativePath); putRequest.setHeader("Content-Location",relativePath);
final String theUri = "http://foo.example.com:80/"; final String theUri = "http://foo.example.com:80/";
cacheEntryHasVariantMap(new HashMap<String,String>()); cacheEntryHasVariantMap(new HashMap<String,String>());
@ -178,19 +178,19 @@ public class TestCacheInvalidator {
replayMocks(); replayMocks();
impl.flushInvalidatedCacheEntries(host, request); impl.flushInvalidatedCacheEntries(host, putRequest);
verifyMocks(); verifyMocks();
} }
@Test @Test
public void testDoesNotInvalidateUrisInContentLocationHeadersOnPUTsToDifferentHosts() throws Exception { public void testDoesNotInvalidateUrisInContentLocationHeadersOnPUTsToDifferentHosts() throws Exception {
final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1); final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
request.setEntity(HttpTestUtils.makeBody(128)); putRequest.setEntity(HttpTestUtils.makeBody(128));
request.setHeader("Content-Length","128"); putRequest.setHeader("Content-Length","128");
final String contentLocation = "http://bar.example.com/content"; final String contentLocation = "http://bar.example.com/content";
request.setHeader("Content-Location",contentLocation); putRequest.setHeader("Content-Location",contentLocation);
final String theUri = "http://foo.example.com:80/"; final String theUri = "http://foo.example.com:80/";
cacheEntryHasVariantMap(new HashMap<String,String>()); cacheEntryHasVariantMap(new HashMap<String,String>());
@ -200,7 +200,7 @@ public class TestCacheInvalidator {
replayMocks(); replayMocks();
impl.flushInvalidatedCacheEntries(host, request); impl.flushInvalidatedCacheEntries(host, putRequest);
verifyMocks(); verifyMocks();
} }

View File

@ -39,6 +39,7 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@SuppressWarnings("boxing") // this is test code
public class TestCacheKeyGenerator { public class TestCacheKeyGenerator {
private static final BasicHttpRequest REQUEST_FULL_EPISODES = new BasicHttpRequest("GET", private static final BasicHttpRequest REQUEST_FULL_EPISODES = new BasicHttpRequest("GET",
@ -46,13 +47,13 @@ public class TestCacheKeyGenerator {
private static final BasicHttpRequest REQUEST_ROOT = new BasicHttpRequest("GET", "/"); private static final BasicHttpRequest REQUEST_ROOT = new BasicHttpRequest("GET", "/");
CacheKeyGenerator extractor; CacheKeyGenerator extractor;
private HttpHost host; private HttpHost defaultHost;
private HttpCacheEntry mockEntry; private HttpCacheEntry mockEntry;
private HttpRequest mockRequest; private HttpRequest mockRequest;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
host = new HttpHost("foo.example.com"); defaultHost = new HttpHost("foo.example.com");
mockEntry = EasyMock.createNiceMock(HttpCacheEntry.class); mockEntry = EasyMock.createNiceMock(HttpCacheEntry.class);
mockRequest = EasyMock.createNiceMock(HttpRequest.class); mockRequest = EasyMock.createNiceMock(HttpRequest.class);
extractor = new CacheKeyGenerator(); extractor = new CacheKeyGenerator();
@ -127,14 +128,14 @@ public class TestCacheKeyGenerator {
extractor = new CacheKeyGenerator() { extractor = new CacheKeyGenerator() {
@Override @Override
public String getURI(final HttpHost h, final HttpRequest req) { public String getURI(final HttpHost h, final HttpRequest req) {
Assert.assertSame(host, h); Assert.assertSame(defaultHost, h);
Assert.assertSame(mockRequest, req); Assert.assertSame(mockRequest, req);
return theURI; return theURI;
} }
}; };
replayMocks(); replayMocks();
final String result = extractor.getVariantURI(host, mockRequest, mockEntry); final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
verifyMocks(); verifyMocks();
Assert.assertSame(theURI, result); Assert.assertSame(theURI, result);
} }
@ -148,7 +149,7 @@ public class TestCacheKeyGenerator {
extractor = new CacheKeyGenerator() { extractor = new CacheKeyGenerator() {
@Override @Override
public String getURI(final HttpHost h, final HttpRequest req) { public String getURI(final HttpHost h, final HttpRequest req) {
Assert.assertSame(host, h); Assert.assertSame(defaultHost, h);
Assert.assertSame(mockRequest, req); Assert.assertSame(mockRequest, req);
return theURI; return theURI;
} }
@ -159,7 +160,7 @@ public class TestCacheKeyGenerator {
encHeaders); encHeaders);
replayMocks(); replayMocks();
final String result = extractor.getVariantURI(host, mockRequest, mockEntry); final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
verifyMocks(); verifyMocks();
Assert.assertEquals("{Accept-Encoding=gzip}" + theURI, result); Assert.assertEquals("{Accept-Encoding=gzip}" + theURI, result);
@ -173,7 +174,7 @@ public class TestCacheKeyGenerator {
extractor = new CacheKeyGenerator() { extractor = new CacheKeyGenerator() {
@Override @Override
public String getURI(final HttpHost h, final HttpRequest req) { public String getURI(final HttpHost h, final HttpRequest req) {
Assert.assertSame(host, h); Assert.assertSame(defaultHost, h);
Assert.assertSame(mockRequest, req); Assert.assertSame(mockRequest, req);
return theURI; return theURI;
} }
@ -184,7 +185,7 @@ public class TestCacheKeyGenerator {
.andReturn(noHeaders); .andReturn(noHeaders);
replayMocks(); replayMocks();
final String result = extractor.getVariantURI(host, mockRequest, mockEntry); final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
verifyMocks(); verifyMocks();
Assert.assertEquals("{Accept-Encoding=}" + theURI, result); Assert.assertEquals("{Accept-Encoding=}" + theURI, result);
@ -199,7 +200,7 @@ public class TestCacheKeyGenerator {
extractor = new CacheKeyGenerator() { extractor = new CacheKeyGenerator() {
@Override @Override
public String getURI(final HttpHost h, final HttpRequest req) { public String getURI(final HttpHost h, final HttpRequest req) {
Assert.assertSame(host, h); Assert.assertSame(defaultHost, h);
Assert.assertSame(mockRequest, req); Assert.assertSame(mockRequest, req);
return theURI; return theURI;
} }
@ -211,7 +212,7 @@ public class TestCacheKeyGenerator {
EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders); EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders);
replayMocks(); replayMocks();
final String result = extractor.getVariantURI(host, mockRequest, mockEntry); final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
verifyMocks(); verifyMocks();
Assert.assertEquals("{Accept-Encoding=gzip&User-Agent=browser}" + theURI, result); Assert.assertEquals("{Accept-Encoding=gzip&User-Agent=browser}" + theURI, result);
@ -227,7 +228,7 @@ public class TestCacheKeyGenerator {
extractor = new CacheKeyGenerator() { extractor = new CacheKeyGenerator() {
@Override @Override
public String getURI(final HttpHost h, final HttpRequest req) { public String getURI(final HttpHost h, final HttpRequest req) {
Assert.assertSame(host, h); Assert.assertSame(defaultHost, h);
Assert.assertSame(mockRequest, req); Assert.assertSame(mockRequest, req);
return theURI; return theURI;
} }
@ -238,7 +239,7 @@ public class TestCacheKeyGenerator {
EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders); EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders);
replayMocks(); replayMocks();
final String result = extractor.getVariantURI(host, mockRequest, mockEntry); final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
verifyMocks(); verifyMocks();
Assert.assertEquals("{Accept-Encoding=gzip&User-Agent=browser}" + theURI, result); Assert.assertEquals("{Accept-Encoding=gzip&User-Agent=browser}" + theURI, result);
@ -254,7 +255,7 @@ public class TestCacheKeyGenerator {
extractor = new CacheKeyGenerator() { extractor = new CacheKeyGenerator() {
@Override @Override
public String getURI(final HttpHost h, final HttpRequest req) { public String getURI(final HttpHost h, final HttpRequest req) {
Assert.assertSame(host, h); Assert.assertSame(defaultHost, h);
Assert.assertSame(mockRequest, req); Assert.assertSame(mockRequest, req);
return theURI; return theURI;
} }
@ -265,7 +266,7 @@ public class TestCacheKeyGenerator {
EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders); EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders);
replayMocks(); replayMocks();
final String result = extractor.getVariantURI(host, mockRequest, mockEntry); final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
verifyMocks(); verifyMocks();
Assert Assert

View File

@ -68,9 +68,9 @@ public class TestCachedHttpResponseGenerator {
@Test @Test
public void testResponseHasContentLength() { public void testResponseHasContentLength() {
final byte[] buf = new byte[] { 1, 2, 3, 4, 5 }; final byte[] buf = new byte[] { 1, 2, 3, 4, 5 };
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(buf); final HttpCacheEntry entry1 = HttpTestUtils.makeCacheEntry(buf);
final HttpResponse response = impl.generateResponse(entry); final HttpResponse response = impl.generateResponse(entry1);
final Header length = response.getFirstHeader("Content-Length"); final Header length = response.getFirstHeader("Content-Length");
Assert.assertNotNull("Content-Length Header is missing", length); Assert.assertNotNull("Content-Length Header is missing", length);
@ -84,9 +84,9 @@ public class TestCachedHttpResponseGenerator {
final Header[] hdrs = new Header[] { new BasicHeader("Transfer-Encoding", "chunked") }; final Header[] hdrs = new Header[] { new BasicHeader("Transfer-Encoding", "chunked") };
final byte[] buf = new byte[] { 1, 2, 3, 4, 5 }; final byte[] buf = new byte[] { 1, 2, 3, 4, 5 };
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(hdrs, buf); final HttpCacheEntry entry1 = HttpTestUtils.makeCacheEntry(hdrs, buf);
final HttpResponse response = impl.generateResponse(entry); final HttpResponse response = impl.generateResponse(entry1);
final Header length = response.getFirstHeader("Content-Length"); final Header length = response.getFirstHeader("Content-Length");

View File

@ -327,9 +327,9 @@ public abstract class TestCachingExecChain {
@Test @Test
public void testNonCacheableResponseIsNotCachedAndIsReturnedAsIs() throws Exception { public void testNonCacheableResponseIsNotCachedAndIsReturnedAsIs() throws Exception {
final CacheConfig config = CacheConfig.DEFAULT; final CacheConfig configDefault = CacheConfig.DEFAULT;
impl = createCachingExecChain(mockBackend, new BasicHttpCache(new HeapResourceFactory(), impl = createCachingExecChain(mockBackend, new BasicHttpCache(new HeapResourceFactory(),
mockStorage, config), config); mockStorage, configDefault), configDefault);
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest()); final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
final HttpResponse resp1 = HttpTestUtils.make200Response(); final HttpResponse resp1 = HttpTestUtils.make200Response();

View File

@ -65,9 +65,9 @@ public class TestConditionalRequestBuilder {
final String theUri = "/theuri"; final String theUri = "/theuri";
final String lastModified = "this is my last modified date"; final String lastModified = "this is my last modified date";
final HttpRequest request = new BasicHttpRequest(theMethod, theUri); final HttpRequest basicRequest = new BasicHttpRequest(theMethod, theUri);
request.addHeader("Accept-Encoding", "gzip"); basicRequest.addHeader("Accept-Encoding", "gzip");
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request); final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
final Header[] headers = new Header[] { final Header[] headers = new Header[] {
new BasicHeader("Date", DateUtils.formatDate(new Date())), new BasicHeader("Date", DateUtils.formatDate(new Date())),
@ -76,11 +76,11 @@ public class TestConditionalRequestBuilder {
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers); final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
final HttpRequestWrapper newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry); final HttpRequestWrapper newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry);
Assert.assertNotSame(request, newRequest); Assert.assertNotSame(basicRequest, newRequest);
Assert.assertEquals(theMethod, newRequest.getRequestLine().getMethod()); Assert.assertEquals(theMethod, newRequest.getRequestLine().getMethod());
Assert.assertEquals(theUri, newRequest.getRequestLine().getUri()); Assert.assertEquals(theUri, newRequest.getRequestLine().getUri());
Assert.assertEquals(request.getRequestLine().getProtocolVersion(), newRequest Assert.assertEquals(basicRequest.getRequestLine().getProtocolVersion(), newRequest
.getRequestLine().getProtocolVersion()); .getRequestLine().getProtocolVersion());
Assert.assertEquals(2, newRequest.getAllHeaders().length); Assert.assertEquals(2, newRequest.getAllHeaders().length);
@ -104,10 +104,10 @@ public class TestConditionalRequestBuilder {
new BasicHeader("Last-Modified", lmDate), new BasicHeader("Last-Modified", lmDate),
new BasicHeader("ETag", etag) new BasicHeader("ETag", etag)
}; };
final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); final HttpRequest basicRequest = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request); final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers); final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
final HttpRequest result = impl.buildConditionalRequest(requestWrapper, entry); final HttpRequest result = impl.buildConditionalRequest(requestWrapper, cacheEntry);
Assert.assertEquals(lmDate, Assert.assertEquals(lmDate,
result.getFirstHeader("If-Modified-Since").getValue()); result.getFirstHeader("If-Modified-Since").getValue());
Assert.assertEquals(etag, Assert.assertEquals(etag,
@ -120,9 +120,9 @@ public class TestConditionalRequestBuilder {
final String theUri = "/theuri"; final String theUri = "/theuri";
final String theETag = "this is my eTag"; final String theETag = "this is my eTag";
final HttpRequest request = new BasicHttpRequest(theMethod, theUri); final HttpRequest basicRequest = new BasicHttpRequest(theMethod, theUri);
request.addHeader("Accept-Encoding", "gzip"); basicRequest.addHeader("Accept-Encoding", "gzip");
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request); final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
final Header[] headers = new Header[] { final Header[] headers = new Header[] {
new BasicHeader("Date", DateUtils.formatDate(new Date())), new BasicHeader("Date", DateUtils.formatDate(new Date())),
@ -133,11 +133,11 @@ public class TestConditionalRequestBuilder {
final HttpRequest newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry); final HttpRequest newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry);
Assert.assertNotSame(request, newRequest); Assert.assertNotSame(basicRequest, newRequest);
Assert.assertEquals(theMethod, newRequest.getRequestLine().getMethod()); Assert.assertEquals(theMethod, newRequest.getRequestLine().getMethod());
Assert.assertEquals(theUri, newRequest.getRequestLine().getUri()); Assert.assertEquals(theUri, newRequest.getRequestLine().getUri());
Assert.assertEquals(request.getRequestLine().getProtocolVersion(), newRequest Assert.assertEquals(basicRequest.getRequestLine().getProtocolVersion(), newRequest
.getRequestLine().getProtocolVersion()); .getRequestLine().getProtocolVersion());
Assert.assertEquals(3, newRequest.getAllHeaders().length); Assert.assertEquals(3, newRequest.getAllHeaders().length);
@ -151,8 +151,8 @@ public class TestConditionalRequestBuilder {
@Test @Test
public void testCacheEntryWithMustRevalidateDoesEndToEndRevalidation() throws Exception { public void testCacheEntryWithMustRevalidateDoesEndToEndRevalidation() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1); final HttpRequest basicRequest = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request); final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
final Date now = new Date(); final Date now = new Date();
final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L); final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L); final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
@ -180,8 +180,8 @@ public class TestConditionalRequestBuilder {
@Test @Test
public void testCacheEntryWithProxyRevalidateDoesEndToEndRevalidation() throws Exception { public void testCacheEntryWithProxyRevalidateDoesEndToEndRevalidation() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1); final HttpRequest basicRequest = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request); final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
final Date now = new Date(); final Date now = new Date();
final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L); final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L); final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);

View File

@ -4842,12 +4842,12 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
} }
protected HttpRequestWrapper makeRequestWithBody(final String method, final String requestUri) { protected HttpRequestWrapper makeRequestWithBody(final String method, final String requestUri) {
final HttpEntityEnclosingRequest request = final HttpEntityEnclosingRequest req =
new BasicHttpEntityEnclosingRequest(method, requestUri, HttpVersion.HTTP_1_1); new BasicHttpEntityEnclosingRequest(method, requestUri, HttpVersion.HTTP_1_1);
final int nbytes = 128; final int nbytes = 128;
request.setEntity(HttpTestUtils.makeBody(nbytes)); req.setEntity(HttpTestUtils.makeBody(nbytes));
request.setHeader("Content-Length",""+nbytes); req.setHeader("Content-Length",""+nbytes);
return HttpRequestWrapper.wrap(request); return HttpRequestWrapper.wrap(req);
} }
@Test @Test

View File

@ -101,8 +101,8 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest()); final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
final HttpResponse resp2 = HttpTestUtils.make500Response(); final HttpResponse resp2 = HttpTestUtils.make500Response();
final byte[] body = HttpTestUtils.getRandomBytes(101); final byte[] body101 = HttpTestUtils.getRandomBytes(101);
final ByteArrayInputStream buf = new ByteArrayInputStream(body); final ByteArrayInputStream buf = new ByteArrayInputStream(body101);
final ConsumableInputStream cis = new ConsumableInputStream(buf); final ConsumableInputStream cis = new ConsumableInputStream(buf);
final HttpEntity entity = new InputStreamEntity(cis, 101); final HttpEntity entity = new InputStreamEntity(cis, 101);
resp2.setEntity(entity); resp2.setEntity(entity);
@ -167,9 +167,9 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
@Test @Test
public void testStaleIfErrorInResponseNeedNotYieldToProxyRevalidateForPrivateCache() public void testStaleIfErrorInResponseNeedNotYieldToProxyRevalidateForPrivateCache()
throws Exception{ throws Exception{
final CacheConfig config = CacheConfig.custom() final CacheConfig configUnshared = CacheConfig.custom()
.setSharedCache(false).build(); .setSharedCache(false).build();
impl = new CachingExec(mockBackend, new BasicHttpCache(config), config); impl = new CachingExec(mockBackend, new BasicHttpCache(configUnshared), configUnshared);
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L); final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest()); final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());

View File

@ -91,10 +91,10 @@ public class TestRequestProtocolCompliance {
@Test @Test
public void removesEntityFromTRACERequest() throws Exception { public void removesEntityFromTRACERequest() throws Exception {
final HttpEntityEnclosingRequest req = final HttpEntityEnclosingRequest reqst =
new BasicHttpEntityEnclosingRequest("TRACE", "/", HttpVersion.HTTP_1_1); new BasicHttpEntityEnclosingRequest("TRACE", "/", HttpVersion.HTTP_1_1);
req.setEntity(HttpTestUtils.makeBody(50)); reqst.setEntity(HttpTestUtils.makeBody(50));
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req); final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(reqst);
impl.makeRequestCompliant(wrapper); impl.makeRequestCompliant(wrapper);
if (wrapper instanceof HttpEntityEnclosingRequest) { if (wrapper instanceof HttpEntityEnclosingRequest) {
assertNull(((HttpEntityEnclosingRequest) wrapper).getEntity()); assertNull(((HttpEntityEnclosingRequest) wrapper).getEntity());

View File

@ -79,13 +79,13 @@ public class TestMemcachedCacheEntryImpl {
@Test @Test
public void canBeReconstitutedFromByteArray() throws Exception { public void canBeReconstitutedFromByteArray() throws Exception {
final String key = impl.getStorageKey(); final String key = impl.getStorageKey();
final HttpCacheEntry entry = impl.getHttpCacheEntry(); final HttpCacheEntry entry1 = impl.getHttpCacheEntry();
final byte[] bytes = impl.toByteArray(); final byte[] bytes = impl.toByteArray();
impl = new MemcachedCacheEntryImpl(); impl = new MemcachedCacheEntryImpl();
impl.set(bytes); impl.set(bytes);
assertEquals(key, impl.getStorageKey()); assertEquals(key, impl.getStorageKey());
assertEquivalent(entry, impl.getHttpCacheEntry()); assertEquivalent(entry1, impl.getHttpCacheEntry());
} }
@Test(expected=MemcachedSerializationException.class) @Test(expected=MemcachedSerializationException.class)

View File

@ -286,7 +286,7 @@ public class RequestBuilder {
public HttpUriRequest build() { public HttpUriRequest build() {
final HttpRequestBase result; final HttpRequestBase result;
URI uri = this.uri != null ? this.uri : URI.create("/"); URI uriNotNull = this.uri != null ? this.uri : URI.create("/");
HttpEntity entity = this.entity; HttpEntity entity = this.entity;
if (parameters != null && !parameters.isEmpty()) { if (parameters != null && !parameters.isEmpty()) {
if (entity == null && (HttpPost.METHOD_NAME.equalsIgnoreCase(method) if (entity == null && (HttpPost.METHOD_NAME.equalsIgnoreCase(method)
@ -294,7 +294,7 @@ public class RequestBuilder {
entity = new UrlEncodedFormEntity(parameters, HTTP.DEF_CONTENT_CHARSET); entity = new UrlEncodedFormEntity(parameters, HTTP.DEF_CONTENT_CHARSET);
} else { } else {
try { try {
uri = new URIBuilder(uri).addParameters(parameters).build(); uriNotNull = new URIBuilder(uriNotNull).addParameters(parameters).build();
} catch (final URISyntaxException ex) { } catch (final URISyntaxException ex) {
// should never happen // should never happen
} }
@ -308,7 +308,7 @@ public class RequestBuilder {
result = request; result = request;
} }
result.setProtocolVersion(this.version); result.setProtocolVersion(this.version);
result.setURI(uri); result.setURI(uriNotNull);
if (this.headergroup != null) { if (this.headergroup != null) {
result.setHeaders(this.headergroup.getAllHeaders()); result.setHeaders(this.headergroup.getAllHeaders());
} }

View File

@ -91,9 +91,9 @@ public abstract class GGSSchemeBase extends AuthSchemeBase {
protected byte[] generateGSSToken( protected byte[] generateGSSToken(
final byte[] input, final Oid oid, final String authServer) throws GSSException { final byte[] input, final Oid oid, final String authServer) throws GSSException {
byte[] token = input; byte[] inputBuff = input;
if (token == null) { if (inputBuff == null) {
token = new byte[0]; inputBuff = new byte[0];
} }
final GSSManager manager = getManager(); final GSSManager manager = getManager();
final GSSName serverName = manager.createName("HTTP@" + authServer, GSSName.NT_HOSTBASED_SERVICE); final GSSName serverName = manager.createName("HTTP@" + authServer, GSSName.NT_HOSTBASED_SERVICE);
@ -101,7 +101,7 @@ public abstract class GGSSchemeBase extends AuthSchemeBase {
serverName.canonicalize(oid), oid, null, GSSContext.DEFAULT_LIFETIME); serverName.canonicalize(oid), oid, null, GSSContext.DEFAULT_LIFETIME);
gssContext.requestMutualAuth(true); gssContext.requestMutualAuth(true);
gssContext.requestCredDeleg(true); gssContext.requestCredDeleg(true);
return gssContext.initSecContext(token, 0, token.length); return gssContext.initSecContext(inputBuff, 0, inputBuff.length);
} }
protected abstract byte[] generateToken( protected abstract byte[] generateToken(

View File

@ -129,7 +129,6 @@ public class RequestWrapper extends AbstractHttpMessage implements HttpUriReques
@Override @Override
public RequestLine getRequestLine() { public RequestLine getRequestLine() {
final String method = getMethod();
final ProtocolVersion ver = getProtocolVersion(); final ProtocolVersion ver = getProtocolVersion();
String uritext = null; String uritext = null;
if (uri != null) { if (uri != null) {
@ -138,7 +137,7 @@ public class RequestWrapper extends AbstractHttpMessage implements HttpUriReques
if (uritext == null || uritext.isEmpty()) { if (uritext == null || uritext.isEmpty()) {
uritext = "/"; uritext = "/";
} }
return new BasicRequestLine(method, uritext, ver); return new BasicRequestLine(getMethod(), uritext, ver);
} }
@Override @Override

View File

@ -60,6 +60,7 @@ import org.mockito.MockitoAnnotations;
/** /**
* {@link PoolingHttpClientConnectionManager} tests. * {@link PoolingHttpClientConnectionManager} tests.
*/ */
@SuppressWarnings({"boxing","static-access","resource"}) // test code
public class TestPoolingHttpClientConnectionManager { public class TestPoolingHttpClientConnectionManager {
@Mock @Mock
@ -300,7 +301,7 @@ public class TestPoolingHttpClientConnectionManager {
final ConnectionSocketFactory plainsf = Mockito.mock(ConnectionSocketFactory.class); final ConnectionSocketFactory plainsf = Mockito.mock(ConnectionSocketFactory.class);
final LayeredConnectionSocketFactory sslsf = Mockito.mock(LayeredConnectionSocketFactory.class); final LayeredConnectionSocketFactory sslsf = Mockito.mock(LayeredConnectionSocketFactory.class);
final Socket socket = Mockito.mock(Socket.class); final Socket mockSock = Mockito.mock(Socket.class);
final HttpClientContext context = HttpClientContext.create(); final HttpClientContext context = HttpClientContext.create();
final SocketConfig sconfig = SocketConfig.custom().build(); final SocketConfig sconfig = SocketConfig.custom().build();
final ConnectionConfig cconfig = ConnectionConfig.custom().build(); final ConnectionConfig cconfig = ConnectionConfig.custom().build();
@ -313,31 +314,31 @@ public class TestPoolingHttpClientConnectionManager {
Mockito.when(schemePortResolver.resolve(target)).thenReturn(8443); Mockito.when(schemePortResolver.resolve(target)).thenReturn(8443);
Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainsf); Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainsf);
Mockito.when(socketFactoryRegistry.lookup("https")).thenReturn(sslsf); Mockito.when(socketFactoryRegistry.lookup("https")).thenReturn(sslsf);
Mockito.when(plainsf.createSocket(Mockito.<HttpContext>any())).thenReturn(socket); Mockito.when(plainsf.createSocket(Mockito.<HttpContext>any())).thenReturn(mockSock);
Mockito.when(plainsf.connectSocket( Mockito.when(plainsf.connectSocket(
Mockito.anyInt(), Mockito.anyInt(),
Mockito.eq(socket), Mockito.eq(mockSock),
Mockito.<HttpHost>any(), Mockito.<HttpHost>any(),
Mockito.<InetSocketAddress>any(), Mockito.<InetSocketAddress>any(),
Mockito.<InetSocketAddress>any(), Mockito.<InetSocketAddress>any(),
Mockito.<HttpContext>any())).thenReturn(socket); Mockito.<HttpContext>any())).thenReturn(mockSock);
mgr.connect(conn1, route, 123, context); mgr.connect(conn1, route, 123, context);
Mockito.verify(dnsResolver, Mockito.times(1)).resolve("someproxy"); Mockito.verify(dnsResolver, Mockito.times(1)).resolve("someproxy");
Mockito.verify(schemePortResolver, Mockito.times(1)).resolve(proxy); Mockito.verify(schemePortResolver, Mockito.times(1)).resolve(proxy);
Mockito.verify(plainsf, Mockito.times(1)).createSocket(context); Mockito.verify(plainsf, Mockito.times(1)).createSocket(context);
Mockito.verify(plainsf, Mockito.times(1)).connectSocket(123, socket, proxy, Mockito.verify(plainsf, Mockito.times(1)).connectSocket(123, mockSock, proxy,
new InetSocketAddress(remote, 8080), new InetSocketAddress(remote, 8080),
new InetSocketAddress(local, 0), context); new InetSocketAddress(local, 0), context);
Mockito.when(conn.getSocket()).thenReturn(socket); Mockito.when(conn.getSocket()).thenReturn(mockSock);
mgr.upgrade(conn1, route, context); mgr.upgrade(conn1, route, context);
Mockito.verify(schemePortResolver, Mockito.times(1)).resolve(target); Mockito.verify(schemePortResolver, Mockito.times(1)).resolve(target);
Mockito.verify(sslsf, Mockito.times(1)).createLayeredSocket( Mockito.verify(sslsf, Mockito.times(1)).createLayeredSocket(
socket, "somehost", 8443, context); mockSock, "somehost", 8443, context);
mgr.routeComplete(conn1, route, context); mgr.routeComplete(conn1, route, context);
} }

View File

@ -27,6 +27,7 @@
package org.apache.http.impl.execchain; package org.apache.http.impl.execchain;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.http.Header; import org.apache.http.Header;
import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
@ -52,6 +53,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@SuppressWarnings({"boxing","static-access","resource"}) // test code
public class TestRetryExec { public class TestRetryExec {
@Mock @Mock
@ -165,8 +167,8 @@ public class TestRetryExec {
@Override @Override
public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
final Object[] args = invocationOnMock.getArguments(); final Object[] args = invocationOnMock.getArguments();
final HttpEntityEnclosingRequest request = (HttpEntityEnclosingRequest) args[1]; final HttpEntityEnclosingRequest req = (HttpEntityEnclosingRequest) args[1];
request.getEntity().writeTo(new ByteArrayOutputStream()); req.getEntity().writeTo(new ByteArrayOutputStream());
throw new IOException("Ka-boom"); throw new IOException("Ka-boom");
} }