HTTPCLIENT-1244: relaxed EasyMock based unit tests in the Caching module

Contributed by Joe Campbell <joseph.r.campbell at gmail.com>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1395613 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2012-10-08 15:26:50 +00:00
parent 639cc93c56
commit 43d4e8f469
17 changed files with 60 additions and 60 deletions

View File

@ -59,7 +59,7 @@ public class TestHttpCacheEntry {
nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1,
HttpStatus.SC_OK, "OK");
mockResource = createMock(Resource.class);
mockResource = createNiceMock(Resource.class);
}
private HttpCacheEntry makeEntry(Header[] headers) {

View File

@ -73,8 +73,8 @@ public abstract class AbstractProtocolTest {
params.setMaxCacheEntries(MAX_ENTRIES);
params.setMaxObjectSize(MAX_BYTES);
cache = new BasicHttpCache(params);
mockBackend = EasyMock.createMock(HttpClient.class);
mockCache = EasyMock.createMock(HttpCache.class);
mockBackend = EasyMock.createNiceMock(HttpClient.class);
mockCache = EasyMock.createNiceMock(HttpCache.class);
impl = new CachingHttpClient(mockBackend, cache, params);
}
@ -95,8 +95,8 @@ public abstract class AbstractProtocolTest {
}
protected void emptyMockCacheExpectsNoPuts() throws Exception {
mockBackend = EasyMock.createMock(HttpClient.class);
mockCache = EasyMock.createMock(HttpCache.class);
mockBackend = EasyMock.createNiceMock(HttpClient.class);
mockCache = EasyMock.createNiceMock(HttpCache.class);
impl = new CachingHttpClient(mockBackend, mockCache, params);

View File

@ -79,9 +79,9 @@ public class DoNotTestProtocolRequirements {
params.setMaxCacheEntries(MAX_ENTRIES);
HttpCache cache = new BasicHttpCache(params);
mockBackend = EasyMock.createMock(HttpClient.class);
mockEntity = EasyMock.createMock(HttpEntity.class);
mockCache = EasyMock.createMock(HttpCache.class);
mockBackend = EasyMock.createNiceMock(HttpClient.class);
mockEntity = EasyMock.createNiceMock(HttpEntity.class);
mockCache = EasyMock.createNiceMock(HttpCache.class);
impl = new CachingHttpClient(mockBackend, cache, params);
}

View File

@ -49,12 +49,12 @@ public class TestAsynchronousValidationRequest {
@Before
public void setUp() {
mockParent = EasyMock.createMock(AsynchronousValidator.class);
mockClient = EasyMock.createMock(CachingHttpClient.class);
mockParent = EasyMock.createNiceMock(AsynchronousValidator.class);
mockClient = EasyMock.createNiceMock(CachingHttpClient.class);
target = new HttpHost("foo.example.com");
request = new HttpGet("/");
mockContext = EasyMock.createMock(HttpContext.class);
mockCacheEntry = EasyMock.createMock(HttpCacheEntry.class);
mockContext = EasyMock.createNiceMock(HttpContext.class);
mockCacheEntry = EasyMock.createNiceMock(HttpCacheEntry.class);
}
@Test

View File

@ -61,13 +61,13 @@ public class TestAsynchronousValidator {
@Before
public void setUp() {
mockClient = EasyMock.createMock(CachingHttpClient.class);
mockClient = EasyMock.createNiceMock(CachingHttpClient.class);
target = new HttpHost("foo.example.com");
request = new HttpGet("/");
mockContext = EasyMock.createMock(HttpContext.class);
mockCacheEntry = EasyMock.createMock(HttpCacheEntry.class);
mockContext = EasyMock.createNiceMock(HttpContext.class);
mockCacheEntry = EasyMock.createNiceMock(HttpCacheEntry.class);
mockExecutor = EasyMock.createMock(ExecutorService.class);
mockExecutor = EasyMock.createNiceMock(ExecutorService.class);
}

View File

@ -73,9 +73,9 @@ public class TestCacheInvalidator {
tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
host = new HttpHost("foo.example.com");
mockStorage = createMock(HttpCacheStorage.class);
mockStorage = createNiceMock(HttpCacheStorage.class);
cacheKeyGenerator = new CacheKeyGenerator();
mockEntry = createMock(HttpCacheEntry.class);
mockEntry = createNiceMock(HttpCacheEntry.class);
request = HttpTestUtils.makeDefaultRequest();
response = HttpTestUtils.make200Response();

View File

@ -53,8 +53,8 @@ public class TestCacheKeyGenerator {
@Before
public void setUp() throws Exception {
host = new HttpHost("foo.example.com");
mockEntry = EasyMock.createMock(HttpCacheEntry.class);
mockRequest = EasyMock.createMock(HttpRequest.class);
mockEntry = EasyMock.createNiceMock(HttpCacheEntry.class);
mockRequest = EasyMock.createNiceMock(HttpRequest.class);
extractor = new CacheKeyGenerator();
}

View File

@ -57,7 +57,7 @@ public class TestCachedHttpResponseGenerator {
new BasicHeader("Content-Length", "150") };
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, sixSecondsAgo, hdrs);
mockValidityPolicy = EasyMock.createMock(CacheValidityPolicy.class);
mockValidityPolicy = EasyMock.createNiceMock(CacheValidityPolicy.class);
impl = new CachedHttpResponseGenerator(mockValidityPolicy);
}

View File

@ -63,7 +63,7 @@ public class TestCachedResponseSuitabilityChecker {
host = new HttpHost("foo.example.com");
request = new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1);
mockValidityPolicy = EasyMock.createMock(CacheValidityPolicy.class);
mockValidityPolicy = EasyMock.createNiceMock(CacheValidityPolicy.class);
entry = HttpTestUtils.makeCacheEntry();
impl = new CachedResponseSuitabilityChecker(new CacheConfig());

View File

@ -115,25 +115,25 @@ public class TestCachingHttpClient {
@SuppressWarnings("unchecked")
@Before
public void setUp() {
mockRequestPolicy = createMock(CacheableRequestPolicy.class);
mockValidityPolicy = createMock(CacheValidityPolicy.class);
mockBackend = createMock(HttpClient.class);
mockCache = createMock(HttpCache.class);
mockSuitabilityChecker = createMock(CachedResponseSuitabilityChecker.class);
mockResponsePolicy = createMock(ResponseCachingPolicy.class);
mockConnectionManager = createMock(ClientConnectionManager.class);
mockHandler = createMock(ResponseHandler.class);
mockBackendResponse = createMock(HttpResponse.class);
mockUriRequest = createMock(HttpUriRequest.class);
mockCacheEntry = createMock(HttpCacheEntry.class);
mockResponseGenerator = createMock(CachedHttpResponseGenerator.class);
mockCachedResponse = createMock(HttpResponse.class);
mockConditionalRequestBuilder = createMock(ConditionalRequestBuilder.class);
mockConditionalRequest = createMock(HttpRequest.class);
mockStatusLine = createMock(StatusLine.class);
mockResponseProtocolCompliance = createMock(ResponseProtocolCompliance.class);
mockRequestProtocolCompliance = createMock(RequestProtocolCompliance.class);
mockStorage = createMock(HttpCacheStorage.class);
mockRequestPolicy = createNiceMock(CacheableRequestPolicy.class);
mockValidityPolicy = createNiceMock(CacheValidityPolicy.class);
mockBackend = createNiceMock(HttpClient.class);
mockCache = createNiceMock(HttpCache.class);
mockSuitabilityChecker = createNiceMock(CachedResponseSuitabilityChecker.class);
mockResponsePolicy = createNiceMock(ResponseCachingPolicy.class);
mockConnectionManager = createNiceMock(ClientConnectionManager.class);
mockHandler = createNiceMock(ResponseHandler.class);
mockBackendResponse = createNiceMock(HttpResponse.class);
mockUriRequest = createNiceMock(HttpUriRequest.class);
mockCacheEntry = createNiceMock(HttpCacheEntry.class);
mockResponseGenerator = createNiceMock(CachedHttpResponseGenerator.class);
mockCachedResponse = createNiceMock(HttpResponse.class);
mockConditionalRequestBuilder = createNiceMock(ConditionalRequestBuilder.class);
mockConditionalRequest = createNiceMock(HttpRequest.class);
mockStatusLine = createNiceMock(StatusLine.class);
mockResponseProtocolCompliance = createNiceMock(ResponseProtocolCompliance.class);
mockRequestProtocolCompliance = createNiceMock(RequestProtocolCompliance.class);
mockStorage = createNiceMock(HttpCacheStorage.class);
requestDate = new Date(System.currentTimeMillis() - 1000);
responseDate = new Date();
@ -2159,7 +2159,7 @@ public class TestCachingHttpClient {
mockSuitabilityChecker,
mockConditionalRequestBuilder,
mockResponseProtocolCompliance,
mockRequestProtocolCompliance).addMockedMethods(methods).createMock();
mockRequestProtocolCompliance).addMockedMethods(methods).createNiceMock();
}
}

View File

@ -38,7 +38,7 @@ public class TestCombinedEntity {
@Test
public void testCombinedEntityBasics() throws Exception {
Resource resource = EasyMock.createMock(Resource.class);
Resource resource = EasyMock.createNiceMock(Resource.class);
EasyMock.expect(resource.getInputStream()).andReturn(
new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }));
resource.dispose();

View File

@ -91,7 +91,7 @@ public class TestHttpCacheJiraNumber1147 {
ResourceFactory resourceFactory = new FileResourceFactory(cacheDir);
HttpCacheStorage httpCacheStorage = new ManagedHttpCacheStorage(cacheConfig);
HttpClient client = EasyMock.createMock(HttpClient.class);
HttpClient client = EasyMock.createNiceMock(HttpClient.class);
HttpGet get = new HttpGet("http://somehost/");
HttpContext context = new BasicHttpContext();
HttpHost target = new HttpHost("somehost");

View File

@ -98,9 +98,9 @@ public class TestProtocolDeviations {
params.setMaxCacheEntries(MAX_ENTRIES);
HttpCache cache = new BasicHttpCache(params);
mockBackend = EasyMock.createMock(HttpClient.class);
mockEntity = EasyMock.createMock(HttpEntity.class);
mockCache = EasyMock.createMock(HttpCache.class);
mockBackend = EasyMock.createNiceMock(HttpClient.class);
mockEntity = EasyMock.createNiceMock(HttpEntity.class);
mockCache = EasyMock.createNiceMock(HttpCache.class);
impl = new CachingHttpClient(mockBackend, cache, params);
}
@ -203,7 +203,7 @@ public class TestProtocolDeviations {
(new Random()).nextBytes(bytes);
HttpEntity mockBody = EasyMock.createMockBuilder(ByteArrayEntity.class).withConstructor(
new Object[] { bytes }).addMockedMethods("getContentLength").createMock();
new Object[] { bytes }).addMockedMethods("getContentLength").createNiceMock();
org.easymock.EasyMock.expect(mockBody.getContentLength()).andReturn(-1L).anyTimes();
post.setEntity(mockBody);

View File

@ -550,7 +550,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
public void testRequestsExpecting100ContinueBehaviorShouldSetExpectHeader() throws Exception {
BasicHttpEntityEnclosingRequest post = EasyMock.createMockBuilder(
BasicHttpEntityEnclosingRequest.class).withConstructor("POST", "/", HttpVersion.HTTP_1_1)
.addMockedMethods("expectContinue").createMock();
.addMockedMethods("expectContinue").createNiceMock();
post.setEntity(new BasicHttpEntity());
post.setHeader("Content-Length", "128");
@ -595,7 +595,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
throws Exception {
BasicHttpEntityEnclosingRequest post = EasyMock.createMockBuilder(
BasicHttpEntityEnclosingRequest.class).withConstructor("POST", "/", HttpVersion.HTTP_1_1)
.addMockedMethods("expectContinue").createMock();
.addMockedMethods("expectContinue").createNiceMock();
post.setEntity(new BasicHttpEntity());
post.setHeader("Content-Length", "128");

View File

@ -51,10 +51,10 @@ public class TestEhcacheHttpCacheStorage extends TestCase {
@Override
public void setUp() {
mockCache = EasyMock.createMock(Ehcache.class);
mockCache = EasyMock.createNiceMock(Ehcache.class);
CacheConfig config = new CacheConfig();
config.setMaxUpdateRetries(1);
mockSerializer = EasyMock.createMock(HttpCacheEntrySerializer.class);
mockSerializer = EasyMock.createNiceMock(HttpCacheEntrySerializer.class);
impl = new EhcacheHttpCacheStorage(mockCache, config, mockSerializer);
}

View File

@ -71,7 +71,7 @@ public class TestEhcacheProtocolRequirements extends TestProtocolRequirements{
}
CACHE_MANAGER.addCache(TEST_EHCACHE_NAME);
HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME));
mockBackend = EasyMock.createMock(HttpClient.class);
mockBackend = EasyMock.createNiceMock(HttpClient.class);
impl = new CachingHttpClient(mockBackend, new HeapResourceFactory(), storage, params);
}

View File

@ -57,13 +57,13 @@ public class TestMemcachedHttpCacheStorage extends TestCase {
@Override
@Before
public void setUp() throws Exception {
mockMemcachedClient = EasyMock.createMock(MemcachedClientIF.class);
mockKeyHashingScheme = EasyMock.createMock(KeyHashingScheme.class);
mockMemcachedCacheEntryFactory = EasyMock.createMock(MemcachedCacheEntryFactory.class);
mockMemcachedCacheEntry = EasyMock.createMock(MemcachedCacheEntry.class);
mockMemcachedCacheEntry2 = EasyMock.createMock(MemcachedCacheEntry.class);
mockMemcachedCacheEntry3 = EasyMock.createMock(MemcachedCacheEntry.class);
mockMemcachedCacheEntry4 = EasyMock.createMock(MemcachedCacheEntry.class);
mockMemcachedClient = EasyMock.createNiceMock(MemcachedClientIF.class);
mockKeyHashingScheme = EasyMock.createNiceMock(KeyHashingScheme.class);
mockMemcachedCacheEntryFactory = EasyMock.createNiceMock(MemcachedCacheEntryFactory.class);
mockMemcachedCacheEntry = EasyMock.createNiceMock(MemcachedCacheEntry.class);
mockMemcachedCacheEntry2 = EasyMock.createNiceMock(MemcachedCacheEntry.class);
mockMemcachedCacheEntry3 = EasyMock.createNiceMock(MemcachedCacheEntry.class);
mockMemcachedCacheEntry4 = EasyMock.createNiceMock(MemcachedCacheEntry.class);
CacheConfig config = new CacheConfig();
config.setMaxUpdateRetries(1);
impl = new MemcachedHttpCacheStorage(mockMemcachedClient, config,