Skip to content

Commit b4b328a

Browse files
committed
Even more assertk
When we split tests into multiplatform we switched them from AssertJ to assertk. I'm migrating everything over to assertk so that I can merge tests back together without changing assertion APIs.
1 parent 2d7eccd commit b4b328a

File tree

69 files changed

+831
-632
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+831
-632
lines changed

okhttp-testing-support/src/test/kotlin/okhttp3/OkHttpClientTestRuleTest.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616
package okhttp3
1717

18-
import org.assertj.core.api.Assertions.assertThat
18+
import assertk.assertThat
19+
import assertk.assertions.hasMessage
1920
import org.junit.jupiter.api.Test
2021
import org.junit.jupiter.api.extension.BeforeEachCallback
2122
import org.junit.jupiter.api.extension.ExtensionContext
@@ -46,7 +47,7 @@ class OkHttpClientTestRuleTest {
4647
fail("")
4748
} catch (expected: AssertionError) {
4849
assertThat(expected).hasMessage("uncaught exception thrown during test")
49-
assertThat(expected.cause).hasMessage("boom!")
50+
assertThat(expected.cause!!).hasMessage("boom!")
5051
}
5152
}
5253
}

okhttp-tls/src/test/java/okhttp3/tls/HandshakeCertificatesTest.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package okhttp3.tls
1717

18+
import assertk.assertThat
19+
import assertk.assertions.isEqualTo
20+
import assertk.assertions.matchesPredicate
1821
import java.net.InetAddress
1922
import java.net.InetSocketAddress
2023
import java.net.ServerSocket
@@ -30,7 +33,6 @@ import okhttp3.Handshake.Companion.handshake
3033
import okhttp3.internal.closeQuietly
3134
import okhttp3.testing.PlatformRule
3235
import okio.ByteString.Companion.toByteString
33-
import org.assertj.core.api.Assertions.assertThat
3436
import org.junit.jupiter.api.AfterEach
3537
import org.junit.jupiter.api.BeforeEach
3638
import org.junit.jupiter.api.Test
@@ -133,7 +135,9 @@ class HandshakeCertificatesTest {
133135
.toSet()
134136

135137
// It's safe to assume all platforms will have a major Internet certificate issuer.
136-
assertThat(names).anyMatch { it.matches(Regex("[A-Z]+=Entrust.*")) }
138+
assertThat(names).matchesPredicate { strings ->
139+
strings.any { it.matches(Regex("[A-Z]+=Entrust.*")) }
140+
}
137141
}
138142

