Skip to content

Commit

Permalink
Remove deprecated TestingResponse constructors and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
johngmyers committed Jan 9, 2017
1 parent 853feb7 commit d272afc
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 49 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -5,6 +5,8 @@ Platform 1.50
We removed the following deprecated features:

- The TestingHttpClient constructors taking Function
- The public TestingResponse constructors
- TestingResponse.mockResponse(HttpStatus, MediaType, String)
- The unused http-client.keep-alive-interval config option

* Version numbers
Expand Down
@@ -1,7 +1,6 @@
package com.proofpoint.http.client.testing;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.Charsets;
import com.google.common.base.Objects;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableListMultimap;
Expand Down Expand Up @@ -36,21 +35,12 @@ public class TestingResponse
private final ListMultimap<HeaderName, String> headers;
private final CountingInputStream countingInputStream;

/**
* @deprecated use {@link TestingResponse#mockResponse()}{@code .status(status).headers(header).body(bytes).build()}
*/
@Deprecated
@SuppressWarnings("deprecation")
public TestingResponse(HttpStatus status, ListMultimap<String, String> headers, byte[] bytes)
private TestingResponse(HttpStatus status, ListMultimap<String, String> headers, byte[] bytes)
{
this(status, headers, new ByteArrayInputStream(checkNotNull(bytes, "bytes is null")));
}

