Skip to content

Commit

Permalink
Use assertk more
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Dec 20, 2023
1 parent 3e06d64 commit 8f5d304
Show file tree
Hide file tree
Showing 29 changed files with 121 additions and 66 deletions.
1 change: 1 addition & 0 deletions android-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ dependencies {
exclude("org.conscrypt", "conscrypt-openjdk-uber")
exclude("software.amazon.cryptools", "AmazonCorrettoCryptoProvider")
}
androidTestImplementation(libs.assertk)
androidTestImplementation(libs.bouncycastle.bcprov)
androidTestImplementation(libs.bouncycastle.bctls)
androidTestImplementation(libs.conscrypt.android)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ package okhttp.android.test.alpn;

import android.os.Build
import android.util.Log
import java.net.InetSocketAddress
import java.net.Proxy
import assertk.assertThat
import assertk.assertions.isEqualTo
import javax.net.ssl.SSLSocket
import javax.net.ssl.SSLSocketFactory
import okhttp3.*
import org.assertj.core.api.Assertions.assertThat
import okhttp3.Call
import okhttp3.Connection
import okhttp3.ConnectionSpec
import okhttp3.DelegatingSSLSocketFactory
import okhttp3.EventListener
import okhttp3.OkHttpClient
import okhttp3.Request
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
package okhttp.android.test.letsencrypt;

import android.os.Build
import assertk.assertThat
import assertk.assertions.isEqualTo
import java.security.cert.X509Certificate
import okhttp3.OkHttpClient
import okhttp3.Protocol
import okhttp3.Request
import okhttp3.tls.HandshakeCertificates
import okhttp3.tls.decodeCertificatePem
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import java.security.cert.X509Certificate

/**
* Test for new Let's Encrypt Root Certificate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package okhttp.android.test.sni;

import android.os.Build
import android.util.Log
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.isEqualTo
import java.security.cert.X509Certificate
import javax.net.ssl.SNIHostName
import javax.net.ssl.SNIServerName
Expand All @@ -28,7 +31,6 @@ import okhttp3.OkHttpClient
import okhttp3.Protocol
import okhttp3.Request
import org.junit.jupiter.api.Assumptions.assumeTrue
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

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

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

mavenPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package mockwebserver3.junit4

import assertk.assertThat
import assertk.assertions.isTrue
import java.net.ConnectException
import java.util.concurrent.atomic.AtomicBoolean
import org.assertj.core.api.Assertions.assertThat
import org.junit.Assert.fail
import org.junit.Test
import org.junit.runner.Description
Expand All @@ -34,7 +35,7 @@ class MockWebServerRuleTest {
}
}, Description.EMPTY)
statement.evaluate()
assertThat(called.get()).isTrue
assertThat(called.get()).isTrue()
try {
rule.server.url("/").toUrl().openConnection().connect()
fail()
Expand Down
1 change: 1 addition & 0 deletions mockwebserver-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
testImplementation(libs.kotlin.junit5)
testImplementation(projects.okhttpTestingSupport)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}

mavenPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
*/
package mockwebserver3.junit5.internal

import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isSameAs
import assertk.assertions.isTrue
import mockwebserver3.MockResponse
import mockwebserver3.MockWebServer
import okhttp3.OkHttpClientTestRule
import okhttp3.Request
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
*/
package mockwebserver3.junit5.internal

import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEqualTo
import assertk.assertions.isTrue
import mockwebserver3.MockWebServer
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package mockwebserver3.junit5.internal

import assertk.assertThat
import assertk.assertions.isTrue
import mockwebserver3.MockWebServer
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.extension.ExtendWith

@ExtendWith(MockWebServerExtension::class)
Expand Down
1 change: 1 addition & 0 deletions mockwebserver/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
testRuntimeOnly(projects.mockwebserver3Junit5)
testImplementation(libs.junit)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}

mavenPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package mockwebserver3

import assertk.assertThat
import assertk.assertions.isEqualTo
import java.io.IOException
import java.net.HttpURLConnection
import java.util.concurrent.CountDownLatch
import java.util.concurrent.atomic.AtomicInteger
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*/
package mockwebserver3

import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import assertk.assertions.isTrue
import okhttp3.Dns
import okhttp3.Headers.Companion.headersOf
import okhttp3.HttpUrl.Companion.toHttpUrl
Expand All @@ -24,7 +29,6 @@ import okhttp3.testing.PlatformRule
import okhttp3.tls.HandshakeCertificates
import okhttp3.tls.HeldCertificate
import okhttp3.tls.internal.TlsUtil.localhost
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
Expand Down
35 changes: 22 additions & 13 deletions mockwebserver/src/test/java/mockwebserver3/MockWebServerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
*/
package mockwebserver3

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 java.io.BufferedReader
import java.io.Closeable
import java.io.IOException
Expand Down Expand Up @@ -42,8 +53,6 @@ import okhttp3.testing.PlatformRule
import okhttp3.tls.HandshakeCertificates
import okhttp3.tls.HeldCertificate
import okio.Buffer
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 @@ -371,7 +380,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 @@ -425,12 +434,12 @@ class MockWebServerTest {

@Test
fun hostnameImplicitlyStarts() {
assertThat(server.hostName).isNotNull
assertThat(server.hostName).isNotNull()
}

@Test
fun toProxyAddressImplicitlyStarts() {
assertThat(server.toProxyAddress()).isNotNull
assertThat(server.toProxyAddress()).isNotNull()
}

@Test
Expand Down Expand Up @@ -491,7 +500,7 @@ class MockWebServerTest {
refusedConnection.responseCode
fail<Any?>("Second connection should be refused")
} catch (e: ConnectException) {
assertThat(e.message).contains("refused")
assertThat(e.message!!).contains("refused")
}
}