139143
private fun startTlsServer(): InetSocketAddress {

okhttp-tls/src/test/java/okhttp3/tls/internal/der/DerCertificatesTest.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*/
1616
package okhttp3.tls.internal.der
1717

18+
import assertk.assertThat
19+
import assertk.assertions.isEqualTo
20+
import assertk.assertions.isFalse
21+
import assertk.assertions.isNull
22+
import assertk.assertions.isTrue
1823
import java.math.BigInteger
1924
import java.security.KeyFactory
2025
import java.security.spec.PKCS8EncodedKeySpec
@@ -36,7 +41,6 @@ import okio.ByteString.Companion.decodeBase64
3641
import okio.ByteString.Companion.decodeHex
3742
import okio.ByteString.Companion.encodeUtf8
3843
import okio.ByteString.Companion.toByteString
39-
import org.assertj.core.api.Assertions.assertThat
4044
import org.junit.jupiter.api.Test
4145

4246
internal class DerCertificatesTest {

okhttp-tls/src/test/java/okhttp3/tls/internal/der/DerTest.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
*/
1616
package okhttp3.tls.internal.der
1717

18+
import assertk.assertThat
19+
import assertk.assertions.hasMessage
20+
import assertk.assertions.isEqualTo
21+
import assertk.assertions.isFalse
22+
import assertk.assertions.isNull
23+
import assertk.assertions.isTrue
1824
import java.math.BigInteger
1925
import java.net.InetAddress
2026
import java.net.ProtocolException
@@ -31,7 +37,6 @@ import okio.Buffer
3137
import okio.ByteString.Companion.decodeHex
3238
import okio.ByteString.Companion.encodeUtf8
3339
import okio.ByteString.Companion.toByteString
34-
import org.assertj.core.api.Assertions.assertThat
3540
import org.junit.jupiter.api.Disabled
3641
import org.junit.jupiter.api.Test
3742
import org.junit.jupiter.api.fail

okhttp/src/test/java/okhttp3/AddressTest.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*/
1616
package okhttp3
1717

18+
import assertk.assertThat
19+
import assertk.assertions.isEqualTo
20+
import assertk.assertions.isNotEqualTo
1821
import java.net.Proxy
1922
import okhttp3.internal.http.RecordingProxySelector
20-
import org.assertj.core.api.Assertions.assertThat
2123
import org.junit.jupiter.api.AfterEach
2224
import org.junit.jupiter.api.Test
2325

okhttp/src/test/java/okhttp3/BouncyCastleTest.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
*/
1616
package okhttp3
1717

18+
import assertk.assertThat
19+
import assertk.assertions.isEqualTo
1820
import mockwebserver3.MockWebServer
1921
import okhttp3.TestUtil.assumeNetwork
2022
import okhttp3.testing.PlatformRule
21-
import org.assertj.core.api.Assertions.assertThat
2223
import org.junit.jupiter.api.BeforeEach
2324
import org.junit.jupiter.api.Test
2425
import org.junit.jupiter.api.extension.RegisterExtension

okhttp/src/test/java/okhttp3/CacheControlJvmTest.kt

+36-34
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
*/
1616
package okhttp3
1717

18+
import assertk.assertThat
19+
import assertk.assertions.isEqualTo
20+
import assertk.assertions.isFalse
21+
import assertk.assertions.isSameAs
22+
import assertk.assertions.isTrue
23+
import java.util.concurrent.TimeUnit
1824
import okhttp3.CacheControl.Companion.parse
1925
import okhttp3.Headers.Companion.headersOf
20-
import org.junit.jupiter.api.Test
21-
import java.lang.Exception
22-
import java.lang.IllegalArgumentException
23-
import java.util.concurrent.TimeUnit
24-
import org.assertj.core.api.Assertions.assertThat
2526
import org.junit.jupiter.api.Assertions.fail
27+
import org.junit.jupiter.api.Test
2628

2729
class CacheControlJvmTest {
2830
@Test
@@ -42,20 +44,20 @@ class CacheControlJvmTest {
4244
"no-cache, no-store, max-age=1, max-stale=2, min-fresh=3, only-if-cached, "
4345
+ "no-transform, immutable"
4446
)
45-
assertThat(cacheControl.noCache).isTrue
46-
assertThat(cacheControl.noStore).isTrue
47+
assertThat(cacheControl.noCache).isTrue()
48+
assertThat(cacheControl.noStore).isTrue()
4749
assertThat(cacheControl.maxAgeSeconds).isEqualTo(1)
4850
assertThat(cacheControl.maxStaleSeconds).isEqualTo(2)
4951
assertThat(cacheControl.minFreshSeconds).isEqualTo(3)
50-
assertThat(cacheControl.onlyIfCached).isTrue
51-
assertThat(cacheControl.noTransform).isTrue
52-
assertThat(cacheControl.immutable).isTrue
52+
assertThat(cacheControl.onlyIfCached).isTrue()
53+
assertThat(cacheControl.noTransform).isTrue()
54+
assertThat(cacheControl.immutable).isTrue()
5355

5456
// These members are accessible to response headers only.
5557
assertThat(cacheControl.sMaxAgeSeconds).isEqualTo(-1)
56-
assertThat(cacheControl.isPrivate).isFalse
57-
assertThat(cacheControl.isPublic).isFalse
58-
assertThat(cacheControl.mustRevalidate).isFalse
58+
assertThat(cacheControl.isPrivate).isFalse()
59+
assertThat(cacheControl.isPublic).isFalse()
60+
assertThat(cacheControl.mustRevalidate).isFalse()
5961
}
6062

6163
@Test
@@ -65,16 +67,16 @@ class CacheControlJvmTest {
6567
Headers.Builder().set("Cache-Control", "").build()
6668
)
6769
assertThat(cacheControl.toString()).isEqualTo("")
68-
assertThat(cacheControl.noCache).isFalse
69-
assertThat(cacheControl.noStore).isFalse
70+
assertThat(cacheControl.noCache).isFalse()
71+
assertThat(cacheControl.noStore).isFalse()
7072
assertThat(cacheControl.maxAgeSeconds).isEqualTo(-1)
7173
assertThat(cacheControl.sMaxAgeSeconds).isEqualTo(-1)
72-
assertThat(cacheControl.isPublic).isFalse
73-
assertThat(cacheControl.mustRevalidate).isFalse
74+
assertThat(cacheControl.isPublic).isFalse()
75+
assertThat(cacheControl.mustRevalidate).isFalse()
7476
assertThat(cacheControl.maxStaleSeconds).isEqualTo(-1)
7577
assertThat(cacheControl.minFreshSeconds).isEqualTo(-1)
76-
assertThat(cacheControl.onlyIfCached).isFalse
77-
assertThat(cacheControl.mustRevalidate).isFalse
78+
assertThat(cacheControl.onlyIfCached).isFalse()
79+
assertThat(cacheControl.mustRevalidate).isFalse()
7880
}
7981

8082
@Test
@@ -87,17 +89,17 @@ class CacheControlJvmTest {
8789
.set("Cache-Control", header)
8890
.build()
8991
)
90-
assertThat(cacheControl.noCache).isTrue
91-
assertThat(cacheControl.noStore).isTrue
92+
assertThat(cacheControl.noCache).isTrue()
93+
assertThat(cacheControl.noStore).isTrue()
9294
assertThat(cacheControl.maxAgeSeconds).isEqualTo(1)
9395
assertThat(cacheControl.sMaxAgeSeconds).isEqualTo(2)
94-
assertThat(cacheControl.isPrivate).isTrue
95-
assertThat(cacheControl.isPublic).isTrue
96-
assertThat(cacheControl.mustRevalidate).isTrue
96+
assertThat(cacheControl.isPrivate).isTrue()
97+
assertThat(cacheControl.isPublic).isTrue()
98+
assertThat(cacheControl.mustRevalidate).isTrue()
9799
assertThat(cacheControl.maxStaleSeconds).isEqualTo(3)
98100
assertThat(cacheControl.minFreshSeconds).isEqualTo(4)
99-
assertThat(cacheControl.onlyIfCached).isTrue
100-
assertThat(cacheControl.noTransform).isTrue
101+
assertThat(cacheControl.onlyIfCached).isTrue()
102+
assertThat(cacheControl.noTransform).isTrue()
101103
assertThat(cacheControl.toString()).isEqualTo(header)
102104
}
103105

