diff --git a/mockwebserver/pom.xml b/mockwebserver/pom.xml
index 888ddcf7c..acd99abb2 100644
--- a/mockwebserver/pom.xml
+++ b/mockwebserver/pom.xml
@@ -34,6 +34,11 @@
junit
junit
+
+ org.assertj
+ assertj-core
+ test
+
diff --git a/mockwebserver/src/test/java/okhttp3/mockwebserver/CustomDispatcherTest.java b/mockwebserver/src/test/java/okhttp3/mockwebserver/CustomDispatcherTest.java
index 0a43dd916..ab69ac808 100644
--- a/mockwebserver/src/test/java/okhttp3/mockwebserver/CustomDispatcherTest.java
+++ b/mockwebserver/src/test/java/okhttp3/mockwebserver/CustomDispatcherTest.java
@@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.After;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
public class CustomDispatcherTest {
private MockWebServer mockWebServer = new MockWebServer();
@@ -44,13 +44,13 @@ public class CustomDispatcherTest {
return new MockResponse();
}
};
- assertEquals(0, requestsMade.size());
+ assertThat(requestsMade.size()).isEqualTo(0);
mockWebServer.setDispatcher(dispatcher);
final URL url = mockWebServer.url("/").url();
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.getResponseCode(); // Force the connection to hit the "server".
// Make sure our dispatcher got the request.
- assertEquals(1, requestsMade.size());
+ assertThat(requestsMade.size()).isEqualTo(1);
}
@Test public void outOfOrderResponses() throws Exception {
@@ -75,12 +75,16 @@ public class CustomDispatcherTest {
final Thread endsFirst = buildRequestThread(secondRequest, secondResponseCode);
endsFirst.start();
endsFirst.join();
- assertEquals(0, firstResponseCode.get()); // First response is still waiting.
- assertEquals(200, secondResponseCode.get()); // Second response is done.
+ // First response is still waiting.
+ assertThat(firstResponseCode.get()).isEqualTo(0);
+ // Second response is done.
+ assertThat(secondResponseCode.get()).isEqualTo(200);
latch.countDown();
startsFirst.join();
- assertEquals(200, firstResponseCode.get()); // And now it's done!
- assertEquals(200, secondResponseCode.get()); // (Still done).
+ // And now it's done!
+ assertThat(firstResponseCode.get()).isEqualTo(200);
+ // (Still done).
+ assertThat(secondResponseCode.get()).isEqualTo(200);
}
private Thread buildRequestThread(String path, AtomicInteger responseCode) {
diff --git a/mockwebserver/src/test/java/okhttp3/mockwebserver/MockWebServerTest.java b/mockwebserver/src/test/java/okhttp3/mockwebserver/MockWebServerTest.java
index 67f417e73..df4d59b4a 100644
--- a/mockwebserver/src/test/java/okhttp3/mockwebserver/MockWebServerTest.java
+++ b/mockwebserver/src/test/java/okhttp3/mockwebserver/MockWebServerTest.java
@@ -51,11 +51,8 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static okhttp3.tls.internal.TlsUtil.localhost;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.data.Offset.offset;
import static org.junit.Assert.fail;
public final class MockWebServerTest {
@@ -63,8 +60,8 @@ public final class MockWebServerTest {
@Test public void defaultMockResponse() {
MockResponse response = new MockResponse();
- assertEquals(Arrays.asList("Content-Length: 0"), headersToList(response));
- assertEquals("HTTP/1.1 200 OK", response.getStatus());
+ assertThat(headersToList(response)).containsExactly("Content-Length: 0");
+ assertThat(response.getStatus()).isEqualTo("HTTP/1.1 200 OK");
}
@Test public void setResponseMockReason() {
@@ -80,21 +77,21 @@ public final class MockWebServerTest {
for (int i = 0; i < 600; i++) {
MockResponse response = new MockResponse().setResponseCode(i);
String expectedReason = reasons[i / 100];
- assertEquals("HTTP/1.1 " + i + " " + expectedReason, response.getStatus());
- assertEquals(Arrays.asList("Content-Length: 0"), headersToList(response));
+ assertThat(response.getStatus()).isEqualTo(("HTTP/1.1 " + i + " " + expectedReason));
+ assertThat(headersToList(response)).containsExactly("Content-Length: 0");
}
}
@Test public void setStatusControlsWholeStatusLine() {
MockResponse response = new MockResponse().setStatus("HTTP/1.1 202 That'll do pig");
- assertEquals(Arrays.asList("Content-Length: 0"), headersToList(response));
- assertEquals("HTTP/1.1 202 That'll do pig", response.getStatus());
+ assertThat(headersToList(response)).containsExactly("Content-Length: 0");
+ assertThat(response.getStatus()).isEqualTo("HTTP/1.1 202 That'll do pig");
}
@Test public void setBodyAdjustsHeaders() throws IOException {
MockResponse response = new MockResponse().setBody("ABC");
- assertEquals(Arrays.asList("Content-Length: 3"), headersToList(response));
- assertEquals("ABC", response.getBody().readUtf8());
+ assertThat(headersToList(response)).containsExactly("Content-Length: 3");
+ assertThat(response.getBody().readUtf8()).isEqualTo("ABC");
}
@Test public void mockResponseAddHeader() {
@@ -102,7 +99,7 @@ public final class MockWebServerTest {
.clearHeaders()
.addHeader("Cookie: s=square")
.addHeader("Cookie", "a=android");
- assertEquals(Arrays.asList("Cookie: s=square", "Cookie: a=android"), headersToList(response));
+ assertThat(headersToList(response)).containsExactly("Cookie: s=square", "Cookie: a=android");
}
@Test public void mockResponseSetHeader() {
@@ -112,7 +109,7 @@ public final class MockWebServerTest {
.addHeader("Cookie: a=android")
.addHeader("Cookies: delicious");
response.setHeader("cookie", "r=robot");
- assertEquals(Arrays.asList("Cookies: delicious", "cookie: r=robot"), headersToList(response));
+ assertThat(headersToList(response)).containsExactly("Cookies: delicious", "cookie: r=robot");
}
@Test public void mockResponseSetHeaders() {
@@ -123,7 +120,7 @@ public final class MockWebServerTest {
response.setHeaders(new Headers.Builder().add("Cookie", "a=android").build());
- assertEquals(Arrays.asList("Cookie: a=android"), headersToList(response));
+ assertThat(headersToList(response)).containsExactly("Cookie: a=android");
}
@Test public void regularResponse() throws Exception {
@@ -134,12 +131,12 @@ public final class MockWebServerTest {
connection.setRequestProperty("Accept-Language", "en-US");
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
- assertEquals("hello world", reader.readLine());
+ assertThat(connection.getResponseCode()).isEqualTo(HttpURLConnection.HTTP_OK);
+ assertThat(reader.readLine()).isEqualTo("hello world");
RecordedRequest request = server.takeRequest();
- assertEquals("GET / HTTP/1.1", request.getRequestLine());
- assertEquals("en-US", request.getHeader("Accept-Language"));
+ assertThat(request.getRequestLine()).isEqualTo("GET / HTTP/1.1");
+ assertThat(request.getHeader("Accept-Language")).isEqualTo("en-US");
}
@Test public void redirect() throws Exception {
@@ -152,12 +149,12 @@ public final class MockWebServerTest {
URLConnection connection = server.url("/").url().openConnection();
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- assertEquals("This is the new location!", reader.readLine());
+ assertThat(reader.readLine()).isEqualTo("This is the new location!");
RecordedRequest first = server.takeRequest();
- assertEquals("GET / HTTP/1.1", first.getRequestLine());
+ assertThat(first.getRequestLine()).isEqualTo("GET / HTTP/1.1");
RecordedRequest redirect = server.takeRequest();
- assertEquals("GET /new-path HTTP/1.1", redirect.getRequestLine());
+ assertThat(redirect.getRequestLine()).isEqualTo("GET /new-path HTTP/1.1");
}
/**
@@ -176,7 +173,7 @@ public final class MockWebServerTest {
URLConnection connection = server.url("/").url().openConnection();
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- assertEquals("enqueued in the background", reader.readLine());
+ assertThat(reader.readLine()).isEqualTo("enqueued in the background");
}
@Test public void nonHexadecimalChunkSize() throws Exception {
@@ -204,9 +201,9 @@ public final class MockWebServerTest {
URLConnection urlConnection = server.url("/").url().openConnection();
urlConnection.setReadTimeout(1000);
InputStream in = urlConnection.getInputStream();
- assertEquals('A', in.read());
- assertEquals('B', in.read());
- assertEquals('C', in.read());
+ assertThat(in.read()).isEqualTo('A');
+ assertThat(in.read()).isEqualTo('B');
+ assertThat(in.read()).isEqualTo('C');
try {
in.read(); // if Content-Length was accurate, this would return -1 immediately
fail();
@@ -215,13 +212,13 @@ public final class MockWebServerTest {
URLConnection urlConnection2 = server.url("/").url().openConnection();
InputStream in2 = urlConnection2.getInputStream();
- assertEquals('D', in2.read());
- assertEquals('E', in2.read());
- assertEquals('F', in2.read());
- assertEquals(-1, in2.read());
+ assertThat(in2.read()).isEqualTo('D');
+ assertThat(in2.read()).isEqualTo('E');
+ assertThat(in2.read()).isEqualTo('F');
+ assertThat(in2.read()).isEqualTo(-1);
- assertEquals(0, server.takeRequest().getSequenceNumber());
- assertEquals(0, server.takeRequest().getSequenceNumber());
+ assertThat(server.takeRequest().getSequenceNumber()).isEqualTo(0);
+ assertThat(server.takeRequest().getSequenceNumber()).isEqualTo(0);
}
@Test public void disconnectAtStart() throws Exception {
@@ -248,12 +245,14 @@ public final class MockWebServerTest {
connection.setDoOutput(true);
connection.getOutputStream().write("ABCDEF".getBytes(UTF_8));
InputStream in = connection.getInputStream();
- assertEquals(-1, in.read());
+ assertThat(in.read()).isEqualTo(-1);
long elapsedNanos = System.nanoTime() - startNanos;
long elapsedMillis = NANOSECONDS.toMillis(elapsedNanos);
- assertTrue(Util.format("Request + Response: %sms", elapsedMillis), elapsedMillis >= 500);
- assertTrue(Util.format("Request + Response: %sms", elapsedMillis), elapsedMillis < 1000);
+ assertThat(elapsedMillis >= 500).overridingErrorMessage(
+ Util.format("Request + Response: %sms", elapsedMillis)).isTrue();
+ assertThat(elapsedMillis < 1000).overridingErrorMessage(
+ Util.format("Request + Response: %sms", elapsedMillis)).isTrue();
}
/**
@@ -268,18 +267,20 @@ public final class MockWebServerTest {
long startNanos = System.nanoTime();
URLConnection connection = server.url("/").url().openConnection();
InputStream in = connection.getInputStream();
- assertEquals('A', in.read());
- assertEquals('B', in.read());
- assertEquals('C', in.read());
- assertEquals('D', in.read());
- assertEquals('E', in.read());
- assertEquals('F', in.read());
- assertEquals(-1, in.read());
+ assertThat(in.read()).isEqualTo('A');
+ assertThat(in.read()).isEqualTo('B');
+ assertThat(in.read()).isEqualTo('C');
+ assertThat(in.read()).isEqualTo('D');
+ assertThat(in.read()).isEqualTo('E');
+ assertThat(in.read()).isEqualTo('F');
+ assertThat(in.read()).isEqualTo(-1);
long elapsedNanos = System.nanoTime() - startNanos;
long elapsedMillis = NANOSECONDS.toMillis(elapsedNanos);
- assertTrue(Util.format("Request + Response: %sms", elapsedMillis), elapsedMillis >= 500);
- assertTrue(Util.format("Request + Response: %sms", elapsedMillis), elapsedMillis < 1000);
+ assertThat(elapsedMillis >= 500).overridingErrorMessage(
+ Util.format("Request + Response: %sms", elapsedMillis)).isTrue();
+ assertThat(elapsedMillis < 1000).overridingErrorMessage(
+ Util.format("Request + Response: %sms", elapsedMillis)).isTrue();
}
/** Delay the response body by sleeping 1s. */
@@ -291,10 +292,11 @@ public final class MockWebServerTest {
long startNanos = System.nanoTime();
URLConnection connection = server.url("/").url().openConnection();
InputStream in = connection.getInputStream();
- assertEquals('A', in.read());
+ assertThat(in.read()).isEqualTo('A');
long elapsedNanos = System.nanoTime() - startNanos;
long elapsedMillis = NANOSECONDS.toMillis(elapsedNanos);
- assertTrue(Util.format("Request + Response: %sms", elapsedMillis), elapsedMillis >= 1000);
+ assertThat(elapsedMillis >= 1000).overridingErrorMessage(
+ Util.format("Request + Response: %sms", elapsedMillis)).isTrue();
in.close();
}
@@ -326,7 +328,8 @@ public final class MockWebServerTest {
break;
}
}
- assertEquals(512f, i, 5f); // Halfway +/- 0.5%
+ // Halfway +/- 0.5%
+ assertThat((float) i).isCloseTo(512f, offset(5f));
}
@Test public void disconnectResponseHalfway() throws IOException {
@@ -335,13 +338,13 @@ public final class MockWebServerTest {
.setSocketPolicy(SocketPolicy.DISCONNECT_DURING_RESPONSE_BODY));
URLConnection connection = server.url("/").url().openConnection();
- assertEquals(2, connection.getContentLength());
+ assertThat(connection.getContentLength()).isEqualTo(2);
InputStream in = connection.getInputStream();
- assertEquals('a', in.read());
+ assertThat(in.read()).isEqualTo('a');
try {
int byteRead = in.read();
// OpenJDK behavior: end of stream.
- assertEquals(-1, byteRead);
+ assertThat(byteRead).isEqualTo(-1);
} catch (ProtocolException e) {
// On Android, HttpURLConnection is implemented by OkHttp v2. OkHttp
// treats an incomplete response body as a ProtocolException.
@@ -379,20 +382,20 @@ public final class MockWebServerTest {
}
@Test public void portImplicitlyStarts() throws IOException {
- assertTrue(server.getPort() > 0);
+ assertThat(server.getPort() > 0).isTrue();
}
@Test public void hostnameImplicitlyStarts() throws IOException {
- assertNotNull(server.getHostName());
+ assertThat(server.getHostName()).isNotNull();
}
@Test public void toProxyAddressImplicitlyStarts() throws IOException {
- assertNotNull(server.toProxyAddress());
+ assertThat(server.toProxyAddress()).isNotNull();
}
@Test public void differentInstancesGetDifferentPorts() throws IOException {
MockWebServer other = new MockWebServer();
- assertNotEquals(server.getPort(), other.getPort());
+ assertThat(other.getPort()).isNotEqualTo(server.getPort());
other.shutdown();
}
@@ -407,7 +410,7 @@ public final class MockWebServerTest {
statement.evaluate();
- assertTrue(called.get());
+ assertThat(called.get()).isTrue();
try {
server.url("/").url().openConnection().connect();
fail();
@@ -436,18 +439,19 @@ public final class MockWebServerTest {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
- assertEquals("hello world", reader.readLine());
+ assertThat(connection.getResponseCode()).isEqualTo(HttpURLConnection.HTTP_OK);
+ assertThat(reader.readLine()).isEqualTo("hello world");
RecordedRequest request = server.takeRequest();
- assertEquals("GET /a/deep/path?key=foo%20bar HTTP/1.1", request.getRequestLine());
+ assertThat(request.getRequestLine()).isEqualTo(
+ "GET /a/deep/path?key=foo%20bar HTTP/1.1");
HttpUrl requestUrl = request.getRequestUrl();
- assertEquals("http", requestUrl.scheme());
- assertEquals(server.getHostName(), requestUrl.host());
- assertEquals(server.getPort(), requestUrl.port());
- assertEquals("/a/deep/path", requestUrl.encodedPath());
- assertEquals("foo bar", requestUrl.queryParameter("key"));
+ assertThat(requestUrl.scheme()).isEqualTo("http");
+ assertThat(requestUrl.host()).isEqualTo(server.getHostName());
+ assertThat(requestUrl.port()).isEqualTo(server.getPort());
+ assertThat(requestUrl.encodedPath()).isEqualTo("/a/deep/path");
+ assertThat(requestUrl.queryParameter("key")).isEqualTo("foo bar");
}
@Test public void shutdownServerAfterRequest() throws Exception {
@@ -456,7 +460,7 @@ public final class MockWebServerTest {
URL url = server.url("/").url();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
+ assertThat(connection.getResponseCode()).isEqualTo(HttpURLConnection.HTTP_OK);
HttpURLConnection refusedConnection = (HttpURLConnection) url.openConnection();
@@ -464,7 +468,7 @@ public final class MockWebServerTest {
refusedConnection.getResponseCode();
fail("Second connection should be refused");
} catch (ConnectException e ) {
- assertTrue(e.getMessage().contains("refused"));
+ assertThat(e.getMessage().contains("refused")).isTrue();
}
}
@@ -479,10 +483,10 @@ public final class MockWebServerTest {
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- assertEquals("response", reader.readLine());
+ assertThat(reader.readLine()).isEqualTo("response");
RecordedRequest request = server.takeRequest();
- assertEquals("request", request.getBody().readUtf8());
+ assertThat(request.getBody().readUtf8()).isEqualTo("request");
}
@Test public void testH2PriorKnowledgeServerFallback() {
@@ -490,8 +494,9 @@ public final class MockWebServerTest {
server.setProtocols(Arrays.asList(Protocol.H2_PRIOR_KNOWLEDGE, Protocol.HTTP_1_1));
fail();
} catch (IllegalArgumentException expected) {
- assertEquals("protocols containing h2_prior_knowledge cannot use other protocols: "
- + "[h2_prior_knowledge, http/1.1]", expected.getMessage());
+ assertThat(expected.getMessage()).isEqualTo(
+ ("protocols containing h2_prior_knowledge cannot use other protocols: "
+ + "[h2_prior_knowledge, http/1.1]"));
}
}
@@ -501,16 +506,17 @@ public final class MockWebServerTest {
server.setProtocols(Arrays.asList(Protocol.H2_PRIOR_KNOWLEDGE, Protocol.H2_PRIOR_KNOWLEDGE));
fail();
} catch (IllegalArgumentException expected) {
- assertEquals("protocols containing h2_prior_knowledge cannot use other protocols: "
- + "[h2_prior_knowledge, h2_prior_knowledge]", expected.getMessage());
+ assertThat(expected.getMessage()).isEqualTo(
+ ("protocols containing h2_prior_knowledge cannot use other protocols: "
+ + "[h2_prior_knowledge, h2_prior_knowledge]"));
}
}
@Test public void testMockWebServerH2PriorKnowledgeProtocol() {
server.setProtocols(Arrays.asList(Protocol.H2_PRIOR_KNOWLEDGE));
- assertEquals(1, server.protocols().size());
- assertEquals(Protocol.H2_PRIOR_KNOWLEDGE, server.protocols().get(0));
+ assertThat(server.protocols().size()).isEqualTo(1);
+ assertThat(server.protocols().get(0)).isEqualTo(Protocol.H2_PRIOR_KNOWLEDGE);
}
@Test public void https() throws Exception {
@@ -523,19 +529,19 @@ public final class MockWebServerTest {
connection.setSSLSocketFactory(handshakeCertificates.sslSocketFactory());
connection.setHostnameVerifier(new RecordingHostnameVerifier());
- assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
+ assertThat(connection.getResponseCode()).isEqualTo(HttpURLConnection.HTTP_OK);
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- assertEquals("abc", reader.readLine());
+ assertThat(reader.readLine()).isEqualTo("abc");
RecordedRequest request = server.takeRequest();
- assertEquals("https", request.getRequestUrl().scheme());
+ assertThat(request.getRequestUrl().scheme()).isEqualTo("https");
Handshake handshake = request.getHandshake();
- assertNotNull(handshake.tlsVersion());
- assertNotNull(handshake.cipherSuite());
- assertNotNull(handshake.localPrincipal());
- assertEquals(1, handshake.localCertificates().size());
- assertNull(handshake.peerPrincipal());
- assertEquals(0, handshake.peerCertificates().size());
+ assertThat(handshake.tlsVersion()).isNotNull();
+ assertThat(handshake.cipherSuite()).isNotNull();
+ assertThat(handshake.localPrincipal()).isNotNull();
+ assertThat(handshake.localCertificates().size()).isEqualTo(1);
+ assertThat(handshake.peerPrincipal()).isNull();
+ assertThat(handshake.peerCertificates().size()).isEqualTo(0);
}
@Test public void httpsWithClientAuth() throws Exception {
@@ -571,18 +577,18 @@ public final class MockWebServerTest {
connection.setSSLSocketFactory(clientHandshakeCertificates.sslSocketFactory());
connection.setHostnameVerifier(new RecordingHostnameVerifier());
- assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
+ assertThat(connection.getResponseCode()).isEqualTo(HttpURLConnection.HTTP_OK);
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- assertEquals("abc", reader.readLine());
+ assertThat(reader.readLine()).isEqualTo("abc");
RecordedRequest request = server.takeRequest();
- assertEquals("https", request.getRequestUrl().scheme());
+ assertThat(request.getRequestUrl().scheme()).isEqualTo("https");
Handshake handshake = request.getHandshake();
- assertNotNull(handshake.tlsVersion());
- assertNotNull(handshake.cipherSuite());
- assertNotNull(handshake.localPrincipal());
- assertEquals(1, handshake.localCertificates().size());
- assertNotNull(handshake.peerPrincipal());
- assertEquals(1, handshake.peerCertificates().size());
+ assertThat(handshake.tlsVersion()).isNotNull();
+ assertThat(handshake.cipherSuite()).isNotNull();
+ assertThat(handshake.localPrincipal()).isNotNull();
+ assertThat(handshake.localCertificates().size()).isEqualTo(1);
+ assertThat(handshake.peerPrincipal()).isNotNull();
+ assertThat(handshake.peerCertificates().size()).isEqualTo(1);
}
}
diff --git a/mockwebserver/src/test/java/okhttp3/mockwebserver/RecordedRequestTest.java b/mockwebserver/src/test/java/okhttp3/mockwebserver/RecordedRequestTest.java
index acd37905f..8a58c17e2 100644
--- a/mockwebserver/src/test/java/okhttp3/mockwebserver/RecordedRequestTest.java
+++ b/mockwebserver/src/test/java/okhttp3/mockwebserver/RecordedRequestTest.java
@@ -26,7 +26,7 @@ import okhttp3.internal.Util;
import okio.Buffer;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
public class RecordedRequestTest {
Headers headers = Util.EMPTY_HEADERS;
@@ -76,7 +76,7 @@ public class RecordedRequestTest {
RecordedRequest request = new RecordedRequest("GET / HTTP/1.1", headers,
Collections.emptyList(), 0, new Buffer(), 0, socket);
- assertEquals("http://127.0.0.1/", request.getRequestUrl().toString());
+ assertThat(request.getRequestUrl().toString()).isEqualTo("http://127.0.0.1/");
}
@Test public void testIpv6() throws UnknownHostException {
@@ -86,7 +86,7 @@ public class RecordedRequestTest {
RecordedRequest request = new RecordedRequest("GET / HTTP/1.1", headers,
Collections.emptyList(), 0, new Buffer(), 0, socket);
- assertEquals("http://[::1]/", request.getRequestUrl().toString());
+ assertThat(request.getRequestUrl().toString()).isEqualTo("http://[::1]/");
}
@Test public void testUsesLocal() throws UnknownHostException {
@@ -96,6 +96,6 @@ public class RecordedRequestTest {
RecordedRequest request = new RecordedRequest("GET / HTTP/1.1", headers,
Collections.emptyList(), 0, new Buffer(), 0, socket);
- assertEquals("http://127.0.0.1/", request.getRequestUrl().toString());
+ assertThat(request.getRequestUrl().toString()).isEqualTo("http://127.0.0.1/");
}
}
diff --git a/okcurl/pom.xml b/okcurl/pom.xml
index 48ee2a4b7..63032f87a 100644
--- a/okcurl/pom.xml
+++ b/okcurl/pom.xml
@@ -43,6 +43,11 @@
junit
test
+
+ org.assertj
+ assertj-core
+ test
+
diff --git a/okcurl/src/test/java/okhttp3/curl/MainTest.java b/okcurl/src/test/java/okhttp3/curl/MainTest.java
index 12fe6d5ec..d4542fbed 100644
--- a/okcurl/src/test/java/okhttp3/curl/MainTest.java
+++ b/okcurl/src/test/java/okhttp3/curl/MainTest.java
@@ -22,72 +22,74 @@ import okio.Buffer;
import org.junit.Test;
import static okhttp3.curl.Main.fromArgs;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.assertj.core.api.Assertions.assertThat;
public class MainTest {
@Test public void simple() {
Request request = fromArgs("http://example.com").createRequest();
- assertEquals("GET", request.method());
- assertEquals("http://example.com/", request.url().toString());
- assertNull(request.body());
+ assertThat(request.method()).isEqualTo("GET");
+ assertThat(request.url().toString()).isEqualTo("http://example.com/");
+ assertThat(request.body()).isNull();
}
@Test public void put() throws IOException {
Request request = fromArgs("-X", "PUT", "-d", "foo", "http://example.com").createRequest();
- assertEquals("PUT", request.method());
- assertEquals("http://example.com/", request.url().toString());
- assertEquals(3, request.body().contentLength());
+ assertThat(request.method()).isEqualTo("PUT");
+ assertThat(request.url().toString()).isEqualTo("http://example.com/");
+ assertThat(request.body().contentLength()).isEqualTo(3);
}
@Test public void dataPost() {
Request request = fromArgs("-d", "foo", "http://example.com").createRequest();
RequestBody body = request.body();
- assertEquals("POST", request.method());
- assertEquals("http://example.com/", request.url().toString());
- assertEquals("application/x-www-form-urlencoded; charset=utf-8", body.contentType().toString());
- assertEquals("foo", bodyAsString(body));
+ assertThat(request.method()).isEqualTo("POST");
+ assertThat(request.url().toString()).isEqualTo("http://example.com/");
+ assertThat(body.contentType().toString()).isEqualTo(
+ "application/x-www-form-urlencoded; charset=utf-8");
+ assertThat(bodyAsString(body)).isEqualTo("foo");
}
@Test public void dataPut() {
Request request = fromArgs("-d", "foo", "-X", "PUT", "http://example.com").createRequest();
RequestBody body = request.body();
- assertEquals("PUT", request.method());
- assertEquals("http://example.com/", request.url().toString());
- assertEquals("application/x-www-form-urlencoded; charset=utf-8", body.contentType().toString());
- assertEquals("foo", bodyAsString(body));
+ assertThat(request.method()).isEqualTo("PUT");
+ assertThat(request.url().toString()).isEqualTo("http://example.com/");
+ assertThat(body.contentType().toString()).isEqualTo(
+ "application/x-www-form-urlencoded; charset=utf-8");
+ assertThat(bodyAsString(body)).isEqualTo("foo");
}
@Test public void contentTypeHeader() {
Request request = fromArgs("-d", "foo", "-H", "Content-Type: application/json",
"http://example.com").createRequest();
RequestBody body = request.body();
- assertEquals("POST", request.method());
- assertEquals("http://example.com/", request.url().toString());
- assertEquals("application/json; charset=utf-8", body.contentType().toString());
- assertEquals("foo", bodyAsString(body));
+ assertThat(request.method()).isEqualTo("POST");
+ assertThat(request.url().toString()).isEqualTo("http://example.com/");
+ assertThat(body.contentType().toString()).isEqualTo("application/json; charset=utf-8");
+ assertThat(bodyAsString(body)).isEqualTo("foo");
}
@Test public void referer() {
Request request = fromArgs("-e", "foo", "http://example.com").createRequest();
- assertEquals("GET", request.method());
- assertEquals("http://example.com/", request.url().toString());
- assertEquals("foo", request.header("Referer"));
- assertNull(request.body());
+ assertThat(request.method()).isEqualTo("GET");
+ assertThat(request.url().toString()).isEqualTo("http://example.com/");
+ assertThat(request.header("Referer")).isEqualTo("foo");
+ assertThat(request.body()).isNull();
}
@Test public void userAgent() {
Request request = fromArgs("-A", "foo", "http://example.com").createRequest();
- assertEquals("GET", request.method());
- assertEquals("http://example.com/", request.url().toString());
- assertEquals("foo", request.header("User-Agent"));
- assertNull(request.body());
+ assertThat(request.method()).isEqualTo("GET");
+ assertThat(request.url().toString()).isEqualTo("http://example.com/");
+ assertThat(request.header("User-Agent")).isEqualTo("foo");
+ assertThat(request.body()).isNull();
}
@Test public void headerSplitWithDate() {
Request request = fromArgs("-H", "If-Modified-Since: Mon, 18 Aug 2014 15:16:06 GMT",
"http://example.com").createRequest();
- assertEquals("Mon, 18 Aug 2014 15:16:06 GMT", request.header("If-Modified-Since"));
+ assertThat(request.header("If-Modified-Since")).isEqualTo(
+ "Mon, 18 Aug 2014 15:16:06 GMT");
}
private static String bodyAsString(RequestBody body) {
diff --git a/okhttp-dnsoverhttps/pom.xml b/okhttp-dnsoverhttps/pom.xml
index 8c72b658b..1fafbb7dc 100644
--- a/okhttp-dnsoverhttps/pom.xml
+++ b/okhttp-dnsoverhttps/pom.xml
@@ -46,6 +46,11 @@
conscrypt-openjdk-uber
test
+
+ org.assertj
+ assertj-core
+ test
+
diff --git a/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsOverHttpsTest.java b/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsOverHttpsTest.java
index c6c16278d..6c939bfdb 100644
--- a/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsOverHttpsTest.java
+++ b/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsOverHttpsTest.java
@@ -39,8 +39,7 @@ import org.junit.Test;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class DnsOverHttpsTest {
@@ -62,12 +61,12 @@ public class DnsOverHttpsTest {
List result = dns.lookup("google.com");
- assertEquals(singletonList(address("157.240.1.18")), result);
+ assertThat(result).isEqualTo(singletonList(address("157.240.1.18")));
RecordedRequest recordedRequest = server.takeRequest();
- assertEquals("GET", recordedRequest.getMethod());
- assertEquals("/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ",
- recordedRequest.getPath());
+ assertThat(recordedRequest.getMethod()).isEqualTo("GET");
+ assertThat(recordedRequest.getPath()).isEqualTo(
+ "/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ");
}
@Test public void getIpv6() throws Exception {
@@ -84,20 +83,20 @@ public class DnsOverHttpsTest {
List result = dns.lookup("google.com");
- assertEquals(2, result.size());
- assertTrue(result.contains(address("157.240.1.18")));
- assertTrue(result.contains(address("2a03:2880:f029:11:face:b00c:0:2")));
+ 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();
RecordedRequest request1 = server.takeRequest();
- assertEquals("GET", request1.getMethod());
+ assertThat(request1.getMethod()).isEqualTo("GET");
RecordedRequest request2 = server.takeRequest();
- assertEquals("GET", request2.getMethod());
+ assertThat(request2.getMethod()).isEqualTo("GET");
- assertEquals(new HashSet<>(
+ assertThat(new LinkedHashSet<>(Arrays.asList(request1.getPath(), request2.getPath()))).isEqualTo(
+ new HashSet<>(
Arrays.asList("/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ",
- "/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AABwAAQ")),
- new LinkedHashSet<>(Arrays.asList(request1.getPath(), request2.getPath())));
+ "/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AABwAAQ")));
}
@Test public void failure() throws Exception {
@@ -111,13 +110,13 @@ public class DnsOverHttpsTest {
fail();
} catch (UnknownHostException uhe) {
uhe.printStackTrace();
- assertEquals("google.com: NXDOMAIN", uhe.getMessage());
+ assertThat(uhe.getMessage()).isEqualTo("google.com: NXDOMAIN");
}
RecordedRequest recordedRequest = server.takeRequest();
- assertEquals("GET", recordedRequest.getMethod());
- assertEquals("/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ",
- recordedRequest.getPath());
+ assertThat(recordedRequest.getMethod()).isEqualTo("GET");
+ assertThat(recordedRequest.getPath()).isEqualTo(
+ "/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ");
}
@Test public void failOnExcessiveResponse() {
@@ -129,10 +128,11 @@ public class DnsOverHttpsTest {
dns.lookup("google.com");
fail();
} catch (IOException ioe) {
- assertEquals("google.com", ioe.getMessage());
+ assertThat(ioe.getMessage()).isEqualTo("google.com");
Throwable cause = ioe.getCause();
- assertTrue(cause instanceof IOException);
- assertEquals("response size exceeds limit (65536 bytes): 65537 bytes", cause.getMessage());
+ assertThat(cause instanceof IOException).isTrue();
+ assertThat(cause.getMessage()).isEqualTo(
+ "response size exceeds limit (65536 bytes): 65537 bytes");
}
}
@@ -143,9 +143,10 @@ public class DnsOverHttpsTest {
dns.lookup("google.com");
fail();
} catch (IOException ioe) {
- assertEquals("google.com", ioe.getMessage());
+ assertThat(ioe.getMessage()).isEqualTo("google.com");
Throwable cause = ioe.getCause();
- assertTrue(cause instanceof RuntimeException);
+ boolean condition = cause instanceof RuntimeException;
+ assertThat(condition).isTrue();
}
}
@@ -170,15 +171,15 @@ public class DnsOverHttpsTest {
List result = cachedDns.lookup("google.com");
- assertEquals(singletonList(address("157.240.1.18")), result);
+ assertThat(result).containsExactly(address("157.240.1.18"));
RecordedRequest recordedRequest = server.takeRequest();
- assertEquals("GET", recordedRequest.getMethod());
- assertEquals("/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ",
- recordedRequest.getPath());
+ assertThat(recordedRequest.getMethod()).isEqualTo("GET");
+ assertThat(recordedRequest.getPath()).isEqualTo(
+ "/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ");
result = cachedDns.lookup("google.com");
- assertEquals(singletonList(address("157.240.1.18")), result);
+ assertThat(result).isEqualTo(singletonList(address("157.240.1.18")));
}
private MockResponse dnsResponse(String s) {
diff --git a/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsRecordCodecTest.java b/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsRecordCodecTest.java
index 3a12b4d25..8eea96c7b 100644
--- a/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsRecordCodecTest.java
+++ b/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsRecordCodecTest.java
@@ -17,21 +17,20 @@ package okhttp3.dnsoverhttps;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.util.Collections;
import java.util.List;
import okio.ByteString;
import org.junit.Test;
import static okhttp3.dnsoverhttps.DnsRecordCodec.TYPE_A;
import static okhttp3.dnsoverhttps.DnsRecordCodec.TYPE_AAAA;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class DnsRecordCodecTest {
@Test public void testGoogleDotComEncoding() {
String encoded = encodeQuery("google.com", TYPE_A);
- assertEquals("AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ", encoded);
+ assertThat(encoded).isEqualTo("AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ");
}
private String encodeQuery(String host, int type) {
@@ -41,30 +40,28 @@ public class DnsRecordCodecTest {
@Test public void testGoogleDotComEncodingWithIPv6() {
String encoded = encodeQuery("google.com", TYPE_AAAA);
- assertEquals("AAABAAABAAAAAAAABmdvb2dsZQNjb20AABwAAQ", encoded);
+ assertThat(encoded).isEqualTo("AAABAAABAAAAAAAABmdvb2dsZQNjb20AABwAAQ");
}
@Test public void testGoogleDotComDecodingFromCloudflare() throws Exception {
List encoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
"00008180000100010000000006676f6f676c6503636f6d0000010001c00c00010001000000430004d83ad54e"));
- assertEquals(Collections.singletonList(InetAddress.getByName("216.58.213.78")), encoded);
+ assertThat(encoded).containsExactly(InetAddress.getByName("216.58.213.78"));
}
@Test public void testGoogleDotComDecodingFromGoogle() throws Exception {
List decoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
"0000818000010003000000000567726170680866616365626f6f6b03636f6d0000010001c00c0005000100000a6d000603617069c012c0300005000100000cde000c04737461720463313072c012c042000100010000003b00049df00112"));
- assertEquals(Collections.singletonList(InetAddress.getByName("157.240.1.18")), decoded);
+ assertThat(decoded).containsExactly(InetAddress.getByName("157.240.1.18"));
}
@Test public void testGoogleDotComDecodingFromGoogleIPv6() throws Exception {
List decoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
"0000818000010003000000000567726170680866616365626f6f6b03636f6d00001c0001c00c0005000100000a1b000603617069c012c0300005000100000b1f000c04737461720463313072c012c042001c00010000003b00102a032880f0290011faceb00c00000002"));
- assertEquals(
- Collections.singletonList(InetAddress.getByName("2a03:2880:f029:11:face:b00c:0:2")),
- decoded);
+ assertThat(decoded).containsExactly(InetAddress.getByName("2a03:2880:f029:11:face:b00c:0:2"));
}
@Test public void testGoogleDotComDecodingNxdomainFailure() throws Exception {
@@ -73,7 +70,7 @@ public class DnsRecordCodecTest {
"0000818300010000000100000e7364666c6b686673646c6b6a64660265650000010001c01b00060001000007070038026e7303746c64c01b0a686f73746d61737465720d6565737469696e7465726e6574c01b5adb12c100000e10000003840012750000000e10"));
fail();
} catch (UnknownHostException uhe) {
- assertEquals("sdflkhfsdlkjdf.ee: NXDOMAIN", uhe.getMessage());
+ assertThat(uhe.getMessage()).isEqualTo("sdflkhfsdlkjdf.ee: NXDOMAIN");
}
}
}
diff --git a/okhttp-hpacktests/pom.xml b/okhttp-hpacktests/pom.xml
index a2a22ae36..d45338750 100644
--- a/okhttp-hpacktests/pom.xml
+++ b/okhttp-hpacktests/pom.xml
@@ -8,7 +8,7 @@
com.squareup.okhttp3
parent
- 3.13.0-SNAPSHOT
+ 3.14.0-SNAPSHOT
okhttp-hpacktests
@@ -45,6 +45,11 @@
${project.version}
test
+
+ org.assertj
+ assertj-core
+ test
+
diff --git a/okhttp-hpacktests/src/test/java/okhttp3/internal/http2/HpackDecodeTestBase.java b/okhttp-hpacktests/src/test/java/okhttp3/internal/http2/HpackDecodeTestBase.java
index a3f69da38..879fe6aba 100644
--- a/okhttp-hpacktests/src/test/java/okhttp3/internal/http2/HpackDecodeTestBase.java
+++ b/okhttp-hpacktests/src/test/java/okhttp3/internal/http2/HpackDecodeTestBase.java
@@ -24,7 +24,7 @@ import okhttp3.internal.http2.hpackjson.HpackJsonUtil;
import okhttp3.internal.http2.hpackjson.Story;
import okio.Buffer;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
/**
@@ -83,7 +83,8 @@ public class HpackDecodeTestBase {
*/
private static void assertSetEquals(
String message, List expected, List observed) {
- assertEquals(message, new LinkedHashSet<>(expected), new LinkedHashSet<>(observed));
+ assertThat(new LinkedHashSet<>(observed)).overridingErrorMessage(message).isEqualTo(
+ new LinkedHashSet<>(expected));
}
protected Story getStory() {
diff --git a/okhttp-logging-interceptor/pom.xml b/okhttp-logging-interceptor/pom.xml
index 35bbc9a52..dfc7064db 100644
--- a/okhttp-logging-interceptor/pom.xml
+++ b/okhttp-logging-interceptor/pom.xml
@@ -47,6 +47,11 @@
${project.version}
test
+
+ org.assertj
+ assertj-core
+ test
+
diff --git a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java
index 1a6bf878b..a3d18befe 100644
--- a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java
+++ b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java
@@ -38,17 +38,13 @@ import okhttp3.tls.HandshakeCertificates;
import okio.Buffer;
import okio.BufferedSink;
import okio.ByteString;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static okhttp3.tls.internal.TlsUtil.localhost;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeThat;
@@ -91,11 +87,11 @@ public final class HttpLoggingInterceptorTest {
@Test public void levelGetter() {
// The default is NONE.
- Assert.assertEquals(Level.NONE, applicationInterceptor.getLevel());
+ assertThat(applicationInterceptor.getLevel()).isEqualTo(Level.NONE);
for (Level level : Level.values()) {
applicationInterceptor.setLevel(level);
- assertEquals(level, applicationInterceptor.getLevel());
+ assertThat(applicationInterceptor.getLevel()).isEqualTo(level);
}
}
@@ -104,13 +100,13 @@ public final class HttpLoggingInterceptorTest {
applicationInterceptor.setLevel(null);
fail();
} catch (NullPointerException expected) {
- assertEquals("level == null. Use Level.NONE instead.", expected.getMessage());
+ assertThat(expected.getMessage()).isEqualTo("level == null. Use Level.NONE instead.");
}
}
@Test public void setLevelShouldReturnSameInstanceOfInterceptor() {
for (Level level : Level.values()) {
- assertSame(applicationInterceptor, applicationInterceptor.setLevel(level));
+ assertThat(applicationInterceptor.setLevel(level)).isSameAs(applicationInterceptor);
}
}
@@ -545,7 +541,8 @@ public final class HttpLoggingInterceptorTest {
Response response = client.newCall(request().build()).execute();
ResponseBody responseBody = response.body();
- assertEquals("Expected response body to be valid","Hello, Hello, Hello", responseBody.string());
+ assertThat(responseBody.string()).overridingErrorMessage(
+ "Expected response body to be valid").isEqualTo("Hello, Hello, Hello");
responseBody.close();
networkLogs
@@ -649,13 +646,13 @@ public final class HttpLoggingInterceptorTest {
}
@Test public void isPlaintext() {
- assertTrue(HttpLoggingInterceptor.isPlaintext(new Buffer()));
- assertTrue(HttpLoggingInterceptor.isPlaintext(new Buffer().writeUtf8("abc")));
- assertTrue(HttpLoggingInterceptor.isPlaintext(new Buffer().writeUtf8("new\r\nlines")));
- assertTrue(HttpLoggingInterceptor.isPlaintext(new Buffer().writeUtf8("white\t space")));
- assertTrue(HttpLoggingInterceptor.isPlaintext(new Buffer().writeByte(0x80)));
- assertFalse(HttpLoggingInterceptor.isPlaintext(new Buffer().writeByte(0x00)));
- assertFalse(HttpLoggingInterceptor.isPlaintext(new Buffer().writeByte(0xc0)));
+ assertThat(HttpLoggingInterceptor.isPlaintext(new Buffer())).isTrue();
+ assertThat(HttpLoggingInterceptor.isPlaintext(new Buffer().writeUtf8("abc"))).isTrue();
+ assertThat(HttpLoggingInterceptor.isPlaintext(new Buffer().writeUtf8("new\r\nlines"))).isTrue();
+ assertThat(HttpLoggingInterceptor.isPlaintext(new Buffer().writeUtf8("white\t space"))).isTrue();
+ assertThat(HttpLoggingInterceptor.isPlaintext(new Buffer().writeByte(0x80))).isTrue();
+ assertThat(HttpLoggingInterceptor.isPlaintext(new Buffer().writeByte(0x00))).isFalse();
+ assertThat(HttpLoggingInterceptor.isPlaintext(new Buffer().writeByte(0xc0))).isFalse();
}
@Test public void responseBodyIsBinary() throws IOException {
@@ -827,7 +824,7 @@ public final class HttpLoggingInterceptorTest {
Response response = client.newCall(request).execute();
assumeThat(response.protocol(), equalTo(Protocol.HTTP_2));
- assertEquals("Hello response!", response.body().string());
+ assertThat(response.body().string()).isEqualTo("Hello response!");
applicationLogs
.assertLogEqual("--> POST " + url)
@@ -849,22 +846,23 @@ public final class HttpLoggingInterceptorTest {
private int index;
LogRecorder assertLogEqual(String expected) {
- assertTrue("No more messages found", index < logs.size());
+ assertThat(index < logs.size()).overridingErrorMessage("No more messages found").isTrue();
String actual = logs.get(index++);
- assertEquals(expected, actual);
+ assertThat(actual).isEqualTo(expected);
return this;
}
LogRecorder assertLogMatch(String pattern) {
- assertTrue("No more messages found", index < logs.size());
+ assertThat(index < logs.size()).overridingErrorMessage("No more messages found").isTrue();
String actual = logs.get(index++);
- assertTrue("<" + actual + "> did not match pattern <" + pattern + ">",
- Pattern.matches(pattern, actual));
+ assertThat(Pattern.matches(pattern, actual)).overridingErrorMessage(
+ "<" + actual + "> did not match pattern <" + pattern + ">").isTrue();
return this;
}
void assertNoMoreLogs() {
- assertEquals("More messages remain: " + logs.subList(index, logs.size()), index, logs.size());
+ assertThat(logs.size()).overridingErrorMessage(
+ "More messages remain: " + logs.subList(index, logs.size())).isEqualTo(index);
}
@Override public void log(String message) {
diff --git a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/LoggingEventListenerTest.java b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/LoggingEventListenerTest.java
index 946ab4424..a1d301542 100644
--- a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/LoggingEventListenerTest.java
+++ b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/LoggingEventListenerTest.java
@@ -35,7 +35,7 @@ import static java.util.Arrays.asList;
import static okhttp3.Protocol.HTTP_1_1;
import static okhttp3.Protocol.HTTP_2;
import static okhttp3.tls.internal.TlsUtil.localhost;
-import static org.junit.Assert.assertNotNull;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public final class LoggingEventListenerTest {
@@ -67,7 +67,7 @@ public final class LoggingEventListenerTest {
public void get() throws Exception {
server.enqueue(new MockResponse().setBody("Hello!").setHeader("Content-Type", PLAIN));
Response response = client.newCall(request().build()).execute();
- assertNotNull(response.body());
+ assertThat(response.body()).isNotNull();
response.body().bytes();
logRecorder
@@ -136,7 +136,7 @@ public final class LoggingEventListenerTest {
server.enqueue(new MockResponse());
Response response = client.newCall(request().build()).execute();
- assertNotNull(response.body());
+ assertThat(response.body()).isNotNull();
response.body().bytes();
logRecorder
diff --git a/okhttp-sse/pom.xml b/okhttp-sse/pom.xml
index bf4c8c459..298331770 100644
--- a/okhttp-sse/pom.xml
+++ b/okhttp-sse/pom.xml
@@ -41,6 +41,11 @@
${project.version}
test
+
+ org.assertj
+ assertj-core
+ test
+
diff --git a/okhttp-sse/src/test/java/okhttp3/internal/sse/EventSourceHttpTest.java b/okhttp-sse/src/test/java/okhttp3/internal/sse/EventSourceHttpTest.java
index 8b7da9a1d..0dbec41be 100644
--- a/okhttp-sse/src/test/java/okhttp3/internal/sse/EventSourceHttpTest.java
+++ b/okhttp-sse/src/test/java/okhttp3/internal/sse/EventSourceHttpTest.java
@@ -27,7 +27,7 @@ import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
public final class EventSourceHttpTest {
@Rule public final MockWebServer server = new MockWebServer();
@@ -47,7 +47,7 @@ public final class EventSourceHttpTest {
EventSource source = newEventSource();
- assertEquals("/", source.request().url().encodedPath());
+ assertThat(source.request().url().encodedPath()).isEqualTo("/");
listener.assertOpen();
listener.assertEvent(null, null, "hey");
@@ -84,7 +84,7 @@ public final class EventSourceHttpTest {
EventSource source = newEventSource();
- assertEquals("/", source.request().url().encodedPath());
+ assertThat(source.request().url().encodedPath()).isEqualTo("/");
listener.assertOpen();
listener.assertEvent(null, null, "hey");
diff --git a/okhttp-sse/src/test/java/okhttp3/internal/sse/EventSourceRecorder.java b/okhttp-sse/src/test/java/okhttp3/internal/sse/EventSourceRecorder.java
index cf4afd4ec..ffcf8daa9 100644
--- a/okhttp-sse/src/test/java/okhttp3/internal/sse/EventSourceRecorder.java
+++ b/okhttp-sse/src/test/java/okhttp3/internal/sse/EventSourceRecorder.java
@@ -25,9 +25,7 @@ import okhttp3.Response;
import okhttp3.internal.platform.Platform;
import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
public final class EventSourceRecorder extends EventSourceListener {
private final BlockingQueue