Skip to content

Commit

Permalink
Stop using AssertJ (#8174)
Browse files Browse the repository at this point in the history
* Stop using AssertJ

This completes the migration to assertk.

* Fix a missing import

* Fix some type issues
  • Loading branch information
squarejesse authored Jan 4, 2024
1 parent 94c9c80 commit eb6c016
Show file tree
Hide file tree
Showing 61 changed files with 388 additions and 304 deletions.
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 0 additions & 1 deletion mockwebserver-deprecated/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dependencies {

testImplementation(projects.okhttpTestingSupport)
testImplementation(projects.okhttpTls)
testImplementation(libs.assertj.core)
}

mavenPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -494,7 +504,7 @@ class MockWebServerTest {
refusedConnection.getResponseCode()
fail<Any>("Second connection should be refused")
} catch (e: ConnectException) {
assertThat(e.message).contains("refused")
assertThat(e.message!!).contains("refused")
}
}

Expand Down
1 change: 0 additions & 1 deletion mockwebserver-junit4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ dependencies {
api(projects.mockwebserver3)
api(libs.junit)

testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}

Expand Down
2 changes: 0 additions & 2 deletions mockwebserver-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion mockwebserver/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dependencies {
testImplementation(projects.okhttpTls)
testRuntimeOnly(projects.mockwebserver3Junit5)
testImplementation(libs.junit)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}

Expand Down
2 changes: 0 additions & 2 deletions native-image-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion native-image-tests/src/main/kotlin/okhttp3/SampleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions okhttp-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion okhttp-brotli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dependencies {
testImplementation(projects.okhttpTestingSupport)
testImplementation(libs.conscrypt.openjdk)
testImplementation(libs.junit)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}

Expand Down
1 change: 0 additions & 1 deletion okhttp-dnsoverhttps/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies {
testImplementation(libs.squareup.okio.fakefilesystem)
testImplementation(libs.conscrypt.openjdk)
testImplementation(libs.junit)
testImplementation(libs.assertj.core)
}

mavenPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -140,8 +145,8 @@ class DnsOverHttpsTest {
fail<Any>()
} 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<IOException>()
assertThat(cause).hasMessage("response size exceeds limit (65536 bytes): 65537 bytes")
}
}
Expand All @@ -154,7 +159,7 @@ class DnsOverHttpsTest {
fail<Any>()
} catch (ioe: IOException) {
assertThat(ioe).hasMessage("google.com")
assertThat(ioe.cause).isInstanceOf(EOFException::class.java)
assertThat(ioe.cause!!).isInstanceOf<EOFException>()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -85,7 +87,7 @@ class DnsRecordCodecTest {
"00060001000007070038026e7303746c64c01b0a686f73746d61737465720d6565737469696e7465726e65" +
"74c01b5adb12c100000e10000003840012750000000e10").decodeHex()
)
fail<Any>("")
fail("")
} catch (uhe: UnknownHostException) {
assertThat(uhe.message).isEqualTo("sdflkhfsdlkjdf.ee: NXDOMAIN")
}
Expand Down
1 change: 0 additions & 1 deletion okhttp-hpacktests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ dependencies {
testImplementation(projects.okhttpTestingSupport)
testImplementation(projects.mockwebserver)
testImplementation(libs.junit)
testImplementation(libs.assertj.core)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -67,8 +68,7 @@ open class HpackDecodeTestBase {
expected: List<Header>,
observed: List<Header>,
) {
assertThat(LinkedHashSet(observed))
.overridingErrorMessage(message)
assertThat(LinkedHashSet(observed), message)
.isEqualTo(LinkedHashSet(expected))
}
}
Expand Down
1 change: 0 additions & 1 deletion okhttp-logging-interceptor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies {
testImplementation(projects.mockwebserver3Junit5)
testImplementation(projects.okhttpTestingSupport)
testImplementation(projects.okhttpTls)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion okhttp-sse/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dependencies {
testImplementation(projects.mockwebserver3)
testImplementation(projects.mockwebserver3Junit5)
testImplementation(libs.junit)
testImplementation(libs.assertj.core)
testCompileOnly(libs.findbugs.jsr305)
}

Expand Down
Loading

0 comments on commit eb6c016

Please sign in to comment.