@@ -111,18 +113,18 @@ class CacheControlJvmTest {
111113
.set("Cache-Control", header)
112114
.build()
113115
)
114-
assertThat(cacheControl.noCache).isFalse
115-
assertThat(cacheControl.noStore).isFalse
116+
assertThat(cacheControl.noCache).isFalse()
117+
assertThat(cacheControl.noStore).isFalse()
116118
assertThat(cacheControl.maxAgeSeconds).isEqualTo(-1)
117119
assertThat(cacheControl.sMaxAgeSeconds).isEqualTo(-1)
118-
assertThat(cacheControl.isPrivate).isTrue
119-
assertThat(cacheControl.isPublic).isFalse
120-
assertThat(cacheControl.mustRevalidate).isFalse
120+
assertThat(cacheControl.isPrivate).isTrue()
121+
assertThat(cacheControl.isPublic).isFalse()
122+
assertThat(cacheControl.mustRevalidate).isFalse()
121123
assertThat(cacheControl.maxStaleSeconds).isEqualTo(-1)
122124
assertThat(cacheControl.minFreshSeconds).isEqualTo(-1)
123-
assertThat(cacheControl.onlyIfCached).isFalse
124-
assertThat(cacheControl.noTransform).isFalse
125-
assertThat(cacheControl.immutable).isFalse
125+
assertThat(cacheControl.onlyIfCached).isFalse()
126+
assertThat(cacheControl.noTransform).isFalse()
127+
assertThat(cacheControl.immutable).isFalse()
126128
assertThat(cacheControl.toString()).isEqualTo(header)
127129
}
128130

