diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 94a5352d7b25..0f9b271d5552 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,7 +21,6 @@ androidx-junit = "androidx.test.ext:junit:1.1.5" androidx-test-runner = "androidx.test:runner:1.5.2" animalsniffer-annotations = "org.codehaus.mojo:animal-sniffer-annotations:1.23" aqute-resolve = { module = "biz.aQute.bnd:biz.aQute.resolve", version.ref = "biz-aQute-bnd" } -assertj-core = "org.assertj:assertj-core:3.24.2" assertk = "com.willowtreeapps.assertk:assertk:0.27.0" bouncycastle-bcpkix = { module = "org.bouncycastle:bcpkix-jdk15to18", version.ref = "org-bouncycastle" } bouncycastle-bcprov = { module = "org.bouncycastle:bcprov-jdk15to18", version.ref = "org-bouncycastle" } diff --git a/mockwebserver-deprecated/build.gradle.kts b/mockwebserver-deprecated/build.gradle.kts index ccf320197742..06ce4f0e12a6 100644 --- a/mockwebserver-deprecated/build.gradle.kts +++ b/mockwebserver-deprecated/build.gradle.kts @@ -21,7 +21,6 @@ dependencies { testImplementation(projects.okhttpTestingSupport) testImplementation(projects.okhttpTls) - testImplementation(libs.assertj.core) } mavenPublishing { diff --git a/mockwebserver-deprecated/src/test/java/okhttp3/mockwebserver/MockWebServerTest.kt b/mockwebserver-deprecated/src/test/java/okhttp3/mockwebserver/MockWebServerTest.kt index b2db3fde9e4a..541036cf8f0a 100644 --- a/mockwebserver-deprecated/src/test/java/okhttp3/mockwebserver/MockWebServerTest.kt +++ b/mockwebserver-deprecated/src/test/java/okhttp3/mockwebserver/MockWebServerTest.kt @@ -15,6 +15,18 @@ */ package okhttp3.mockwebserver +import assertk.assertThat +import assertk.assertions.contains +import assertk.assertions.containsExactly +import assertk.assertions.isBetween +import assertk.assertions.isCloseTo +import assertk.assertions.isEqualTo +import assertk.assertions.isGreaterThan +import assertk.assertions.isGreaterThanOrEqualTo +import assertk.assertions.isNotEqualTo +import assertk.assertions.isNotNull +import assertk.assertions.isNull +import assertk.assertions.isTrue import java.io.BufferedReader import java.io.Closeable import java.io.IOException @@ -35,8 +47,6 @@ import okhttp3.TestUtil.assumeNotWindows import okhttp3.testing.PlatformRule import okhttp3.tls.HandshakeCertificates import okhttp3.tls.HeldCertificate -import org.assertj.core.api.Assertions.assertThat -import org.assertj.core.data.Offset import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach @@ -354,7 +364,7 @@ class MockWebServerTest { i++ } // Halfway +/- 0.5% - assertThat(i.toFloat()).isCloseTo(512f, Offset.offset(5f)) + assertThat(i.toFloat()).isCloseTo(512f, 5f) } @Test @@ -494,7 +504,7 @@ class MockWebServerTest { refusedConnection.getResponseCode() fail("Second connection should be refused") } catch (e: ConnectException) { - assertThat(e.message).contains("refused") + assertThat(e.message!!).contains("refused") } } diff --git a/mockwebserver-junit4/build.gradle.kts b/mockwebserver-junit4/build.gradle.kts index 8302a3a3035c..ced54ebe9c95 100644 --- a/mockwebserver-junit4/build.gradle.kts +++ b/mockwebserver-junit4/build.gradle.kts @@ -18,7 +18,6 @@ dependencies { api(projects.mockwebserver3) api(libs.junit) - testImplementation(libs.assertj.core) testImplementation(libs.assertk) } diff --git a/mockwebserver-junit5/build.gradle.kts b/mockwebserver-junit5/build.gradle.kts index 8eab01aee008..73de96017794 100644 --- a/mockwebserver-junit5/build.gradle.kts +++ b/mockwebserver-junit5/build.gradle.kts @@ -26,10 +26,8 @@ dependencies { compileOnly(libs.animalsniffer.annotations) testRuntimeOnly(libs.junit.jupiter.engine) - testImplementation(libs.assertj.core) testImplementation(libs.kotlin.junit5) testImplementation(projects.okhttpTestingSupport) - testImplementation(libs.assertj.core) testImplementation(libs.assertk) } diff --git a/mockwebserver/build.gradle.kts b/mockwebserver/build.gradle.kts index 34eefd8c694e..f6431f9361ae 100644 --- a/mockwebserver/build.gradle.kts +++ b/mockwebserver/build.gradle.kts @@ -21,7 +21,6 @@ dependencies { testImplementation(projects.okhttpTls) testRuntimeOnly(projects.mockwebserver3Junit5) testImplementation(libs.junit) - testImplementation(libs.assertj.core) testImplementation(libs.assertk) } diff --git a/native-image-tests/build.gradle.kts b/native-image-tests/build.gradle.kts index 03657004d3b6..0f82353eb75d 100644 --- a/native-image-tests/build.gradle.kts +++ b/native-image-tests/build.gradle.kts @@ -6,7 +6,6 @@ plugins { } dependencies { - implementation(libs.assertj.core) implementation(libs.junit.jupiter.api) implementation(libs.junit.jupiter.engine) implementation(libs.junit.platform.console) @@ -19,7 +18,6 @@ dependencies { implementation(projects.okhttpSse) implementation(projects.okhttpTestingSupport) implementation(projects.okhttpTls) - implementation(libs.assertj.core) implementation(projects.mockwebserver3) implementation(projects.mockwebserver) implementation(projects.okhttpJavaNetCookiejar) diff --git a/native-image-tests/src/main/kotlin/okhttp3/SampleTest.kt b/native-image-tests/src/main/kotlin/okhttp3/SampleTest.kt index 9f5bb55706f0..ee0a2c49a6b5 100644 --- a/native-image-tests/src/main/kotlin/okhttp3/SampleTest.kt +++ b/native-image-tests/src/main/kotlin/okhttp3/SampleTest.kt @@ -15,10 +15,11 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.isEqualTo import mockwebserver3.MockResponse import mockwebserver3.MockWebServer import okhttp3.HttpUrl.Companion.toHttpUrl -import org.assertj.core.api.AssertionsForClassTypes.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.RegisterExtension import org.junit.jupiter.params.ParameterizedTest diff --git a/okhttp-android/build.gradle.kts b/okhttp-android/build.gradle.kts index e4eb927adf0c..fe6093341406 100644 --- a/okhttp-android/build.gradle.kts +++ b/okhttp-android/build.gradle.kts @@ -57,7 +57,6 @@ dependencies { testImplementation(libs.junit) testImplementation(libs.junit.ktx) - testImplementation(libs.assertj.core) testImplementation(libs.assertk) testImplementation(projects.okhttpTls) testImplementation(libs.androidx.test.runner) @@ -66,7 +65,6 @@ dependencies { testImplementation(libs.squareup.okio.fakefilesystem) androidTestImplementation(projects.okhttpTls) - androidTestImplementation(libs.assertj.core) androidTestImplementation(libs.assertk) androidTestImplementation(projects.mockwebserver3Junit4) androidTestImplementation(libs.androidx.test.runner) diff --git a/okhttp-android/src/androidTest/kotlin/okhttp3/android/AndroidAsyncDnsTest.kt b/okhttp-android/src/androidTest/kotlin/okhttp3/android/AndroidAsyncDnsTest.kt index 9525b1ce6f04..0f540ee8f26f 100644 --- a/okhttp-android/src/androidTest/kotlin/okhttp3/android/AndroidAsyncDnsTest.kt +++ b/okhttp-android/src/androidTest/kotlin/okhttp3/android/AndroidAsyncDnsTest.kt @@ -26,6 +26,7 @@ import assertk.assertions.isEmpty import assertk.assertions.isEqualTo import assertk.assertions.isNotEmpty import assertk.assertions.isNull +import assertk.fail import java.net.InetAddress import java.net.UnknownHostException import java.util.concurrent.CountDownLatch @@ -38,7 +39,6 @@ import okhttp3.Request import okhttp3.tls.HandshakeCertificates import okhttp3.tls.HeldCertificate import okio.IOException -import org.assertj.core.api.Assertions.fail import org.junit.Assume.assumeTrue import org.junit.AssumptionViolatedException import org.junit.Before diff --git a/okhttp-brotli/build.gradle.kts b/okhttp-brotli/build.gradle.kts index e0c2764fb7ec..26613adb5938 100644 --- a/okhttp-brotli/build.gradle.kts +++ b/okhttp-brotli/build.gradle.kts @@ -22,7 +22,6 @@ dependencies { testImplementation(projects.okhttpTestingSupport) testImplementation(libs.conscrypt.openjdk) testImplementation(libs.junit) - testImplementation(libs.assertj.core) testImplementation(libs.assertk) } diff --git a/okhttp-dnsoverhttps/build.gradle.kts b/okhttp-dnsoverhttps/build.gradle.kts index a2deec57eb2b..aa905364efed 100644 --- a/okhttp-dnsoverhttps/build.gradle.kts +++ b/okhttp-dnsoverhttps/build.gradle.kts @@ -24,7 +24,6 @@ dependencies { testImplementation(libs.squareup.okio.fakefilesystem) testImplementation(libs.conscrypt.openjdk) testImplementation(libs.junit) - testImplementation(libs.assertj.core) } mavenPublishing { diff --git a/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsOverHttpsTest.kt b/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsOverHttpsTest.kt index 7cc2f9cf88fe..48de726c0b8b 100644 --- a/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsOverHttpsTest.kt +++ b/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsOverHttpsTest.kt @@ -15,12 +15,18 @@ */ package okhttp3.dnsoverhttps +import assertk.assertThat +import assertk.assertions.contains +import assertk.assertions.containsExactly +import assertk.assertions.containsExactlyInAnyOrder +import assertk.assertions.hasMessage +import assertk.assertions.isEqualTo +import assertk.assertions.isInstanceOf import java.io.EOFException import java.io.File import java.io.IOException import java.net.InetAddress import java.net.UnknownHostException -import java.util.Arrays import java.util.concurrent.TimeUnit import mockwebserver3.MockResponse import mockwebserver3.MockWebServer @@ -34,7 +40,6 @@ import okio.Buffer import okio.ByteString.Companion.decodeHex import okio.Path.Companion.toPath import okio.fakefilesystem.FakeFileSystem -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Tag @@ -103,7 +108,7 @@ class DnsOverHttpsTest { assertThat(request1.method).isEqualTo("GET") val request2 = server.takeRequest() assertThat(request2.method).isEqualTo("GET") - assertThat(Arrays.asList(request1.path, request2.path)) + assertThat(listOf(request1.path, request2.path)) .containsExactlyInAnyOrder( "/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ", "/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AABwAAQ" @@ -140,8 +145,8 @@ class DnsOverHttpsTest { fail() } catch (ioe: IOException) { assertThat(ioe.message).isEqualTo("google.com") - val cause = ioe.cause - assertThat(cause).isInstanceOf(IOException::class.java) + val cause = ioe.cause!! + assertThat(cause).isInstanceOf() assertThat(cause).hasMessage("response size exceeds limit (65536 bytes): 65537 bytes") } } @@ -154,7 +159,7 @@ class DnsOverHttpsTest { fail() } catch (ioe: IOException) { assertThat(ioe).hasMessage("google.com") - assertThat(ioe.cause).isInstanceOf(EOFException::class.java) + assertThat(ioe.cause!!).isInstanceOf() } } diff --git a/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsRecordCodecTest.kt b/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsRecordCodecTest.kt index e89f845a84e4..b9f5e4c27301 100644 --- a/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsRecordCodecTest.kt +++ b/okhttp-dnsoverhttps/src/test/java/okhttp3/dnsoverhttps/DnsRecordCodecTest.kt @@ -16,14 +16,16 @@ @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") package okhttp3.dnsoverhttps +import assertk.assertThat +import assertk.assertions.containsExactly +import assertk.assertions.isEqualTo +import assertk.fail import java.net.InetAddress import java.net.UnknownHostException import okhttp3.AsyncDns.Companion.TYPE_A import okhttp3.AsyncDns.Companion.TYPE_AAAA import okhttp3.dnsoverhttps.DnsRecordCodec.decodeAnswers import okio.ByteString.Companion.decodeHex -import org.assertj.core.api.Assertions.assertThat -import org.assertj.core.api.Assertions.fail import org.junit.jupiter.api.Test class DnsRecordCodecTest { @@ -85,7 +87,7 @@ class DnsRecordCodecTest { "00060001000007070038026e7303746c64c01b0a686f73746d61737465720d6565737469696e7465726e65" + "74c01b5adb12c100000e10000003840012750000000e10").decodeHex() ) - fail("") + fail("") } catch (uhe: UnknownHostException) { assertThat(uhe.message).isEqualTo("sdflkhfsdlkjdf.ee: NXDOMAIN") } diff --git a/okhttp-hpacktests/build.gradle.kts b/okhttp-hpacktests/build.gradle.kts index 6d5c2b271ed3..9fc8e1c125b9 100644 --- a/okhttp-hpacktests/build.gradle.kts +++ b/okhttp-hpacktests/build.gradle.kts @@ -10,5 +10,4 @@ dependencies { testImplementation(projects.okhttpTestingSupport) testImplementation(projects.mockwebserver) testImplementation(libs.junit) - testImplementation(libs.assertj.core) } diff --git a/okhttp-hpacktests/src/test/java/okhttp3/internal/http2/HpackDecodeTestBase.kt b/okhttp-hpacktests/src/test/java/okhttp3/internal/http2/HpackDecodeTestBase.kt index 3a3b4541dc71..4cb329a5b819 100644 --- a/okhttp-hpacktests/src/test/java/okhttp3/internal/http2/HpackDecodeTestBase.kt +++ b/okhttp-hpacktests/src/test/java/okhttp3/internal/http2/HpackDecodeTestBase.kt @@ -15,10 +15,11 @@ */ package okhttp3.internal.http2 +import assertk.assertThat +import assertk.assertions.isEqualTo import okhttp3.internal.http2.hpackjson.HpackJsonUtil import okhttp3.internal.http2.hpackjson.Story import okio.Buffer -import org.assertj.core.api.Assertions.assertThat /** * Tests Hpack implementation using https://github.com/http2jp/hpack-test-case/ @@ -67,8 +68,7 @@ open class HpackDecodeTestBase { expected: List
, observed: List
, ) { - assertThat(LinkedHashSet(observed)) - .overridingErrorMessage(message) + assertThat(LinkedHashSet(observed), message) .isEqualTo(LinkedHashSet(expected)) } } diff --git a/okhttp-logging-interceptor/build.gradle.kts b/okhttp-logging-interceptor/build.gradle.kts index 9395c780d8fc..69fe384620b1 100644 --- a/okhttp-logging-interceptor/build.gradle.kts +++ b/okhttp-logging-interceptor/build.gradle.kts @@ -24,7 +24,6 @@ dependencies { testImplementation(projects.mockwebserver3Junit5) testImplementation(projects.okhttpTestingSupport) testImplementation(projects.okhttpTls) - testImplementation(libs.assertj.core) testImplementation(libs.assertk) } diff --git a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.kt b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.kt index 11c7459ec125..ccecfb4427b6 100644 --- a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.kt +++ b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.kt @@ -15,8 +15,13 @@ */ package okhttp3.logging +import assertk.assertThat +import assertk.assertions.isEqualTo +import assertk.assertions.isLessThan +import assertk.assertions.isLessThanOrEqualTo +import assertk.assertions.isSameAs +import assertk.assertions.matches import java.net.UnknownHostException -import java.util.regex.Pattern import mockwebserver3.MockResponse import mockwebserver3.MockWebServer import mockwebserver3.junit5.internal.MockWebServerExtension @@ -36,7 +41,6 @@ import okhttp3.testing.PlatformRule import okio.Buffer import okio.BufferedSink import okio.ByteString.Companion.decodeBase64 -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Assumptions import org.junit.jupiter.api.BeforeEach @@ -572,9 +576,8 @@ class HttpLoggingInterceptorTest { .build() ).execute() val responseBody = response.body - assertThat(responseBody.string()).overridingErrorMessage( - "Expected response body to be valid" - ).isEqualTo("Uncompressed") + assertThat(responseBody.string(), "Expected response body to be valid") + .isEqualTo("Uncompressed") responseBody.close() networkLogs .assertLogEqual("--> POST $url http/1.1") @@ -607,9 +610,8 @@ class HttpLoggingInterceptorTest { ) val response = client.newCall(request().build()).execute() val responseBody = response.body - assertThat(responseBody.string()).overridingErrorMessage( - "Expected response body to be valid" - ).isEqualTo("Hello, Hello, Hello") + assertThat(responseBody.string(), "Expected response body to be valid") + .isEqualTo("Hello, Hello, Hello") responseBody.close() networkLogs .assertLogEqual("--> GET $url http/1.1") @@ -984,24 +986,21 @@ class HttpLoggingInterceptorTest { private var index = 0 fun assertLogEqual(expected: String) = apply { - assertThat(index) - .overridingErrorMessage("No more messages found") + assertThat(index, "No more messages found") .isLessThan(logs.size) assertThat(logs[index++]).isEqualTo(expected) return this } fun assertLogMatch(regex: Regex) = apply { - assertThat(index) - .overridingErrorMessage("No more messages found") + assertThat(index, "No more messages found") .isLessThan(logs.size) assertThat(logs[index++]) - .matches(Pattern.compile(prefix.pattern + regex.pattern, Pattern.DOTALL)) + .matches(Regex(prefix.pattern + regex.pattern, RegexOption.DOT_MATCHES_ALL)) } fun assertNoMoreLogs() { - assertThat(logs.size) - .overridingErrorMessage("More messages remain: ${logs.subList(index, logs.size)}") + assertThat(logs.size, "More messages remain: ${logs.subList(index, logs.size)}") .isEqualTo(index) } diff --git a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/LoggingEventListenerTest.kt b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/LoggingEventListenerTest.kt index 1d832e802861..c4871c6ddf7e 100644 --- a/okhttp-logging-interceptor/src/test/java/okhttp3/logging/LoggingEventListenerTest.kt +++ b/okhttp-logging-interceptor/src/test/java/okhttp3/logging/LoggingEventListenerTest.kt @@ -15,6 +15,8 @@ */ package okhttp3.logging +import assertk.assertThat +import assertk.assertions.isNotNull import java.io.IOException import java.net.UnknownHostException import java.util.Arrays @@ -32,7 +34,6 @@ import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response import okhttp3.TestUtil.assumeNotWindows import okhttp3.testing.PlatformRule -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/okhttp-sse/build.gradle.kts b/okhttp-sse/build.gradle.kts index c6886bf124ca..dedeeb4121ea 100644 --- a/okhttp-sse/build.gradle.kts +++ b/okhttp-sse/build.gradle.kts @@ -22,7 +22,6 @@ dependencies { testImplementation(projects.mockwebserver3) testImplementation(projects.mockwebserver3Junit5) testImplementation(libs.junit) - testImplementation(libs.assertj.core) testCompileOnly(libs.findbugs.jsr305) } diff --git a/okhttp-sse/src/test/java/okhttp3/sse/internal/EventSourceHttpTest.kt b/okhttp-sse/src/test/java/okhttp3/sse/internal/EventSourceHttpTest.kt index b722a922091f..7884f6411b07 100644 --- a/okhttp-sse/src/test/java/okhttp3/sse/internal/EventSourceHttpTest.kt +++ b/okhttp-sse/src/test/java/okhttp3/sse/internal/EventSourceHttpTest.kt @@ -15,6 +15,9 @@ */ package okhttp3.sse.internal +import assertk.assertThat +import assertk.assertions.containsExactly +import assertk.assertions.isEqualTo import java.util.concurrent.TimeUnit import mockwebserver3.MockResponse import mockwebserver3.MockWebServer @@ -25,7 +28,6 @@ import okhttp3.Request import okhttp3.sse.EventSource import okhttp3.sse.EventSources.createFactory import okhttp3.testing.PlatformRule -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Tag diff --git a/okhttp-sse/src/test/java/okhttp3/sse/internal/EventSourceRecorder.kt b/okhttp-sse/src/test/java/okhttp3/sse/internal/EventSourceRecorder.kt index d6662f0d9f38..e754abdb18db 100644 --- a/okhttp-sse/src/test/java/okhttp3/sse/internal/EventSourceRecorder.kt +++ b/okhttp-sse/src/test/java/okhttp3/sse/internal/EventSourceRecorder.kt @@ -15,6 +15,10 @@ */ package okhttp3.sse.internal +import assertk.assertThat +import assertk.assertions.isEmpty +import assertk.assertions.isEqualTo +import assertk.assertions.isNull import java.util.concurrent.LinkedBlockingDeque import java.util.concurrent.TimeUnit import okhttp3.Response @@ -22,7 +26,6 @@ import okhttp3.internal.platform.Platform import okhttp3.internal.platform.Platform.Companion.get import okhttp3.sse.EventSource import okhttp3.sse.EventSourceListener -import org.assertj.core.api.Assertions.assertThat class EventSourceRecorder : EventSourceListener() { private val events = LinkedBlockingDeque() diff --git a/okhttp-sse/src/test/java/okhttp3/sse/internal/ServerSentEventIteratorTest.kt b/okhttp-sse/src/test/java/okhttp3/sse/internal/ServerSentEventIteratorTest.kt index d08d2653dcea..f348aaf72df4 100644 --- a/okhttp-sse/src/test/java/okhttp3/sse/internal/ServerSentEventIteratorTest.kt +++ b/okhttp-sse/src/test/java/okhttp3/sse/internal/ServerSentEventIteratorTest.kt @@ -15,10 +15,12 @@ */ package okhttp3.sse.internal +import assertk.assertThat +import assertk.assertions.isEmpty +import assertk.assertions.isEqualTo import java.util.ArrayDeque import java.util.Deque import okio.Buffer -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Test @@ -298,8 +300,7 @@ class ServerSentEventIteratorTest { val reader = ServerSentEventReader(buffer, callback) while (reader.processNextEvent()) { } - assertThat(buffer.size) - .overridingErrorMessage("Unconsumed buffer: ${buffer.readUtf8()}") + assertThat(buffer.size, "Unconsumed buffer: ${buffer.readUtf8()}") .isEqualTo(0) } } diff --git a/okhttp-testing-support/build.gradle.kts b/okhttp-testing-support/build.gradle.kts index 01138236cecf..6c025fdd3675 100644 --- a/okhttp-testing-support/build.gradle.kts +++ b/okhttp-testing-support/build.gradle.kts @@ -7,7 +7,6 @@ dependencies { api(libs.squareup.okio) api(projects.okhttp) api(projects.okhttpTls) - api(libs.assertj.core) api(libs.assertk) api(libs.bouncycastle.bcprov) implementation(libs.bouncycastle.bcpkix) diff --git a/okhttp-tls/build.gradle.kts b/okhttp-tls/build.gradle.kts index c32f564aeda8..20a6467533de 100644 --- a/okhttp-tls/build.gradle.kts +++ b/okhttp-tls/build.gradle.kts @@ -24,7 +24,7 @@ dependencies { testImplementation(projects.okhttpTestingSupport) testImplementation(projects.mockwebserver3Junit5) testImplementation(libs.junit) - testImplementation(libs.assertj.core) + testImplementation(libs.assertk) } animalsniffer { diff --git a/okhttp-tls/src/test/java/okhttp3/tls/HeldCertificateTest.kt b/okhttp-tls/src/test/java/okhttp3/tls/HeldCertificateTest.kt index 743bae841247..55c7a458f00a 100644 --- a/okhttp-tls/src/test/java/okhttp3/tls/HeldCertificateTest.kt +++ b/okhttp-tls/src/test/java/okhttp3/tls/HeldCertificateTest.kt @@ -15,17 +15,20 @@ */ package okhttp3.tls +import assertk.assertThat +import assertk.assertions.containsExactly +import assertk.assertions.isCloseTo +import assertk.assertions.isEqualTo +import assertk.assertions.isNull +import assertk.assertions.matches import java.math.BigInteger import java.security.KeyFactory import java.security.spec.PKCS8EncodedKeySpec import java.security.spec.X509EncodedKeySpec -import java.util.Arrays import java.util.concurrent.TimeUnit import okhttp3.testing.PlatformRule import okhttp3.tls.HeldCertificate.Companion.decode import okio.ByteString.Companion.decodeBase64 -import org.assertj.core.api.Assertions.assertThat -import org.assertj.core.data.Offset import org.bouncycastle.asn1.x509.GeneralName import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Test @@ -40,19 +43,17 @@ class HeldCertificateTest { val now = System.currentTimeMillis() val heldCertificate = HeldCertificate.Builder().build() val certificate = heldCertificate.certificate - assertThat(certificate.getSubjectX500Principal().name).overridingErrorMessage( - "self-signed" - ).isEqualTo(certificate.getIssuerX500Principal().name) - assertThat(certificate.getIssuerX500Principal().name).matches("CN=[0-9a-f-]{36}") + assertThat(certificate.getSubjectX500Principal().name, "self-signed") + .isEqualTo(certificate.getIssuerX500Principal().name) + assertThat(certificate.getIssuerX500Principal().name).matches(Regex("CN=[0-9a-f-]{36}")) assertThat(certificate.serialNumber).isEqualTo(BigInteger.ONE) assertThat(certificate.subjectAlternativeNames).isNull() val deltaMillis = 1000.0 val durationMillis = TimeUnit.MINUTES.toMillis((60 * 24).toLong()) assertThat(certificate.notBefore.time.toDouble()) - .isCloseTo(now.toDouble(), Offset.offset(deltaMillis)) - assertThat(certificate.notAfter.time.toDouble()).isCloseTo( - now.toDouble() + durationMillis, Offset.offset(deltaMillis) - ) + .isCloseTo(now.toDouble(), deltaMillis) + assertThat(certificate.notAfter.time.toDouble()) + .isCloseTo(now.toDouble() + durationMillis, deltaMillis) } @Test @@ -76,10 +77,9 @@ class HeldCertificateTest { val deltaMillis = 1000.0 val durationMillis = 5000L assertThat(certificate.notBefore.time.toDouble()) - .isCloseTo(now.toDouble(), Offset.offset(deltaMillis)) - assertThat(certificate.notAfter.time.toDouble()).isCloseTo( - now.toDouble() + durationMillis, Offset.offset(deltaMillis) - ) + .isCloseTo(now.toDouble(), deltaMillis) + assertThat(certificate.notAfter.time.toDouble()) + .isCloseTo(now.toDouble() + durationMillis, deltaMillis) } @Test @@ -89,7 +89,7 @@ class HeldCertificateTest { .addSubjectAlternativeName("cash.app") .build() val certificate = heldCertificate.certificate - assertThat(certificate.subjectAlternativeNames).containsExactly( + assertThat(certificate.subjectAlternativeNames.toList()).containsExactly( listOf(GeneralName.iPAddress, "1.1.1.1"), listOf(GeneralName.dNSName, "cash.app") ) @@ -213,8 +213,8 @@ class HeldCertificateTest { .ecdsa256() .signedBy(root) .build() - assertThat(root.certificate.sigAlgName).isEqualToIgnoringCase("SHA256WITHRSA") - assertThat(leaf.certificate.sigAlgName).isEqualToIgnoringCase("SHA256WITHRSA") + assertThat(root.certificate.sigAlgName).isEqualTo("SHA256WITHRSA", ignoreCase = true) + assertThat(leaf.certificate.sigAlgName).isEqualTo("SHA256WITHRSA", ignoreCase = true) } @Test @@ -228,8 +228,8 @@ class HeldCertificateTest { .rsa2048() .signedBy(root) .build() - assertThat(root.certificate.sigAlgName).isEqualToIgnoringCase("SHA256WITHECDSA") - assertThat(leaf.certificate.sigAlgName).isEqualToIgnoringCase("SHA256WITHECDSA") + assertThat(root.certificate.sigAlgName).isEqualTo("SHA256WITHECDSA", ignoreCase = true) + assertThat(leaf.certificate.sigAlgName).isEqualTo("SHA256WITHECDSA", ignoreCase = true) } @Test @@ -281,7 +281,7 @@ class HeldCertificateTest { val certificate = heldCertificate.certificate assertThat(certificate.notBefore.time).isEqualTo(5000L) assertThat(certificate.notAfter.time).isEqualTo(10000L) - assertThat(certificate.subjectAlternativeNames).containsExactly( + assertThat(certificate.subjectAlternativeNames.toList()).containsExactly( listOf(GeneralName.iPAddress, "1.1.1.1"), listOf(GeneralName.dNSName, "cash.app") ) @@ -401,9 +401,9 @@ class HeldCertificateTest { val certificate = heldCertificate.certificate assertThat(certificate.notBefore.time).isEqualTo(5000L) assertThat(certificate.notAfter.time).isEqualTo(10000L) - assertThat(certificate.subjectAlternativeNames).containsExactly( - Arrays.asList(GeneralName.iPAddress, "1.1.1.1"), - Arrays.asList(GeneralName.dNSName, "cash.app") + assertThat(certificate.subjectAlternativeNames.toList()).containsExactly( + listOf(GeneralName.iPAddress, "1.1.1.1"), + listOf(GeneralName.dNSName, "cash.app") ) assertThat(certificate.getSubjectX500Principal().name) .isEqualTo("CN=cash.app,OU=engineering") @@ -433,25 +433,25 @@ class HeldCertificateTest { decode(certificatePem) fail() } catch (expected: IllegalArgumentException) { - assertThat(expected).hasMessage("string does not include a private key") + assertThat(expected.message).isEqualTo("string does not include a private key") } try { decode(pkcs8Pem) fail() } catch (expected: IllegalArgumentException) { - assertThat(expected).hasMessage("string does not include a certificate") + assertThat(expected.message).isEqualTo("string does not include a certificate") } try { decode(certificatePem + pkcs8Pem + certificatePem) fail() } catch (expected: IllegalArgumentException) { - assertThat(expected).hasMessage("string includes multiple certificates") + assertThat(expected.message).isEqualTo("string includes multiple certificates") } try { decode(pkcs8Pem + certificatePem + pkcs8Pem) fail() } catch (expected: IllegalArgumentException) { - assertThat(expected).hasMessage("string includes multiple private keys") + assertThat(expected.message).isEqualTo("string includes multiple private keys") } } @@ -470,7 +470,7 @@ class HeldCertificateTest { ) fail() } catch (expected: IllegalArgumentException) { - assertThat(expected).hasMessage("unexpected type: RSA PRIVATE KEY") + assertThat(expected.message).isEqualTo("unexpected type: RSA PRIVATE KEY") } } @@ -491,7 +491,7 @@ class HeldCertificateTest { fail() } catch (expected: IllegalArgumentException) { if (!platform.isConscrypt()) { - assertThat(expected).hasMessage("failed to decode certificate") + assertThat(expected.message).isEqualTo("failed to decode certificate") } } try { @@ -515,7 +515,7 @@ class HeldCertificateTest { fail() } catch (expected: IllegalArgumentException) { if (!platform.isConscrypt()) { - assertThat(expected).hasMessage("failed to decode private key") + assertThat(expected.message).isEqualTo("failed to decode private key") } } } diff --git a/okhttp/build.gradle.kts b/okhttp/build.gradle.kts index 093bb6eacedf..5c3f2fb4e8df 100644 --- a/okhttp/build.gradle.kts +++ b/okhttp/build.gradle.kts @@ -139,7 +139,6 @@ dependencies { testImplementation(libs.junit.jupiter.api) testImplementation(libs.junit.jupiter.params) testImplementation(libs.kotlin.test.junit) - testImplementation(libs.assertj.core) testImplementation(libs.openjsse) testImplementation(libs.aqute.resolve) testCompileOnly(libs.findbugs.jsr305) diff --git a/okhttp/src/test/java/okhttp3/CacheTest.kt b/okhttp/src/test/java/okhttp3/CacheTest.kt index 38dc45247778..3f49b68d69b1 100644 --- a/okhttp/src/test/java/okhttp3/CacheTest.kt +++ b/okhttp/src/test/java/okhttp3/CacheTest.kt @@ -15,6 +15,15 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.containsExactly +import assertk.assertions.isCloseTo +import assertk.assertions.isEmpty +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import assertk.assertions.isNotNull +import assertk.assertions.isNull +import assertk.assertions.isTrue import java.io.IOException import java.net.CookieManager import java.net.HttpURLConnection @@ -49,8 +58,6 @@ import okio.Path import okio.Path.Companion.toPath import okio.buffer import okio.fakefilesystem.FakeFileSystem -import org.assertj.core.api.Assertions.assertThat -import org.assertj.core.data.Offset import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach @@ -2369,107 +2376,99 @@ class CacheTest { cookieJar.assertResponseCookies("a=SECOND; path=/") } - @get:Throws(Exception::class) - @get:Test - val headersReturnsNetworkEndToEndHeaders: Unit - get() { - server.enqueue( - MockResponse.Builder() - .addHeader("Allow: GET, HEAD") - .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)) - .addHeader("Cache-Control: max-age=0") - .body("A") - .build() - ) - server.enqueue( - MockResponse.Builder() - .addHeader("Allow: GET, HEAD, PUT") - .code(HttpURLConnection.HTTP_NOT_MODIFIED) - .build() - ) - val response1 = get(server.url("/")) - assertThat(response1.body.string()).isEqualTo("A") - assertThat(response1.header("Allow")).isEqualTo("GET, HEAD") - val response2 = get(server.url("/")) - assertThat(response2.body.string()).isEqualTo("A") - assertThat(response2.header("Allow")).isEqualTo("GET, HEAD, PUT") - } + @Test + fun getHeadersReturnsNetworkEndToEndHeaders() { + server.enqueue( + MockResponse.Builder() + .addHeader("Allow: GET, HEAD") + .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)) + .addHeader("Cache-Control: max-age=0") + .body("A") + .build() + ) + server.enqueue( + MockResponse.Builder() + .addHeader("Allow: GET, HEAD, PUT") + .code(HttpURLConnection.HTTP_NOT_MODIFIED) + .build() + ) + val response1 = get(server.url("/")) + assertThat(response1.body.string()).isEqualTo("A") + assertThat(response1.header("Allow")).isEqualTo("GET, HEAD") + val response2 = get(server.url("/")) + assertThat(response2.body.string()).isEqualTo("A") + assertThat(response2.header("Allow")).isEqualTo("GET, HEAD, PUT") + } - @get:Throws(Exception::class) - @get:Test - val headersReturnsCachedHopByHopHeaders: Unit - get() { - server.enqueue( - MockResponse.Builder() - .addHeader("Transfer-Encoding: identity") - .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)) - .addHeader("Cache-Control: max-age=0") - .body("A") - .build() - ) - server.enqueue( - MockResponse.Builder() - .addHeader("Transfer-Encoding: none") - .code(HttpURLConnection.HTTP_NOT_MODIFIED) - .build() - ) - val response1 = get(server.url("/")) - assertThat(response1.body.string()).isEqualTo("A") - assertThat(response1.header("Transfer-Encoding")).isEqualTo("identity") - val response2 = get(server.url("/")) - assertThat(response2.body.string()).isEqualTo("A") - assertThat(response2.header("Transfer-Encoding")).isEqualTo("identity") - } + @Test + fun getHeadersReturnsCachedHopByHopHeaders() { + server.enqueue( + MockResponse.Builder() + .addHeader("Transfer-Encoding: identity") + .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)) + .addHeader("Cache-Control: max-age=0") + .body("A") + .build() + ) + server.enqueue( + MockResponse.Builder() + .addHeader("Transfer-Encoding: none") + .code(HttpURLConnection.HTTP_NOT_MODIFIED) + .build() + ) + val response1 = get(server.url("/")) + assertThat(response1.body.string()).isEqualTo("A") + assertThat(response1.header("Transfer-Encoding")).isEqualTo("identity") + val response2 = get(server.url("/")) + assertThat(response2.body.string()).isEqualTo("A") + assertThat(response2.header("Transfer-Encoding")).isEqualTo("identity") + } - @get:Throws(Exception::class) - @get:Test - val headersDeletesCached100LevelWarnings: Unit - get() { - server.enqueue( - MockResponse.Builder() - .addHeader("Warning: 199 test danger") - .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)) - .addHeader("Cache-Control: max-age=0") - .body("A") - .build() - ) - server.enqueue( - MockResponse.Builder() - .code(HttpURLConnection.HTTP_NOT_MODIFIED) - .build() - ) - val response1 = get(server.url("/")) - assertThat(response1.body.string()).isEqualTo("A") - assertThat(response1.header("Warning")).isEqualTo("199 test danger") - val response2 = get(server.url("/")) - assertThat(response2.body.string()).isEqualTo("A") - assertThat(response2.header("Warning")).isNull() - } + @Test + fun getHeadersDeletesCached100LevelWarnings() { + server.enqueue( + MockResponse.Builder() + .addHeader("Warning: 199 test danger") + .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)) + .addHeader("Cache-Control: max-age=0") + .body("A") + .build() + ) + server.enqueue( + MockResponse.Builder() + .code(HttpURLConnection.HTTP_NOT_MODIFIED) + .build() + ) + val response1 = get(server.url("/")) + assertThat(response1.body.string()).isEqualTo("A") + assertThat(response1.header("Warning")).isEqualTo("199 test danger") + val response2 = get(server.url("/")) + assertThat(response2.body.string()).isEqualTo("A") + assertThat(response2.header("Warning")).isNull() + } - @get:Throws(Exception::class) - @get:Test - val headersRetainsCached200LevelWarnings: Unit - get() { - server.enqueue( - MockResponse.Builder() - .addHeader("Warning: 299 test danger") - .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)) - .addHeader("Cache-Control: max-age=0") - .body("A") - .build() - ) - server.enqueue( - MockResponse.Builder() - .code(HttpURLConnection.HTTP_NOT_MODIFIED) - .build() - ) - val response1 = get(server.url("/")) - assertThat(response1.body.string()).isEqualTo("A") - assertThat(response1.header("Warning")).isEqualTo("299 test danger") - val response2 = get(server.url("/")) - assertThat(response2.body.string()).isEqualTo("A") - assertThat(response2.header("Warning")).isEqualTo("299 test danger") - } + @Test + fun getHeadersRetainsCached200LevelWarnings() { + server.enqueue( + MockResponse.Builder() + .addHeader("Warning: 299 test danger") + .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)) + .addHeader("Cache-Control: max-age=0") + .body("A") + .build() + ) + server.enqueue( + MockResponse.Builder() + .code(HttpURLConnection.HTTP_NOT_MODIFIED) + .build() + ) + val response1 = get(server.url("/")) + assertThat(response1.body.string()).isEqualTo("A") + assertThat(response1.header("Warning")).isEqualTo("299 test danger") + val response2 = get(server.url("/")) + assertThat(response2.body.string()).isEqualTo("A") + assertThat(response2.header("Warning")).isEqualTo("299 test danger") + } @Test fun doNotCachePartialResponse() { @@ -2510,8 +2509,7 @@ class CacheTest { val response1 = get(server.url("/a")) assertThat(response1.body.string()).isEqualTo("A") assertThat(response1.header("Allow")).isNull() - assertThat((response1.receivedResponseAtMillis - t0).toDouble()) - .isCloseTo(0.0, Offset.offset(250.0)) + assertThat((response1.receivedResponseAtMillis - t0).toDouble()).isCloseTo(0.0, 250.0) // A conditional cache hit updates the cache. Thread.sleep(500) // Make sure t0 and t1 are distinct. @@ -2521,8 +2519,7 @@ class CacheTest { assertThat(response2.body.string()).isEqualTo("A") assertThat(response2.header("Allow")).isEqualTo("GET, HEAD") val updatedTimestamp = response2.receivedResponseAtMillis - assertThat((updatedTimestamp - t1).toDouble()) - .isCloseTo(0.0, Offset.offset(250.0)) + assertThat((updatedTimestamp - t1).toDouble()).isCloseTo(0.0, 250.0) // A full cache hit reads the cache. Thread.sleep(10) diff --git a/okhttp/src/test/java/okhttp3/CertificateChainCleanerTest.kt b/okhttp/src/test/java/okhttp3/CertificateChainCleanerTest.kt index 01f827637fe0..c4f4f28820de 100644 --- a/okhttp/src/test/java/okhttp3/CertificateChainCleanerTest.kt +++ b/okhttp/src/test/java/okhttp3/CertificateChainCleanerTest.kt @@ -15,12 +15,13 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.isEqualTo import java.security.cert.Certificate import javax.net.ssl.SSLPeerUnverifiedException import okhttp3.internal.tls.CertificateChainCleaner.Companion.get import okhttp3.tls.HandshakeCertificates import okhttp3.tls.HeldCertificate -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Test diff --git a/okhttp/src/test/java/okhttp3/CertificatePinnerTest.kt b/okhttp/src/test/java/okhttp3/CertificatePinnerTest.kt index 0250032b7103..10c3460829a6 100644 --- a/okhttp/src/test/java/okhttp3/CertificatePinnerTest.kt +++ b/okhttp/src/test/java/okhttp3/CertificatePinnerTest.kt @@ -15,13 +15,15 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.isEqualTo +import assertk.assertions.isNotEqualTo import java.util.Arrays import javax.net.ssl.SSLPeerUnverifiedException import okhttp3.CertificatePinner.Companion.pin import okhttp3.CertificatePinner.Companion.sha1Hash import okhttp3.tls.HeldCertificate import okio.ByteString.Companion.decodeBase64 -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.fail @@ -61,12 +63,8 @@ class CertificatePinnerTest { .serialNumber(201L) .build() val keypairBCertificate2Pin = pin(heldCertificateB2.certificate) - assertThat(keypairACertificate2Pin).isEqualTo( - certA1Sha256Pin - ) - assertThat(keypairBCertificate2Pin).isEqualTo( - certB1Sha256Pin - ) + assertThat(keypairACertificate2Pin).isEqualTo(certA1Sha256Pin) + assertThat(keypairBCertificate2Pin).isEqualTo(certB1Sha256Pin) assertThat(certB1Sha256Pin).isNotEqualTo(certA1Sha256Pin) } diff --git a/okhttp/src/test/java/okhttp3/CipherSuiteTest.kt b/okhttp/src/test/java/okhttp3/CipherSuiteTest.kt index bb7dcdf971e3..5b38579ce545 100644 --- a/okhttp/src/test/java/okhttp3/CipherSuiteTest.kt +++ b/okhttp/src/test/java/okhttp3/CipherSuiteTest.kt @@ -15,9 +15,12 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.isEqualTo +import assertk.assertions.isNotEqualTo +import assertk.assertions.isSameAs import okhttp3.CipherSuite.Companion.forJavaName import okhttp3.internal.applyConnectionSpec -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.assertArrayEquals import org.junit.jupiter.api.Test @@ -25,8 +28,7 @@ class CipherSuiteTest { @Test fun hashCode_usesIdentityHashCode_legacyCase() { val cs = CipherSuite.TLS_RSA_EXPORT_WITH_RC4_40_MD5 // This one's javaName starts with "SSL_". - assertThat(cs.hashCode()) - .overridingErrorMessage(cs.toString()) + assertThat(cs.hashCode(), cs.toString()) .isEqualTo(System.identityHashCode(cs)) } @@ -34,8 +36,7 @@ class CipherSuiteTest { fun hashCode_usesIdentityHashCode_regularCase() { // This one's javaName matches the identifier. val cs = CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256 - assertThat(cs.hashCode()) - .overridingErrorMessage(cs.toString()) + assertThat(cs.hashCode(), cs.toString()) .isEqualTo(System.identityHashCode(cs)) } diff --git a/okhttp/src/test/java/okhttp3/ConnectionCoalescingTest.kt b/okhttp/src/test/java/okhttp3/ConnectionCoalescingTest.kt index 13027d01496d..6c9f0ffae1e8 100644 --- a/okhttp/src/test/java/okhttp3/ConnectionCoalescingTest.kt +++ b/okhttp/src/test/java/okhttp3/ConnectionCoalescingTest.kt @@ -15,6 +15,8 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.isEqualTo import java.io.IOException import java.net.InetAddress import java.net.InetSocketAddress @@ -34,7 +36,6 @@ import okhttp3.CertificatePinner.Companion.pin import okhttp3.testing.PlatformRule import okhttp3.tls.HandshakeCertificates import okhttp3.tls.HeldCertificate -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Tag diff --git a/okhttp/src/test/java/okhttp3/ConnectionSpecTest.kt b/okhttp/src/test/java/okhttp3/ConnectionSpecTest.kt index 15558a396974..dcae22f1bc2a 100644 --- a/okhttp/src/test/java/okhttp3/ConnectionSpecTest.kt +++ b/okhttp/src/test/java/okhttp3/ConnectionSpecTest.kt @@ -15,7 +15,14 @@ */ package okhttp3 -import java.util.Arrays +import assertk.assertThat +import assertk.assertions.containsExactly +import assertk.assertions.containsExactlyInAnyOrder +import assertk.assertions.isEmpty +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import assertk.assertions.isNull +import assertk.assertions.isTrue import java.util.concurrent.CopyOnWriteArraySet import javax.net.ssl.SSLSocket import javax.net.ssl.SSLSocketFactory @@ -23,7 +30,6 @@ import okhttp3.internal.applyConnectionSpec import okhttp3.internal.platform.Platform.Companion.isAndroid import okhttp3.testing.PlatformRule import okhttp3.testing.PlatformVersion.majorVersion -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.RegisterExtension @@ -71,9 +77,9 @@ class ConnectionSpecTest { .tlsVersions(TlsVersion.TLS_1_2) .supportsTlsExtensions(true) .build() - assertThat(tlsSpec.cipherSuites) + assertThat(tlsSpec.cipherSuites!!.toList()) .containsExactly(CipherSuite.TLS_RSA_WITH_RC4_128_MD5) - assertThat(tlsSpec.tlsVersions) + assertThat(tlsSpec.tlsVersions!!.toList()) .containsExactly(TlsVersion.TLS_1_2) assertThat(tlsSpec.supportsTlsExtensions).isTrue() } @@ -85,7 +91,7 @@ class ConnectionSpecTest { .supportsTlsExtensions(true) .build() assertThat(tlsSpec.cipherSuites).isNull() - assertThat(tlsSpec.tlsVersions) + assertThat(tlsSpec.tlsVersions!!.toList()) .containsExactly(TlsVersion.TLS_1_2) assertThat(tlsSpec.supportsTlsExtensions).isTrue() } @@ -112,7 +118,7 @@ class ConnectionSpecTest { assertThat(socket.enabledProtocols).containsExactly( TlsVersion.TLS_1_2.javaName ) - assertThat(socket.enabledCipherSuites) + assertThat(socket.enabledCipherSuites.toList()) .containsExactlyInAnyOrder( CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256.javaName, CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA.javaName @@ -148,7 +154,7 @@ class ConnectionSpecTest { expectedCipherSuites.add("TLS_FALLBACK_SCSV") } assertThat(socket.enabledCipherSuites) - .containsExactlyElementsOf(expectedCipherSuites) + .containsExactly(*expectedCipherSuites.toTypedArray()) } @Test @@ -176,11 +182,11 @@ class ConnectionSpecTest { ) val expectedCipherSuites: MutableList = ArrayList() expectedCipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256.javaName) - if (Arrays.asList(*socket.supportedCipherSuites).contains("TLS_FALLBACK_SCSV")) { + if (listOf(*socket.supportedCipherSuites).contains("TLS_FALLBACK_SCSV")) { expectedCipherSuites.add("TLS_FALLBACK_SCSV") } assertThat(socket.enabledCipherSuites) - .containsExactlyElementsOf(expectedCipherSuites) + .containsExactly(*expectedCipherSuites.toTypedArray()) } @Test diff --git a/okhttp/src/test/java/okhttp3/CookiesTest.kt b/okhttp/src/test/java/okhttp3/CookiesTest.kt index 52a83f7cb932..60605418feb1 100644 --- a/okhttp/src/test/java/okhttp3/CookiesTest.kt +++ b/okhttp/src/test/java/okhttp3/CookiesTest.kt @@ -15,6 +15,14 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.isCloseTo +import assertk.assertions.isEmpty +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import assertk.assertions.isGreaterThan +import assertk.assertions.isNull +import assertk.assertions.isTrue import java.net.CookieHandler import java.net.CookieManager import java.net.CookiePolicy @@ -27,8 +35,6 @@ import mockwebserver3.MockWebServer import okhttp3.Cookie.Companion.parse import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.java.net.cookiejar.JavaNetCookieJar -import org.assertj.core.api.Assertions.assertThat -import org.assertj.core.data.Offset import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -110,7 +116,7 @@ class CookiesTest { assertThat(cookie.commentURL).isNull() assertThat(cookie.discard).isFalse() // Converting to a fixed date can cause rounding! - assertThat(cookie.maxAge.toDouble()).isCloseTo(60.0, Offset.offset(5.0)) + assertThat(cookie.maxAge.toDouble()).isCloseTo(60.0, 5.0) assertThat(cookie.path).isEqualTo("/path") assertThat(cookie.secure).isTrue() } @@ -145,7 +151,7 @@ class CookiesTest { assertThat(cookie.name).isEqualTo("a") assertThat(cookie.value).isEqualTo("android") // Converting to a fixed date can cause rounding! - assertThat(cookie.maxAge.toDouble()).isCloseTo(60.0, Offset.offset(1.0)) + assertThat(cookie.maxAge.toDouble()).isCloseTo(60.0, 1.0) assertThat(cookie.path).isEqualTo("/path") assertThat(cookie.secure).isTrue() } diff --git a/okhttp/src/test/java/okhttp3/DispatcherTest.kt b/okhttp/src/test/java/okhttp3/DispatcherTest.kt index 9226710bbdcd..1b5b9cee6a9a 100644 --- a/okhttp/src/test/java/okhttp3/DispatcherTest.kt +++ b/okhttp/src/test/java/okhttp3/DispatcherTest.kt @@ -1,12 +1,18 @@ package okhttp3 +import assertk.assertThat +import assertk.assertions.containsExactly +import assertk.assertions.containsExactlyInAnyOrder +import assertk.assertions.isEmpty +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import assertk.assertions.isTrue import java.io.IOException import java.io.InterruptedIOException import java.net.UnknownHostException import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicBoolean -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Tag diff --git a/okhttp/src/test/java/okhttp3/DuplexTest.kt b/okhttp/src/test/java/okhttp3/DuplexTest.kt index 924b07c57670..a13682823425 100644 --- a/okhttp/src/test/java/okhttp3/DuplexTest.kt +++ b/okhttp/src/test/java/okhttp3/DuplexTest.kt @@ -15,6 +15,12 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.contains +import assertk.assertions.containsExactly +import assertk.assertions.isEqualTo +import assertk.assertions.isNull +import assertk.assertions.isTrue import java.io.IOException import java.net.HttpURLConnection import java.net.ProtocolException @@ -34,9 +40,8 @@ import okhttp3.internal.RecordingOkAuthenticator import okhttp3.internal.duplex.AsyncRequestBody import okhttp3.testing.PlatformRule import okio.BufferedSink -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Disabled @@ -200,17 +205,12 @@ class DuplexTest { .build() ) call.execute().use { response -> - assertThat?>(response.headers) - .isEqualTo( - headersOf("h1", "v1", "h2", "v2") - ) + assertThat(response.headers) + .isEqualTo(headersOf("h1", "v1", "h2", "v2")) val responseBody = response.body.source() assertThat(responseBody.readUtf8(2)).isEqualTo("ok") - Assertions.assertTrue(responseBody.exhausted()) - assertThat?>(response.trailers()) - .isEqualTo( - headersOf("trailers", "boom") - ) + assertThat(responseBody.exhausted()).isTrue() + assertThat(response.trailers()).isEqualTo(headersOf("trailers", "boom")) } body.awaitSuccess() } @@ -267,7 +267,7 @@ class DuplexTest { ) call.execute().use { response -> val responseBody = response.body.source() - Assertions.assertTrue(responseBody.exhausted()) + assertTrue(responseBody.exhausted()) val requestBody = (call.request().body as AsyncRequestBody?)!!.takeSink() requestBody.writeUtf8("request A\n") requestBody.close() @@ -448,7 +448,7 @@ class DuplexTest { val responseBody2 = response2.body.source() assertThat(responseBody2.readUtf8Line()) .isEqualTo("response body") - Assertions.assertTrue(responseBody2.exhausted()) + assertTrue(responseBody2.exhausted()) body.awaitSuccess() // No more requests attempted! @@ -474,7 +474,7 @@ class DuplexTest { fail() } catch (e: IOException) { assertThat(e.message).isEqualTo("timeout") - Assertions.assertTrue(call.isCanceled()) + assertTrue(call.isCanceled()) } } @@ -607,7 +607,7 @@ class DuplexTest { assertThat(response.body.string()).isEqualTo("success!") } body.awaitSuccess() - assertThat(log.take()) + assertThat(log.take()!!) .contains("StreamResetException: stream was reset: CANCEL") } diff --git a/okhttp/src/test/java/okhttp3/EventListenerTest.kt b/okhttp/src/test/java/okhttp3/EventListenerTest.kt index 93063b982d50..ed3888f651ee 100644 --- a/okhttp/src/test/java/okhttp3/EventListenerTest.kt +++ b/okhttp/src/test/java/okhttp3/EventListenerTest.kt @@ -15,6 +15,16 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.contains +import assertk.assertions.containsExactly +import assertk.assertions.doesNotContain +import assertk.assertions.isEqualTo +import assertk.assertions.isIn +import assertk.assertions.isInstanceOf +import assertk.assertions.isNotNull +import assertk.assertions.isNull +import assertk.assertions.isSameAs import java.io.File import java.io.IOException import java.io.InterruptedIOException @@ -61,7 +71,6 @@ import okhttp3.testing.Flaky import okhttp3.testing.PlatformRule import okio.Buffer import okio.BufferedSink -import org.assertj.core.api.Assertions.assertThat import org.hamcrest.BaseMatcher import org.hamcrest.CoreMatchers import org.hamcrest.Description @@ -617,9 +626,7 @@ class EventListenerTest { listener.removeUpToEvent() val callFailed: CallFailed = listener.removeUpToEvent() assertThat(callFailed.call).isSameAs(call) - assertThat(callFailed.ioe).isInstanceOf( - UnknownHostException::class.java - ) + assertThat(callFailed.ioe).isInstanceOf() } @Test diff --git a/okhttp/src/test/java/okhttp3/FormBodyTest.kt b/okhttp/src/test/java/okhttp3/FormBodyTest.kt index 6e8f8a09720d..cdf9a424e90b 100644 --- a/okhttp/src/test/java/okhttp3/FormBodyTest.kt +++ b/okhttp/src/test/java/okhttp3/FormBodyTest.kt @@ -15,10 +15,11 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.isEqualTo import java.io.IOException import java.nio.charset.StandardCharsets import okio.Buffer -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test class FormBodyTest { diff --git a/okhttp/src/test/java/okhttp3/InterceptorTest.kt b/okhttp/src/test/java/okhttp3/InterceptorTest.kt index ca4260b43aed..1fbf461ca308 100644 --- a/okhttp/src/test/java/okhttp3/InterceptorTest.kt +++ b/okhttp/src/test/java/okhttp3/InterceptorTest.kt @@ -15,6 +15,15 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.contains +import assertk.assertions.containsExactly +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import assertk.assertions.isNotNull +import assertk.assertions.isNull +import assertk.assertions.isSameAs +import assertk.assertions.isTrue import java.io.IOException import java.net.SocketTimeoutException import java.time.Duration @@ -39,7 +48,6 @@ import okio.GzipSink import okio.Sink import okio.Source import okio.buffer -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Tag @@ -543,10 +551,9 @@ class InterceptorTest { val call = client.newCall(request) call.enqueue(callback) val recordedResponse = callback.await(server.url("/")) - assertThat(recordedResponse.failure) - .hasMessage("canceled due to java.lang.RuntimeException: boom!") + assertThat(recordedResponse.failure, "canceled due to java.lang.RuntimeException: boom!") recordedResponse.failure!!.assertSuppressed { throwables: List? -> - assertThat(throwables).contains(boom) + assertThat(throwables!!).contains(boom) Unit } assertThat(call.isCanceled()).isTrue() diff --git a/okhttp/src/test/java/okhttp3/MultipartBodyTest.kt b/okhttp/src/test/java/okhttp3/MultipartBodyTest.kt index f48aeb6e9fc4..116512cb20c5 100644 --- a/okhttp/src/test/java/okhttp3/MultipartBodyTest.kt +++ b/okhttp/src/test/java/okhttp3/MultipartBodyTest.kt @@ -15,6 +15,8 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.isEqualTo import java.io.IOException import java.nio.charset.StandardCharsets import okhttp3.Headers.Companion.headersOf @@ -23,9 +25,7 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody.Companion.toRequestBody import okio.Buffer import okio.BufferedSink -import okio.ByteString.Companion.encodeUtf8 import okio.utf8Size -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Test diff --git a/okhttp/src/test/java/okhttp3/ProtocolTest.kt b/okhttp/src/test/java/okhttp3/ProtocolTest.kt index 408dbc75b33c..c536ddc0e5c3 100644 --- a/okhttp/src/test/java/okhttp3/ProtocolTest.kt +++ b/okhttp/src/test/java/okhttp3/ProtocolTest.kt @@ -15,9 +15,10 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.isEqualTo import java.io.IOException import okhttp3.Protocol.Companion.get -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.assertThrows import org.junit.jupiter.api.Test diff --git a/okhttp/src/test/java/okhttp3/RecordedResponse.kt b/okhttp/src/test/java/okhttp3/RecordedResponse.kt index 90ad85c8fbf6..f2a6ad69c8ff 100644 --- a/okhttp/src/test/java/okhttp3/RecordedResponse.kt +++ b/okhttp/src/test/java/okhttp3/RecordedResponse.kt @@ -15,10 +15,18 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.contains +import assertk.assertions.containsExactly +import assertk.assertions.isBetween +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import assertk.assertions.isNotNull +import assertk.assertions.isNull +import assertk.assertions.isTrue import java.io.IOException import java.text.SimpleDateFormat import java.util.Date -import org.assertj.core.api.Assertions.assertThat /** * A received response or failure recorded by the response recorder. @@ -119,16 +127,14 @@ class RecordedResponse( break } } - assertThat(found) - .overridingErrorMessage( - "Expected exception type among " - + allowedExceptionTypes.contentToString() + ", got " + failure - ) - .isTrue() + assertThat( + found, + "Expected exception type among ${allowedExceptionTypes.contentToString()}, got $failure" + ).isTrue() } fun assertFailure(vararg messages: String) = apply { - assertThat(failure).overridingErrorMessage("No failure found").isNotNull() + assertThat(failure, "No failure found").isNotNull() assertThat(messages).contains(failure!!.message) } @@ -148,8 +154,7 @@ class RecordedResponse( } private fun assertDateInRange(minimum: Long, actual: Long, maximum: Long) { - assertThat(actual) - .overridingErrorMessage("${format(minimum)} <= ${format(actual)} <= ${format(maximum)}") + assertThat(actual, "${format(minimum)} <= ${format(actual)} <= ${format(maximum)}") .isBetween(minimum, maximum) } diff --git a/okhttp/src/test/java/okhttp3/RequestTest.kt b/okhttp/src/test/java/okhttp3/RequestTest.kt index 83d97631acda..10efd790620e 100644 --- a/okhttp/src/test/java/okhttp3/RequestTest.kt +++ b/okhttp/src/test/java/okhttp3/RequestTest.kt @@ -26,6 +26,7 @@ import java.io.File import java.io.FileWriter import java.net.URI import java.util.UUID +import kotlin.test.fail import okhttp3.Headers.Companion.headersOf import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.MediaType.Companion.toMediaType @@ -33,7 +34,6 @@ import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody import okio.Buffer import okio.ByteString.Companion.encodeUtf8 -import org.assertj.core.api.Assertions.fail import org.junit.jupiter.api.Test class RequestTest { diff --git a/okhttp/src/test/java/okhttp3/SocksProxyTest.kt b/okhttp/src/test/java/okhttp3/SocksProxyTest.kt index 8d76986a7f4c..efa69e41d439 100644 --- a/okhttp/src/test/java/okhttp3/SocksProxyTest.kt +++ b/okhttp/src/test/java/okhttp3/SocksProxyTest.kt @@ -15,6 +15,8 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.isEqualTo import java.io.IOException import java.net.ProxySelector import java.net.SocketAddress @@ -22,7 +24,6 @@ import java.net.URI import mockwebserver3.MockResponse import mockwebserver3.MockWebServer import okhttp3.testing.PlatformRule -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/okhttp/src/test/java/okhttp3/WholeOperationTimeoutTest.kt b/okhttp/src/test/java/okhttp3/WholeOperationTimeoutTest.kt index c88eff6c6a55..93ad386001eb 100644 --- a/okhttp/src/test/java/okhttp3/WholeOperationTimeoutTest.kt +++ b/okhttp/src/test/java/okhttp3/WholeOperationTimeoutTest.kt @@ -15,6 +15,11 @@ */ package okhttp3 +import assertk.assertThat +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import assertk.assertions.isNotNull +import assertk.assertions.isTrue import java.io.IOException import java.io.InterruptedIOException import java.net.HttpURLConnection @@ -28,7 +33,6 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.TestUtil.repeat import okhttp3.testing.Flaky import okio.BufferedSink -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Tag diff --git a/okhttp/src/test/java/okhttp3/internal/cache2/FileOperatorTest.kt b/okhttp/src/test/java/okhttp3/internal/cache2/FileOperatorTest.kt index 946c599d1f62..6b3b17c42634 100644 --- a/okhttp/src/test/java/okhttp3/internal/cache2/FileOperatorTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/cache2/FileOperatorTest.kt @@ -15,6 +15,8 @@ */ package okhttp3.internal.cache2 +import assertk.assertThat +import assertk.assertions.isEqualTo import java.io.File import java.io.RandomAccessFile import java.util.Random @@ -24,7 +26,6 @@ import okio.ByteString.Companion.encodeUtf8 import okio.buffer import okio.sink import okio.source -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach diff --git a/okhttp/src/test/java/okhttp3/internal/cache2/RelayTest.kt b/okhttp/src/test/java/okhttp3/internal/cache2/RelayTest.kt index eb1cb33bf208..9fac7315037c 100644 --- a/okhttp/src/test/java/okhttp3/internal/cache2/RelayTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/cache2/RelayTest.kt @@ -15,6 +15,11 @@ */ package okhttp3.internal.cache2 +import assertk.assertThat +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import assertk.assertions.isNull +import assertk.assertions.isTrue import java.io.File import java.io.IOException import java.util.concurrent.Callable @@ -28,7 +33,6 @@ import okio.Pipe import okio.Source import okio.buffer import okio.source -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Tag diff --git a/okhttp/src/test/java/okhttp3/internal/http/StatusLineTest.kt b/okhttp/src/test/java/okhttp3/internal/http/StatusLineTest.kt index 4e5064af96aa..91ccb8719ef8 100644 --- a/okhttp/src/test/java/okhttp3/internal/http/StatusLineTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/http/StatusLineTest.kt @@ -15,10 +15,11 @@ */ package okhttp3.internal.http +import assertk.assertThat +import assertk.assertions.isEqualTo import java.net.ProtocolException import okhttp3.Protocol import okhttp3.internal.http.StatusLine.Companion.parse -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Test diff --git a/okhttp/src/test/java/okhttp3/internal/http2/HpackTest.kt b/okhttp/src/test/java/okhttp3/internal/http2/HpackTest.kt index 00ff1ed13a69..44b65f8c804e 100644 --- a/okhttp/src/test/java/okhttp3/internal/http2/HpackTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/http2/HpackTest.kt @@ -15,6 +15,10 @@ */ package okhttp3.internal.http2 +import assertk.assertThat +import assertk.assertions.containsExactly +import assertk.assertions.isEqualTo +import assertk.assertions.isNull import java.io.IOException import java.util.Arrays import okhttp3.TestUtil.headerEntries @@ -22,7 +26,6 @@ import okio.Buffer import okio.ByteString import okio.ByteString.Companion.decodeHex import okio.ByteString.Companion.encodeUtf8 -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -782,7 +785,7 @@ class HpackTest { hpackWriter!!.writeInt(0x7fffffff, 31, 0) assertBytes(31, 224, 255, 255, 255, 7) assertThat(newReader(byteStream(224, 255, 255, 255, 7)).readInt(31, 31)) - .isEqualTo(0x7fffffffL) + .isEqualTo(0x7fffffff) } @Test @@ -1057,7 +1060,7 @@ class HpackTest { } @Test - fun incrementalIndexingWithDynamcTableIndexedName() { + fun incrementalIndexingWithDynamicTableIndexedName() { hpackWriter!!.writeHeaders(headerEntries("foo", "bar")) assertBytes(0x40, 3, 'f'.code, 'o'.code, 'o'.code, 3, 'b'.code, 'a'.code, 'r'.code) assertThat(hpackWriter!!.headerCount).isEqualTo(1) diff --git a/okhttp/src/test/java/okhttp3/internal/http2/HuffmanTest.kt b/okhttp/src/test/java/okhttp3/internal/http2/HuffmanTest.kt index 1278ad9b0d19..63a9efa482dd 100644 --- a/okhttp/src/test/java/okhttp3/internal/http2/HuffmanTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/http2/HuffmanTest.kt @@ -15,6 +15,8 @@ */ package okhttp3.internal.http2 +import assertk.assertThat +import assertk.assertions.isEqualTo import java.util.Random import okhttp3.internal.http2.Huffman.decode import okhttp3.internal.http2.Huffman.encode @@ -23,7 +25,6 @@ import okio.Buffer import okio.ByteString import okio.ByteString.Companion.encodeUtf8 import okio.ByteString.Companion.toByteString -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -44,7 +45,7 @@ class HuffmanTest { private fun assertRoundTrip(data: ByteString) { val encodeBuffer = Buffer() encode(data, encodeBuffer) - assertThat(encodedLength(data)).isEqualTo(encodeBuffer.size) + assertThat(encodedLength(data).toLong()).isEqualTo(encodeBuffer.size) val decodeBuffer = Buffer() decode(encodeBuffer, encodeBuffer.size, decodeBuffer) assertEquals(data, decodeBuffer.readByteString()) diff --git a/okhttp/src/test/java/okhttp3/internal/http2/SettingsTest.kt b/okhttp/src/test/java/okhttp3/internal/http2/SettingsTest.kt index 4b508ade893c..1c82a2d83a21 100644 --- a/okhttp/src/test/java/okhttp3/internal/http2/SettingsTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/http2/SettingsTest.kt @@ -15,7 +15,10 @@ */ package okhttp3.internal.http2 -import org.assertj.core.api.Assertions.assertThat +import assertk.assertThat +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import assertk.assertions.isTrue import org.junit.jupiter.api.Test class SettingsTest { diff --git a/okhttp/src/test/java/okhttp3/internal/platform/Jdk8WithJettyBootPlatformTest.kt b/okhttp/src/test/java/okhttp3/internal/platform/Jdk8WithJettyBootPlatformTest.kt index f7364c043453..bd2c3bf78be2 100644 --- a/okhttp/src/test/java/okhttp3/internal/platform/Jdk8WithJettyBootPlatformTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/platform/Jdk8WithJettyBootPlatformTest.kt @@ -15,9 +15,11 @@ */ package okhttp3.internal.platform +import assertk.assertThat +import assertk.assertions.isNotNull +import assertk.assertions.isNull import okhttp3.internal.platform.Jdk8WithJettyBootPlatform.Companion.buildIfSupported import okhttp3.testing.PlatformRule -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assumptions.assumeFalse import org.junit.jupiter.api.Assumptions.assumeTrue import org.junit.jupiter.api.Test diff --git a/okhttp/src/test/java/okhttp3/internal/platform/Jdk9PlatformTest.kt b/okhttp/src/test/java/okhttp3/internal/platform/Jdk9PlatformTest.kt index f4a9e535f405..bb7ebe12faba 100644 --- a/okhttp/src/test/java/okhttp3/internal/platform/Jdk9PlatformTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/platform/Jdk9PlatformTest.kt @@ -15,11 +15,14 @@ */ package okhttp3.internal.platform +import assertk.assertThat +import assertk.assertions.isEqualTo +import assertk.assertions.isNotNull +import assertk.assertions.isNull import javax.net.ssl.SSLSocket import okhttp3.DelegatingSSLSocket import okhttp3.internal.platform.Jdk9Platform.Companion.buildIfSupported import okhttp3.testing.PlatformRule -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.RegisterExtension diff --git a/okhttp/src/test/java/okhttp3/internal/platform/PlatformTest.kt b/okhttp/src/test/java/okhttp3/internal/platform/PlatformTest.kt index 14081a824911..6a88ea4a8ba4 100644 --- a/okhttp/src/test/java/okhttp3/internal/platform/PlatformTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/platform/PlatformTest.kt @@ -15,9 +15,10 @@ */ package okhttp3.internal.platform +import assertk.assertThat +import assertk.assertions.isEqualTo import okhttp3.internal.platform.Platform.Companion.isAndroid import okhttp3.testing.PlatformRule -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.RegisterExtension diff --git a/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.kt b/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.kt index b78c0f0bd14f..6c95313f6200 100644 --- a/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixDatabaseTest.kt @@ -20,6 +20,7 @@ import assertk.assertions.isEqualTo import assertk.assertions.isNull import assertk.assertions.isTrue import kotlin.test.assertEquals +import kotlin.test.fail import okhttp3.internal.toCanonicalHost import okio.Buffer import okio.FileSystem @@ -27,7 +28,6 @@ import okio.GzipSource import okio.Path.Companion.toPath import okio.buffer import okio.use -import org.assertj.core.api.Assertions.fail import org.junit.jupiter.api.Test class PublicSuffixDatabaseTest { diff --git a/okhttp/src/test/java/okhttp3/internal/tls/CertificatePinnerChainValidationTest.kt b/okhttp/src/test/java/okhttp3/internal/tls/CertificatePinnerChainValidationTest.kt index e38ccb6f6738..9ef4fe0a537b 100644 --- a/okhttp/src/test/java/okhttp3/internal/tls/CertificatePinnerChainValidationTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/tls/CertificatePinnerChainValidationTest.kt @@ -15,6 +15,10 @@ */ package okhttp3.internal.tls +import assertk.assertThat +import assertk.assertions.contains +import assertk.assertions.isEqualTo +import assertk.assertions.startsWith import java.security.SecureRandom import java.security.cert.X509Certificate import javax.net.ssl.KeyManager @@ -36,7 +40,6 @@ import okhttp3.tls.HandshakeCertificates import okhttp3.tls.HeldCertificate import okhttp3.tls.internal.TlsUtil.newKeyManager import okhttp3.tls.internal.TlsUtil.newTrustManager -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -268,8 +271,7 @@ class CertificatePinnerChainValidationTest { fail() } catch (expected: SSLPeerUnverifiedException) { // Certificate pinning fails! - val message = expected.message - assertThat(message).startsWith("Certificate pinning failure!") + assertThat(expected.message!!).startsWith("Certificate pinning failure!") } } @@ -354,12 +356,10 @@ class CertificatePinnerChainValidationTest { fail() } catch (expected: SSLHandshakeException) { // On Android, the handshake fails before the certificate pinner runs. - val message = expected.message - assertThat(message).contains("Could not validate certificate") + assertThat(expected.message!!).contains("Could not validate certificate") } catch (expected: SSLPeerUnverifiedException) { // On OpenJDK, the handshake succeeds but the certificate pinner fails. - val message = expected.message - assertThat(message).startsWith("Certificate pinning failure!") + assertThat(expected.message!!).startsWith("Certificate pinning failure!") } } @@ -490,11 +490,10 @@ class CertificatePinnerChainValidationTest { .use { response -> fail("expected connection failure but got $response") } } catch (expected: SSLPeerUnverifiedException) { // Certificate pinning fails! - val message = expected.message - assertThat(message).startsWith("Certificate pinning failure!") + assertThat(expected.message!!).startsWith("Certificate pinning failure!") } catch (expected: SSLHandshakeException) { // We didn't have the opportunity to do certificate pinning because the handshake failed. - assertThat(expected).hasMessageContaining("this is not a CA certificate") + assertThat(expected.message!!).contains("this is not a CA certificate") } } diff --git a/okhttp/src/test/java/okhttp3/internal/tls/ClientAuthTest.kt b/okhttp/src/test/java/okhttp3/internal/tls/ClientAuthTest.kt index 8481190d8d82..9fc40bd7c121 100644 --- a/okhttp/src/test/java/okhttp3/internal/tls/ClientAuthTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/tls/ClientAuthTest.kt @@ -15,6 +15,11 @@ */ package okhttp3.internal.tls +import assertk.assertThat +import assertk.assertions.endsWith +import assertk.assertions.isEqualTo +import assertk.assertions.isNull +import assertk.assertions.startsWith import java.io.IOException import java.net.SocketException import java.security.GeneralSecurityException @@ -43,7 +48,6 @@ import okhttp3.tls.HandshakeCertificates import okhttp3.tls.HeldCertificate import okhttp3.tls.internal.TlsUtil.newKeyManager import okhttp3.tls.internal.TlsUtil.newTrustManager -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Tag @@ -127,12 +131,10 @@ class ClientAuthTest { ) val call = client.newCall(Request.Builder().url(server.url("/")).build()) val response = call.execute() - assertThat(response.handshake!!.peerPrincipal).isEqualTo( - X500Principal("CN=Local Host") - ) - assertThat(response.handshake!!.localPrincipal).isEqualTo( - X500Principal("CN=Jethro Willis") - ) + assertThat(response.handshake!!.peerPrincipal) + .isEqualTo(X500Principal("CN=Local Host")) + assertThat(response.handshake!!.localPrincipal) + .isEqualTo(X500Principal("CN=Jethro Willis")) assertThat(response.body.string()).isEqualTo("abc") } diff --git a/okhttp/src/test/java/okhttp3/internal/ws/RealWebSocketTest.kt b/okhttp/src/test/java/okhttp3/internal/ws/RealWebSocketTest.kt index ee86d660d56d..325d2de755d9 100644 --- a/okhttp/src/test/java/okhttp3/internal/ws/RealWebSocketTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/ws/RealWebSocketTest.kt @@ -15,6 +15,12 @@ */ package okhttp3.internal.ws +import assertk.assertThat +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import assertk.assertions.isGreaterThan +import assertk.assertions.isLessThan +import assertk.assertions.isTrue import java.io.EOFException import java.io.IOException import java.net.ProtocolException @@ -32,7 +38,6 @@ import okio.ByteString.Companion.decodeHex import okio.ByteString.Companion.encodeUtf8 import okio.Pipe import okio.buffer -import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Tag diff --git a/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.kt b/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.kt index 2c28e9c44359..daf411633ccf 100644 --- a/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.kt +++ b/okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.kt @@ -15,6 +15,16 @@ */ package okhttp3.internal.ws +import assertk.assertThat +import assertk.assertions.isBetween +import assertk.assertions.isCloseTo +import assertk.assertions.isEmpty +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import assertk.assertions.isInstanceOf +import assertk.assertions.isLessThan +import assertk.assertions.isNotNull +import assertk.assertions.isNull import java.io.EOFException import java.io.IOException import java.io.InterruptedIOException @@ -57,8 +67,6 @@ import okio.Buffer import okio.ByteString import okio.ByteString.Companion.decodeHex import okio.ByteString.Companion.encodeUtf8 -import org.assertj.core.api.Assertions.assertThat -import org.assertj.core.data.Offset import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Disabled @@ -497,9 +505,7 @@ class WebSocketHttpTest { assertThat(chain.request().body).isNull() val response = chain.proceed(chain.request()) assertThat(response.header("Connection")).isEqualTo("Upgrade") - assertThat(response.body).isInstanceOf( - UnreadableResponseBody::class.java - ) + assertThat(response.body).isInstanceOf() interceptedCount.incrementAndGet() response }) @@ -730,8 +736,8 @@ class WebSocketHttpTest { Thread.sleep(50) } val elapsedUntilPong3 = System.nanoTime() - startNanos - assertThat(TimeUnit.NANOSECONDS.toMillis(elapsedUntilPong3)) - .isCloseTo(1500L, Offset.offset(250L)) + assertThat(TimeUnit.NANOSECONDS.toMillis(elapsedUntilPong3).toDouble()) + .isCloseTo(1500.0, 250.0) // The client pinged the server 3 times, and it has ponged back 3 times. assertThat(webSocket.sentPingCount()).isEqualTo(3) @@ -803,8 +809,8 @@ class WebSocketHttpTest { ) latch.countDown() val elapsedUntilFailure = System.nanoTime() - openAtNanos - assertThat(TimeUnit.NANOSECONDS.toMillis(elapsedUntilFailure)) - .isCloseTo(1000L, Offset.offset(250L)) + assertThat(TimeUnit.NANOSECONDS.toMillis(elapsedUntilFailure).toDouble()) + .isCloseTo(1000.0, 250.0) } /** https://github.com/square/okhttp/issues/2788 */ @@ -827,8 +833,8 @@ class WebSocketHttpTest { // Confirm that the hard cancel occurred after 500 ms. clientListener.assertFailure() val elapsedUntilFailure = System.nanoTime() - closeAtNanos - assertThat(TimeUnit.NANOSECONDS.toMillis(elapsedUntilFailure)) - .isCloseTo(500L, Offset.offset(250L)) + assertThat(TimeUnit.NANOSECONDS.toMillis(elapsedUntilFailure).toDouble()) + .isCloseTo(500.0, 250.0) // Close the server and confirm it saw what we expected. server.close(1000, null) diff --git a/okhttp/src/test/java/okhttp3/internal/ws/WebSocketRecorder.kt b/okhttp/src/test/java/okhttp3/internal/ws/WebSocketRecorder.kt index 4aba0c594521..328331167f33 100644 --- a/okhttp/src/test/java/okhttp3/internal/ws/WebSocketRecorder.kt +++ b/okhttp/src/test/java/okhttp3/internal/ws/WebSocketRecorder.kt @@ -15,6 +15,12 @@ */ package okhttp3.internal.ws +import assertk.assertThat +import assertk.assertions.contains +import assertk.assertions.isEmpty +import assertk.assertions.isEqualTo +import assertk.assertions.isNull +import assertk.assertions.isSameAs import java.io.IOException import java.util.concurrent.LinkedBlockingQueue import java.util.concurrent.TimeUnit @@ -23,7 +29,6 @@ import okhttp3.WebSocket import okhttp3.WebSocketListener import okhttp3.internal.platform.Platform import okio.ByteString -import org.assertj.core.api.Assertions.assertThat class WebSocketRecorder( private val name: String, diff --git a/samples/compare/build.gradle.kts b/samples/compare/build.gradle.kts index 82cbb5696854..ec414b33f8b7 100644 --- a/samples/compare/build.gradle.kts +++ b/samples/compare/build.gradle.kts @@ -11,7 +11,6 @@ dependencies { testImplementation(libs.httpClient5) testImplementation(libs.jettyClient) testImplementation(libs.junit) - testImplementation(libs.assertj.core) testImplementation(libs.assertk) }