/**
* @deprecated use {@link TestingResponse#mockResponse()}{@code .status(status).headers(header).body(input).build()}
*/
@Deprecated
public TestingResponse(HttpStatus status, ListMultimap<String, String> headers, InputStream input)
private TestingResponse(HttpStatus status, ListMultimap<String, String> headers, InputStream input)
{
this.status = requireNonNull(status, "status is null");
this.headers = ImmutableListMultimap.copyOf(toHeaderMap(checkNotNull(headers, "headers is null")));
Expand Down Expand Up @@ -106,22 +96,11 @@ public static ListMultimap<String, String> contentType(MediaType type)
/**
* Returns a response with the specified status.
*/
@SuppressWarnings("deprecation")
public static Response mockResponse(HttpStatus status)
{
return new TestingResponse(status, ImmutableListMultimap.<String, String>of(), new byte[0]);
}

/**
* @deprecated use {@link TestingResponse#mockResponse()}{@code .status(status).contentType(type).body(content).build()}
*/
@Deprecated
@SuppressWarnings("deprecation")
public static Response mockResponse(HttpStatus status, MediaType type, String content)
{
return new TestingResponse(status, contentType(type), content.getBytes(Charsets.UTF_8));
}

/**
* Returns a new builder.
*/
Expand Down Expand Up @@ -251,7 +230,6 @@ public Builder jsonBody(@Nullable Object entity)
/**
* Returns a newly created TestingResponse.
*/
@SuppressWarnings("deprecation")
public TestingResponse build()
{
if (status == null) {
Expand Down
Expand Up @@ -13,7 +13,6 @@
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
import static com.proofpoint.http.client.DefaultingJsonResponseHandler.createDefaultingJsonResponseHandler;
import static com.proofpoint.http.client.HttpStatus.INTERNAL_SERVER_ERROR;
import static com.proofpoint.http.client.HttpStatus.OK;
import static com.proofpoint.http.client.testing.TestingResponse.mockResponse;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
Expand Down Expand Up @@ -42,7 +41,7 @@ public void testValidJson()
{
User user = new User("Joe", 25);
String json = codec.toJson(user);
User response = handler.handle(null, mockResponse(OK, JSON_UTF_8, json));
User response = handler.handle(null, mockResponse().contentType(JSON_UTF_8).body(json).build());

assertEquals(response.getName(), user.getName());
assertEquals(response.getAge(), user.getAge());
Expand All @@ -52,7 +51,7 @@ public void testValidJson()
public void testInvalidJson()
{
String json = "{\"age\": \"foo\"}";
User response = handler.handle(null, mockResponse(OK, JSON_UTF_8, json));
User response = handler.handle(null, mockResponse().contentType(JSON_UTF_8).body(json).build());

assertSame(response, DEFAULT_VALUE);
}
Expand All @@ -61,7 +60,7 @@ public void testInvalidJson()
public void testSyntacticallyInvalidJson()
{
String json = "foo";
User response = handler.handle(null, mockResponse(OK, JSON_UTF_8, json));
User response = handler.handle(null, mockResponse().contentType(JSON_UTF_8).body(json).build());

assertSame(response, DEFAULT_VALUE);
}
Expand All @@ -77,7 +76,7 @@ public void testException()
@Test
public void testNonJsonResponse()
{
User response = handler.handle(null, mockResponse(OK, PLAIN_TEXT_UTF_8, "hello"));
User response = handler.handle(null, mockResponse().contentType(PLAIN_TEXT_UTF_8).body("hello").build());

assertSame(response, DEFAULT_VALUE);
}
Expand All @@ -86,7 +85,7 @@ public void testNonJsonResponse()
public void testJsonErrorResponse()
{
String json = "{\"error\": true}";
User response = handler.handle(null, mockResponse(INTERNAL_SERVER_ERROR, JSON_UTF_8, json));
User response = handler.handle(null, mockResponse().status(INTERNAL_SERVER_ERROR).contentType(JSON_UTF_8).body(json).build());

assertSame(response, DEFAULT_VALUE);
}
Expand Down
Expand Up @@ -15,7 +15,6 @@
import static com.proofpoint.http.client.FullJsonResponseHandler.JsonResponse;
import static com.proofpoint.http.client.FullJsonResponseHandler.createFullJsonResponseHandler;
import static com.proofpoint.http.client.HttpStatus.INTERNAL_SERVER_ERROR;
import static com.proofpoint.http.client.HttpStatus.OK;
import static com.proofpoint.http.client.testing.TestingResponse.mockResponse;
import static com.proofpoint.testing.Assertions.assertInstanceOf;
import static org.mockito.Matchers.any;
Expand Down Expand Up @@ -48,7 +47,7 @@ public void testValidJson()
{
User user = new User("Joe", 25);
String json = codec.toJson(user);
JsonResponse<User> response = handler.handle(null, mockResponse(OK, JSON_UTF_8, json));
JsonResponse<User> response = handler.handle(null, mockResponse().contentType(JSON_UTF_8).body(json).build());

assertTrue(response.hasValue());
assertEquals(response.getJsonBytes(), json.getBytes(UTF_8));
Expand All @@ -69,7 +68,7 @@ public void testValidJson()
public void testInvalidJson()
{
String json = "{\"age\": \"foo\"}";
JsonResponse<User> response = handler.handle(null, mockResponse(OK, JSON_UTF_8, json));
JsonResponse<User> response = handler.handle(null, mockResponse().contentType(JSON_UTF_8).body(json).build());

assertFalse(response.hasValue());
assertEquals(response.getException().getMessage(),
Expand All @@ -87,7 +86,7 @@ public void testInvalidJson()
public void testInvalidJsonGetValue()
{
String json = "{\"age\": \"foo\"}";
JsonResponse<User> response = handler.handle(null, mockResponse(OK, JSON_UTF_8, json));
JsonResponse<User> response = handler.handle(null, mockResponse().contentType(JSON_UTF_8).body(json).build());

try {
response.getValue();
Expand All @@ -108,7 +107,7 @@ public void testInvalidJsonGetValue()
@Test
public void testNonJsonResponse()
{
JsonResponse<User> response = handler.handle(null, mockResponse(OK, PLAIN_TEXT_UTF_8, "hello"));
JsonResponse<User> response = handler.handle(null, mockResponse().contentType(PLAIN_TEXT_UTF_8).body("hello").build());

assertFalse(response.hasValue());
assertNull(response.getException());
Expand Down Expand Up @@ -139,7 +138,7 @@ public void testMissingContentType()
public void testJsonErrorResponse()
{
String json = "{\"error\": true}";
JsonResponse<User> response = handler.handle(null, mockResponse(INTERNAL_SERVER_ERROR, JSON_UTF_8, json));
JsonResponse<User> response = handler.handle(null, mockResponse().status(INTERNAL_SERVER_ERROR).contentType(JSON_UTF_8).body(json).build());

assertTrue(response.hasValue());
assertEquals(response.getJson(), json);
Expand Down
Expand Up @@ -99,7 +99,7 @@ public void testInvalidSmileGetValue()
@Test
public void testNonSmileResponse()
{
SmileResponse<User> response = handler.handle(null, mockResponse(OK, PLAIN_TEXT_UTF_8, "hello"));
SmileResponse<User> response = handler.handle(null, mockResponse().contentType(PLAIN_TEXT_UTF_8).body("hello").build());

assertFalse(response.hasValue());
assertNull(response.getException());
Expand Down
Expand Up @@ -92,7 +92,7 @@ public void testMissingContentType()
public void testJsonErrorResponse()
{
String json = "{\"error\": true}";
handler.handle(null, mockResponse(INTERNAL_SERVER_ERROR, JSON_UTF_8, json));
handler.handle(null, mockResponse().status(INTERNAL_SERVER_ERROR).contentType(JSON_UTF_8).body(json).build());
}

@Test
Expand Down
Expand Up @@ -34,17 +34,6 @@ public void testStatus()
assertResponse(mockResponse(HttpStatus.IM_A_TEAPOT), HttpStatus.IM_A_TEAPOT, ImmutableListMultimap.of(), new byte[0]);
}

@Test
@SuppressWarnings("deprecation")
public void testStringContent()
{
assertResponse(mockResponse(HttpStatus.ENHANCE_YOUR_CALM, MediaType.TEXT_JAVASCRIPT_UTF_8, "neé"),
HttpStatus.ENHANCE_YOUR_CALM,
ImmutableListMultimap.of("Content-Type", "text/javascript; charset=utf-8"),
new byte[] { 'n', 'e', -61, -87}
);
}

@Test
public void testBuilderDefault()
{
Expand Down

0 comments on commit d272afc

Please sign in to comment.