okhttp/src/test/java/okhttp3/CacheCorruptionTest.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package okhttp3
1717

18+
import assertk.assertThat
19+
import assertk.assertions.isEqualTo
20+
import assertk.assertions.startsWith
1821
import java.net.CookieManager
1922
import java.net.ResponseCache
2023
import java.text.DateFormat
@@ -34,7 +37,6 @@ import okhttp3.okio.LoggingFilesystem
3437
import okhttp3.testing.PlatformRule
3538
import okio.Path.Companion.toPath
3639
import okio.fakefilesystem.FakeFileSystem
37-
import org.assertj.core.api.Assertions.assertThat
3840
import org.junit.jupiter.api.AfterEach
3941
import org.junit.jupiter.api.BeforeEach
4042
import org.junit.jupiter.api.Test
@@ -94,7 +96,7 @@ class CacheCorruptionTest {
9496
assertThat(cache.networkCount()).isEqualTo(1)
9597
assertThat(cache.hitCount()).isEqualTo(1)
9698

97-
assertThat(response.handshake?.cipherSuite?.javaName).startsWith("SLT_")
99+
assertThat(response.handshake!!.cipherSuite.javaName).startsWith("SLT_")
98100
}
99101

100102
@Test

okhttp/src/test/java/okhttp3/CallHandshakeTest.kt

+36-29
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package okhttp3
1717

