Skip to content

Commit

Permalink
Clean up ShadowDefaultRequestDirectorTest.java
Browse files Browse the repository at this point in the history
1. Remove unused Exception from test method.
2. Replace anonymous class with lambda for method input parameter.

Signed-off-by: utzcoz <utzcoz@outlook.com>
  • Loading branch information
utzcoz committed Apr 3, 2022
1 parent 2ca9115 commit fa03046
Showing 1 changed file with 7 additions and 23 deletions.
Expand Up @@ -18,7 +18,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
Expand All @@ -31,7 +30,6 @@
import org.apache.http.message.BasicHeader;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -52,13 +50,7 @@ public void setUp_EnsureStaticStateIsReset() {
assertFalse(fakeHttpLayer.hasRequestInfos());
assertFalse(fakeHttpLayer.hasResponseRules());

connectionKeepAliveStrategy =
new ConnectionKeepAliveStrategy() {
@Override
public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) {
return 0;
}
};
connectionKeepAliveStrategy = (httpResponse, httpContext) -> 0;
requestDirector =
new DefaultRequestDirector(
null,
Expand All @@ -76,7 +68,7 @@ public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpCont
}

@After
public void tearDown_EnsureStaticStateIsReset() throws Exception {
public void tearDown_EnsureStaticStateIsReset() {
FakeHttp.addPendingHttpResponse(200, "a happy response body");
}

Expand Down Expand Up @@ -213,12 +205,9 @@ public void clearPendingHttpResponses() throws Exception {
public void shouldReturnRequestsByRule_WithCustomRequestMatcher() throws Exception {
FakeHttp.setDefaultHttpResponse(404, "no such page");

FakeHttp.addHttpResponseRule(new RequestMatcher() {
@Override
public boolean matches(HttpRequest request) {
return request.getRequestLine().getUri().equals("http://matching.uri");
}
}, new TestHttpResponse(200, "a cheery response body"));
FakeHttp.addHttpResponseRule(
request -> request.getRequestLine().getUri().equals("http://matching.uri"),
new TestHttpResponse(200, "a cheery response body"));

HttpResponse response = requestDirector.execute(null, new HttpGet("http://matching.uri"), null);
assertNotNull(response);
Expand Down Expand Up @@ -392,7 +381,7 @@ public HttpParams getParams() {
}

@Test
public void shouldSupportRealHttpRequests() throws Exception {
public void shouldSupportRealHttpRequests() {
FakeHttp.getFakeHttpLayer().interceptHttpRequests(false);
DefaultHttpClient client = new DefaultHttpClient();

Expand Down Expand Up @@ -441,12 +430,7 @@ public void realHttpRequestsShouldMakeContentDataAvailable() throws Exception {

@Test
public void shouldReturnResponseFromHttpResponseGenerator() throws Exception {
FakeHttp.addPendingHttpResponse(new HttpResponseGenerator() {
@Override
public HttpResponse getResponse(HttpRequest request) {
return new TestHttpResponse(200, "a happy response body");
}
});
FakeHttp.addPendingHttpResponse(request -> new TestHttpResponse(200, "a happy response body"));
HttpResponse response = requestDirector.execute(null, new HttpGet("http://example.com"), null);

assertNotNull(response);
Expand Down

0 comments on commit fa03046

Please sign in to comment.