mirror of
https://github.com/square/okhttp.git
synced 2025-11-26 06:43:09 +03:00
Use lambdas where appropriate
This commit is contained in:
@@ -17,7 +17,6 @@ package okhttp3;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -32,11 +31,9 @@ public final class TestUtil {
|
||||
* A network that resolves only one IP address per host. Use this when testing route selection
|
||||
* fallbacks to prevent the host machine's various IP addresses from interfering.
|
||||
*/
|
||||
private static final Dns SINGLE_INET_ADDRESS_DNS = new Dns() {
|
||||
@Override public List<InetAddress> lookup(String hostname) throws UnknownHostException {
|
||||
List<InetAddress> addresses = Dns.SYSTEM.lookup(hostname);
|
||||
return Collections.singletonList(addresses.get(0));
|
||||
}
|
||||
private static final Dns SINGLE_INET_ADDRESS_DNS = hostname -> {
|
||||
List<InetAddress> addresses = Dns.SYSTEM.lookup(hostname);
|
||||
return Collections.singletonList(addresses.get(0));
|
||||
};
|
||||
|
||||
private TestUtil() {
|
||||
|
||||
@@ -38,24 +38,22 @@ public class InstallUncaughtExceptionHandlerListener extends RunListener {
|
||||
@Override public void testRunStarted(Description description) {
|
||||
System.err.println("Installing aggressive uncaught exception handler");
|
||||
oldDefaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
||||
@Override public void uncaughtException(Thread thread, Throwable throwable) {
|
||||
StringWriter errorText = new StringWriter(256);
|
||||
errorText.append("Uncaught exception in OkHttp thread \"");
|
||||
errorText.append(thread.getName());
|
||||
errorText.append("\"\n");
|
||||
throwable.printStackTrace(new PrintWriter(errorText));
|
||||
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
|
||||
StringWriter errorText = new StringWriter(256);
|
||||
errorText.append("Uncaught exception in OkHttp thread \"");
|
||||
errorText.append(thread.getName());
|
||||
errorText.append("\"\n");
|
||||
throwable.printStackTrace(new PrintWriter(errorText));
|
||||
errorText.append("\n");
|
||||
if (lastTestStarted != null) {
|
||||
errorText.append("Last test to start was: ");
|
||||
errorText.append(lastTestStarted.getDisplayName());
|
||||
errorText.append("\n");
|
||||
if (lastTestStarted != null) {
|
||||
errorText.append("Last test to start was: ");
|
||||
errorText.append(lastTestStarted.getDisplayName());
|
||||
errorText.append("\n");
|
||||
}
|
||||
System.err.print(errorText.toString());
|
||||
}
|
||||
System.err.print(errorText.toString());
|
||||
|
||||
synchronized (exceptions) {
|
||||
exceptions.put(throwable, lastTestStarted.getDisplayName());
|
||||
}
|
||||
synchronized (exceptions) {
|
||||
exceptions.put(throwable, lastTestStarted.getDisplayName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user