18+
import assertk.assertThat
19+
import assertk.assertions.containsExactly
20+
import assertk.assertions.isIn
1821
import javax.net.ssl.SSLSocket
1922
import mockwebserver3.MockResponse
2023
import mockwebserver3.MockWebServer
@@ -31,7 +34,6 @@ import okhttp3.CipherSuite.Companion.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
3134
import okhttp3.internal.effectiveCipherSuites
3235
import okhttp3.internal.platform.Platform
3336
import okhttp3.testing.PlatformRule
34-
import org.assertj.core.api.Assertions.assertThat
3537
import org.junit.jupiter.api.BeforeEach
3638
import org.junit.jupiter.api.Test
3739
import org.junit.jupiter.api.extension.RegisterExtension
@@ -101,7 +103,7 @@ class CallHandshakeTest {
101103
// TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
102104
// TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
103105
// TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
104-
assertThat(handshakeEnabledCipherSuites).containsExactlyElementsOf(
106+
assertThat(handshakeEnabledCipherSuites).containsExactly(
105107
expectedConnectionCipherSuites(client))
106108
}
107109

@@ -130,8 +132,9 @@ class CallHandshakeTest {
130132
// TLS_RSA_WITH_AES_256_CBC_SHA
131133
// TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
132134
// TLS_RSA_WITH_AES_128_CBC_SHA
133-
assertThat(handshakeEnabledCipherSuites).containsExactlyElementsOf(
134-
expectedConnectionCipherSuites(client))
135+
assertThat(handshakeEnabledCipherSuites).containsExactly(
136+
*expectedConnectionCipherSuites(client).toTypedArray()
137+
)
135138
}
136139

137140
@Test
@@ -159,8 +162,9 @@ class CallHandshakeTest {
159162
// TLS_RSA_WITH_AES_256_CBC_SHA
160163
// TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
161164
// TLS_RSA_WITH_AES_128_CBC_SHA
162-
assertThat(handshakeEnabledCipherSuites).containsExactlyElementsOf(
163-
expectedConnectionCipherSuites(client))
165+
assertThat(handshakeEnabledCipherSuites).containsExactly(
166+
*expectedConnectionCipherSuites(client).toTypedArray()
167+
)
164168
}
165169

166170
@Test
@@ -178,8 +182,9 @@ class CallHandshakeTest {
178182
val expectedConnectionCipherSuites = expectedConnectionCipherSuites(client)
179183
// Will choose a poor cipher suite but not plaintext.
180184
// assertThat(handshake.cipherSuite).isEqualTo("TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256")
181-
assertThat(handshakeEnabledCipherSuites).containsExactlyElementsOf(
182-
expectedConnectionCipherSuites)
185+
assertThat(handshakeEnabledCipherSuites).containsExactly(
186+
*expectedConnectionCipherSuites.toTypedArray()
187+
)
183188
}
184189

185190
@Test
@@ -197,12 +202,14 @@ class CallHandshakeTest {
197202
val socketOrderedByDefaults =
198203
handshakeEnabledCipherSuites.sortedBy { ConnectionSpec.MODERN_TLS.cipherSuitesAsString!!.indexOf(it) }
199204

200-
assertThat(handshakeEnabledCipherSuites).containsExactlyElementsOf(socketOrderedByDefaults)
205+
assertThat(handshakeEnabledCipherSuites).containsExactly(
206+
*socketOrderedByDefaults.toTypedArray()
207+
)
201208
}
202209

203210
@Test
204211
fun advertisedOrderInRestricted() {
205-
assertThat(ConnectionSpec.RESTRICTED_TLS.cipherSuites).containsExactly(
212+
assertThat(ConnectionSpec.RESTRICTED_TLS.cipherSuites!!).containsExactly(
206213
TLS_AES_128_GCM_SHA256,
207214
TLS_AES_256_GCM_SHA384,
208215
TLS_CHACHA20_POLY1305_SHA256,
@@ -229,26 +236,26 @@ class CallHandshakeTest {
229236
ConnectionSpec.RESTRICTED_TLS.effectiveCipherSuites(platformDefaultCipherSuites)
230237

231238
if (cipherSuites.contains(TLS_CHACHA20_POLY1305_SHA256.javaName)) {
232-
assertThat(cipherSuites).containsExactlyElementsOf(listOf(
233-
TLS_AES_128_GCM_SHA256,
234-
TLS_AES_256_GCM_SHA384,
235-
TLS_CHACHA20_POLY1305_SHA256,
236-
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
237-
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
238-
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
239-
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
240-
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
241-
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
242-
).map { it.javaName })
239+
assertThat(cipherSuites).containsExactly(
240+
TLS_AES_128_GCM_SHA256.javaName,
241+
TLS_AES_256_GCM_SHA384.javaName,
242+
TLS_CHACHA20_POLY1305_SHA256.javaName,
243+
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256.javaName,
244+
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256.javaName,
245+
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384.javaName,
246+
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384.javaName,
247+
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256.javaName,
248+
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256.javaName,
249+
)
243250
} else {
244-
assertThat(cipherSuites).containsExactlyElementsOf(listOf(
245-
TLS_AES_128_GCM_SHA256,
246-
TLS_AES_256_GCM_SHA384,
247-
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
248-
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
249-
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
250-
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
251-
).map { it.javaName })
251+
assertThat(cipherSuites).containsExactly(
252+
TLS_AES_128_GCM_SHA256.javaName,
253+
TLS_AES_256_GCM_SHA384.javaName,
254+
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384.javaName,
255+
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256.javaName,
256+
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384.javaName,
257+
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256.javaName,
258+
)
252259
}
253260
}
254261

0 commit comments

Comments
 (0)