Expand Down Expand Up @@ -579,9 +588,9 @@ class MockWebServerTest {
val request = server.takeRequest()
assertThat(request.requestUrl!!.scheme).isEqualTo("https")
val handshake = request.handshake
assertThat(handshake!!.tlsVersion).isNotNull
assertThat(handshake.cipherSuite).isNotNull
assertThat(handshake.localPrincipal).isNotNull
assertThat(handshake!!.tlsVersion).isNotNull()
assertThat(handshake.cipherSuite).isNotNull()
assertThat(handshake.localPrincipal).isNotNull()
assertThat(handshake.localCertificates.size).isEqualTo(1)
assertThat(handshake.peerPrincipal).isNull()
assertThat(handshake.peerCertificates.size).isEqualTo(0)
Expand Down Expand Up @@ -628,11 +637,11 @@ class MockWebServerTest {
val request = server.takeRequest()
assertThat(request.requestUrl!!.scheme).isEqualTo("https")
val handshake = request.handshake
assertThat(handshake!!.tlsVersion).isNotNull
assertThat(handshake.cipherSuite).isNotNull
assertThat(handshake.localPrincipal).isNotNull
assertThat(handshake!!.tlsVersion).isNotNull()
assertThat(handshake.cipherSuite).isNotNull()
assertThat(handshake.localPrincipal).isNotNull()
assertThat(handshake.localCertificates.size).isEqualTo(1)
assertThat(handshake.peerPrincipal).isNotNull
assertThat(handshake.peerPrincipal).isNotNull()
assertThat(handshake.peerCertificates.size).isEqualTo(1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package mockwebserver3

import assertk.assertThat
import assertk.assertions.isEqualTo
import java.net.InetAddress
import java.net.Socket
import okhttp3.Headers
import okhttp3.Headers.Companion.headersOf
import okhttp3.internal.EMPTY_HEADERS
import okio.Buffer
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout

Expand Down
2 changes: 2 additions & 0 deletions okhttp-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
testImplementation(libs.junit)
testImplementation(libs.junit.ktx)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
testImplementation(projects.okhttpTls)
testImplementation(libs.androidx.test.runner)
testImplementation(libs.robolectric)
Expand All @@ -64,6 +65,7 @@ dependencies {

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 @@ -20,11 +20,16 @@ import android.content.Context
import android.net.ConnectivityManager
import android.os.Build
import androidx.test.platform.app.InstrumentationRegistry
import assertk.assertThat
import assertk.assertions.hasMessage
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEmpty
import assertk.assertions.isNull
import java.net.InetAddress
import java.net.UnknownHostException
import java.util.concurrent.CountDownLatch
import mockwebserver3.MockResponse
import mockwebserver3.MockWebServer
import mockwebserver3.junit4.MockWebServerRule
import okhttp3.AsyncDns
import okhttp3.HttpUrl.Companion.toHttpUrl
Expand All @@ -33,9 +38,7 @@ import okhttp3.Request
import okhttp3.tls.HandshakeCertificates
import okhttp3.tls.HeldCertificate
import okio.IOException
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.fail
import org.junit.Assume
import org.junit.Assume.assumeTrue
import org.junit.AssumptionViolatedException
import org.junit.Before
Expand Down Expand Up @@ -115,7 +118,7 @@ class AndroidAsyncDnsTest {
val (allAddresses, exception) = dnsQuery("localhost")

assertThat(exception).isNull()
assertThat(allAddresses).isNotEmpty
assertThat(allAddresses).isNotEmpty()
}

private fun dnsQuery(hostname: String): Pair<List<InetAddress>, Exception?> {
Expand Down Expand Up @@ -148,7 +151,7 @@ class AndroidAsyncDnsTest {
val (allAddresses, exception) = dnsQuery("google.com")

assertThat(exception).isNull()
assertThat(allAddresses).isNotEmpty
assertThat(allAddresses).isNotEmpty()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@ package okhttp3.android
import android.app.Application
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import okhttp3.CacheControl
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isNotNull
import assertk.assertions.isNull
import java.net.InetAddress
import java.net.UnknownHostException
import okhttp3.Cache
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import org.assertj.core.api.Assertions.assertThat
import okio.Path.Companion.toPath
import okio.fakefilesystem.FakeFileSystem
import org.junit.AssumptionViolatedException
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import java.net.InetAddress
import java.net.UnknownHostException
import okhttp3.Cache
import okio.Path.Companion.toPath
import okio.fakefilesystem.FakeFileSystem

@RunWith(RobolectricTestRunner::class)
@Config(
Expand Down
1 change: 1 addition & 0 deletions okhttp-brotli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
testImplementation(libs.conscrypt.openjdk)
testImplementation(libs.junit)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk)
}

mavenPublishing {
Expand Down
Loading

0 comments on commit 8f5d304

Please sign in to comment.