mirror of
https://github.com/square/okhttp.git
synced 2025-07-31 05:04:26 +03:00
Use more AssertJ features
This commit is contained in:
@ -19,7 +19,6 @@ import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import javax.annotation.Nullable;
|
||||
@ -40,6 +39,8 @@ import okhttp3.internal.platform.Platform;
|
||||
import okhttp3.internal.publicsuffix.PublicSuffixDatabase;
|
||||
import okio.ByteString;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* DNS over HTTPS implementation.
|
||||
*
|
||||
@ -348,7 +349,7 @@ public class DnsOverHttps implements Dns {
|
||||
}
|
||||
|
||||
public Builder bootstrapDnsHosts(InetAddress... bootstrapDnsHosts) {
|
||||
return bootstrapDnsHosts(Arrays.asList(bootstrapDnsHosts));
|
||||
return bootstrapDnsHosts(asList(bootstrapDnsHosts));
|
||||
}
|
||||
|
||||
public Builder systemDns(Dns systemDns) {
|
||||
|
@ -20,8 +20,6 @@ import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.Dns;
|
||||
@ -84,8 +82,8 @@ public class DnsOverHttpsTest {
|
||||
List<InetAddress> result = dns.lookup("google.com");
|
||||
|
||||
assertThat(result.size()).isEqualTo(2);
|
||||
assertThat(result.contains(address("157.240.1.18"))).isTrue();
|
||||
assertThat(result.contains(address("2a03:2880:f029:11:face:b00c:0:2"))).isTrue();
|
||||
assertThat(result).contains(address("157.240.1.18"));
|
||||
assertThat(result).contains(address("2a03:2880:f029:11:face:b00c:0:2"));
|
||||
|
||||
RecordedRequest request1 = server.takeRequest();
|
||||
assertThat(request1.getMethod()).isEqualTo("GET");
|
||||
@ -93,10 +91,9 @@ public class DnsOverHttpsTest {
|
||||
RecordedRequest request2 = server.takeRequest();
|
||||
assertThat(request2.getMethod()).isEqualTo("GET");
|
||||
|
||||
assertThat(new LinkedHashSet<>(Arrays.asList(request1.getPath(), request2.getPath()))).isEqualTo(
|
||||
new HashSet<>(
|
||||
Arrays.asList("/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ",
|
||||
"/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AABwAAQ")));
|
||||
assertThat(asList(request1.getPath(), request2.getPath())).containsExactlyInAnyOrder(
|
||||
"/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ",
|
||||
"/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AABwAAQ");
|
||||
}
|
||||
|
||||
@Test public void failure() throws Exception {
|
||||
@ -130,9 +127,8 @@ public class DnsOverHttpsTest {
|
||||
} catch (IOException ioe) {
|
||||
assertThat(ioe.getMessage()).isEqualTo("google.com");
|
||||
Throwable cause = ioe.getCause();
|
||||
assertThat(cause instanceof IOException).isTrue();
|
||||
assertThat(cause.getMessage()).isEqualTo(
|
||||
"response size exceeds limit (65536 bytes): 65537 bytes");
|
||||
assertThat(cause).isInstanceOf(IOException.class);
|
||||
assertThat(cause).hasMessage("response size exceeds limit (65536 bytes): 65537 bytes");
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,10 +139,8 @@ public class DnsOverHttpsTest {
|
||||
dns.lookup("google.com");
|
||||
fail();
|
||||
} catch (IOException ioe) {
|
||||
assertThat(ioe.getMessage()).isEqualTo("google.com");
|
||||
Throwable cause = ioe.getCause();
|
||||
boolean condition = cause instanceof RuntimeException;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(ioe).hasMessage("google.com");
|
||||
assertThat(ioe.getCause()).isInstanceOf(RuntimeException.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,13 +27,15 @@ import okhttp3.Cache;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class TestDohMain {
|
||||
public static void main(String[] args) throws IOException {
|
||||
Security.insertProviderAt(new org.conscrypt.OpenSSLProvider(), 1);
|
||||
|
||||
OkHttpClient bootstrapClient = new OkHttpClient.Builder().build();
|
||||
|
||||
List<String> names = Arrays.asList("google.com", "graph.facebook.com", "sdflkhfsdlkjdf.ee");
|
||||
List<String> names = asList("google.com", "graph.facebook.com", "sdflkhfsdlkjdf.ee");
|
||||
|
||||
try {
|
||||
System.out.println("uncached\n********\n");
|
||||
@ -53,7 +55,7 @@ public class TestDohMain {
|
||||
runBatch(badProviders, names);
|
||||
|
||||
System.out.println("cached first run\n****************\n");
|
||||
names = Arrays.asList("google.com", "graph.facebook.com");
|
||||
names = asList("google.com", "graph.facebook.com");
|
||||
bootstrapClient = bootstrapClient.newBuilder().cache(dnsCache).build();
|
||||
dnsProviders = DohProviders.providers(bootstrapClient, true, true, true);
|
||||
runBatch(dnsProviders, names);
|
||||
|
Reference in New Issue
Block a user