Code cleanup: replaced anonymous inner classes with lambdas.

This commit is contained in:
Simone Bordet 2017-09-11 17:02:32 +02:00
parent 172bf27922
commit b078c910a7
1 changed files with 39 additions and 97 deletions

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.client;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@ -29,9 +28,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.ssl.SslContextFactory;
@ -53,22 +49,11 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.onResponseBegin(new Response.BeginListener()
{
@Override
public void onBegin(Response response)
{
response.abort(new Exception());
}
})
.send(new Response.CompleteListener()
{
@Override
public void onComplete(Result result)
.onResponseBegin(response -> response.abort(new Exception()))
.send(result ->
{
Assert.assertTrue(result.isFailed());
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
@ -81,23 +66,15 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.onResponseHeader(new Response.HeaderListener()
{
@Override
public boolean onHeader(Response response, HttpField field)
.onResponseHeader((response, field) ->
{
response.abort(new Exception());
return true;
}
})
.send(new Response.CompleteListener()
{
@Override
public void onComplete(Result result)
.send(result ->
{
Assert.assertTrue(result.isFailed());
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
@ -110,23 +87,11 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.onResponseHeaders(new Response.HeadersListener()
{
@Override
public void onHeaders(Response response)
{
response.abort(new Exception());
}
})
.send(new Response.CompleteListener()
{
@Override
public void onComplete(Result result)
.onResponseHeaders(response -> response.abort(new Exception()))
.send(result ->
{
Assert.assertTrue(result.isFailed());
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
@ -158,22 +123,11 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.onResponseContent(new Response.ContentListener()
{
@Override
public void onContent(Response response, ByteBuffer content)
{
response.abort(new Exception());
}
})
.send(new Response.CompleteListener()
{
@Override
public void onComplete(Result result)
.onResponseContent((response, content) -> response.abort(new Exception()))
.send(result ->
{
Assert.assertTrue(result.isFailed());
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
@ -207,10 +161,7 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
final CountDownLatch completeLatch = new CountDownLatch(1);
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.onRequestSuccess(new org.eclipse.jetty.client.api.Request.SuccessListener()
{
@Override
public void onSuccess(org.eclipse.jetty.client.api.Request request)
.onRequestSuccess(request ->
{
try
{
@ -220,12 +171,8 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
{
x.printStackTrace();
}
}
})
.onResponseContent(new Response.ContentListener()
{
@Override
public void onContent(Response response, ByteBuffer content)
.onResponseContent((response, content) ->
{
try
{
@ -238,17 +185,12 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
{
x.printStackTrace();
}
}
})
.send(new Response.CompleteListener()
{
@Override
public void onComplete(Result result)
.send(result ->
{
completes.incrementAndGet();
Assert.assertTrue(result.isFailed());
completeLatch.countDown();
}
});
Assert.assertTrue(completeLatch.await(5, TimeUnit.SECONDS));