Skip to content

Commit

Permalink
Migrate from AssertJ to AssertK in kotlin files.
Browse files Browse the repository at this point in the history
  • Loading branch information
oldergod committed Nov 15, 2024
1 parent db02978 commit 174e8cc
Show file tree
Hide file tree
Showing 83 changed files with 462 additions and 238 deletions.
2 changes: 1 addition & 1 deletion samples/wire-codegen-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ dependencies {
implementation(libs.guava)
implementation(libs.javapoet)
testImplementation(libs.junit)
testImplementation(libs.assertj)
testImplementation(libs.assertk)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.squareup.wire.sample

import assertk.assertThat
import assertk.assertions.isEqualTo
import com.palantir.javapoet.JavaFile
import com.palantir.javapoet.TypeSpec
import com.squareup.wire.java.JavaGenerator
Expand All @@ -26,7 +28,6 @@ import java.io.IOException
import java.nio.file.FileSystems
import okio.buffer
import okio.sink
import org.assertj.core.api.Assertions.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
Expand Down
2 changes: 1 addition & 1 deletion wire-compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
implementation(libs.kotlin.serialization)
implementation(libs.kaml)
testImplementation(libs.junit)
testImplementation(libs.assertj)
testImplementation(libs.assertk)
testImplementation(libs.kotlin.test.junit)
testImplementation(projects.wireTestUtils)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
*/
package com.squareup.wire

import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.containsOnly
import assertk.assertions.hasMessage
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import com.squareup.wire.schema.WireRun
import java.io.File
import java.io.FileOutputStream
import java.io.PrintWriter
import kotlin.test.assertFailsWith
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test

class CommandLineOptionsTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/
package com.squareup.wire

import org.assertj.core.api.Assertions.assertThat
import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.containsExactlyInAnyOrder
import assertk.assertions.messageContains
import org.junit.Assert.fail
import org.junit.Test

Expand Down Expand Up @@ -56,7 +59,7 @@ class ManifestParseTest {
parseManifestModules(yaml)
fail()
} catch (e: Exception) {
assertThat(e).hasMessageContaining("Unknown property 'includes'")
assertThat(e).messageContains("Unknown property 'includes'")
}
}

Expand All @@ -69,7 +72,7 @@ class ManifestParseTest {
""".trimMargin()

val modules = parseManifestModules(yaml)
assertThat(modules.keys).containsExactly("one", "two")
assertThat(modules.getValue("one").dependencies).containsExactly("two")
assertThat(modules.keys.toList()).containsExactly("one", "two")
assertThat(modules.getValue("one").dependencies.toList()).containsExactly("two")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
*/
package com.squareup.wire

import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.doesNotContain
import assertk.assertions.hasMessage
import com.squareup.wire.schema.SchemaException
import kotlin.test.assertFailsWith
import okio.Path
import okio.Path.Companion.toPath
import okio.fakefilesystem.FakeFileSystem
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test

class WireCompilerErrorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@

package com.squareup.wire

import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEmpty
import com.squareup.wire.schema.ProtoType
import java.util.Collections
import okio.FileSystem
import okio.Path
import okio.Path.Companion.toOkioPath
import okio.Path.Companion.toPath
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -827,7 +830,7 @@ class WireCompilerTest {
private fun assertOutputs(target: TargetLanguage, outputs: Array<String>, suffix: String = "") {
val filesAfter = paths
assertThat(filesAfter.size)
.overridingErrorMessage(filesAfter.toString())
// .overridingErrorMessage(filesAfter.toString())
.isEqualTo(outputs.size)

for (output in outputs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

package com.squareup.wire.schema

import assertk.assertThat
import assertk.assertions.hasMessage
import com.squareup.wire.testing.add
import kotlin.test.assertFailsWith
import okio.Path
import okio.fakefilesystem.FakeFileSystem
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test

class CycleCheckerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@

package com.squareup.wire.schema

import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isEqualTo
import assertk.assertions.isNotNull
import assertk.assertions.isNull
import assertk.assertions.messageContains
import com.squareup.wire.testing.add
import kotlin.test.assertFailsWith
import okio.ForwardingFileSystem
import okio.Path
import okio.Path.Companion.toPath
import okio.fakefilesystem.FakeFileSystem
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test

class LinkerTest {
Expand Down Expand Up @@ -144,7 +149,7 @@ class LinkerTest {
val exception = assertFailsWith<SchemaException> {
loadAndLinkSchema(opaqueTypes = listOf(ProtoType.get("cafe.Roast")))
}
assertThat(exception).hasMessageContaining(
assertThat(exception).messageContains(
"""
|Enums like cafe.Roast cannot be opaqued
| for field roast (source-path/cafe/cafe.proto:11:3)
Expand Down Expand Up @@ -297,7 +302,7 @@ class LinkerTest {
val exception = assertFailsWith<SchemaException> {
loadAndLinkSchema(opaqueTypes = listOf(ProtoType.INT32))
}
assertThat(exception).hasMessageContaining(
assertThat(exception).messageContains(
"""
|Scalar types like int32 cannot be opaqued
| for field size_ounces (source-path/cafe/cafe.proto:6:3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

package com.squareup.wire.schema

import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isNotNull
import com.squareup.wire.testing.add
import okio.Path
import okio.Path.Companion.toPath
import okio.fakefilesystem.FakeFileSystem
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test

class OptionsLinkingTest {
Expand Down
37 changes: 24 additions & 13 deletions wire-compiler/src/test/java/com/squareup/wire/schema/WireRunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
*/
package com.squareup.wire.schema

import assertk.all
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.doesNotContain
import assertk.assertions.hasMessage
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEmpty
import com.squareup.wire.StringWireLogger
import com.squareup.wire.WireLogger
import com.squareup.wire.WireLogger.Companion.NONE
Expand All @@ -30,7 +38,6 @@ import kotlin.test.assertFailsWith
import okio.Path
import okio.Path.Companion.toPath
import okio.fakefilesystem.FakeFileSystem
import org.assertj.core.api.Assertions.assertThat
import org.junit.Assert.fail
import org.junit.Test

Expand Down Expand Up @@ -145,12 +152,13 @@ class WireRunTest {
assertThat(fs.findFiles("generated")).containsExactlyInAnyOrderAsRelativePaths(
"generated/kt/squareup/routes/RouteBlockingServer.kt",
)
assertThat(fs.readUtf8("generated/kt/squareup/routes/RouteBlockingServer.kt"))
.contains(
assertThat(fs.readUtf8("generated/kt/squareup/routes/RouteBlockingServer.kt")).all {
contains(
"interface RouteBlockingServer : Service",
"fun GetUpdatedRed",
)
.doesNotContain("suspend fun GetUpdatedRed")
doesNotContain("suspend fun GetUpdatedRed")
}
}

@Test
Expand Down Expand Up @@ -182,16 +190,18 @@ class WireRunTest {
.contains("interface RouteGetUpdatedBlueClient : Service")
assertThat(fs.readUtf8("generated/kt/squareup/routes/RouteGetUpdatedRedClient.kt"))
.contains("interface RouteGetUpdatedRedClient : Service")
assertThat(fs.readUtf8("generated/kt/squareup/routes/GrpcRouteGetUpdatedBlueClient.kt"))
.contains(
assertThat(fs.readUtf8("generated/kt/squareup/routes/GrpcRouteGetUpdatedBlueClient.kt")).all {
contains(
"class GrpcRouteGetUpdatedBlueClient(\n private val client: GrpcClient,\n) : RouteGetUpdatedBlueClient",
)
.doesNotContain("RouteGetUpdatedRedClient")
assertThat(fs.readUtf8("generated/kt/squareup/routes/GrpcRouteGetUpdatedRedClient.kt"))
.contains(
doesNotContain("RouteGetUpdatedRedClient")
}
assertThat(fs.readUtf8("generated/kt/squareup/routes/GrpcRouteGetUpdatedRedClient.kt")).all {
contains(
"class GrpcRouteGetUpdatedRedClient(\n private val client: GrpcClient,\n) : RouteGetUpdatedRedClient",
)
.doesNotContain("RouteGetUpdatedBlueClient")
doesNotContain("RouteGetUpdatedBlueClient")
}
}

@Test
Expand Down Expand Up @@ -290,10 +300,11 @@ class WireRunTest {
assertThat(fs.findFiles("generated")).containsExactlyInAnyOrderAsRelativePaths(
"generated/kt/squareup/colors/Blue.kt",
)
assertThat(fs.readUtf8("generated/kt/squareup/colors/Blue.kt"))
.contains("class Blue")
assertThat(fs.readUtf8("generated/kt/squareup/colors/Blue.kt")).all {
contains("class Blue")
// The type `Triangle` has been opaqued.
.contains("public val triangle: ByteString? = null")
contains("public val triangle: ByteString? = null")
}
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion wire-gradle-plugin-playground/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dependencies {
implementation(projects.wireSchema)
implementation(projects.wireGsonSupport)
implementation(projects.wireMoshiAdapter)
implementation(libs.assertj)
implementation(libs.assertk)
implementation(libs.junit)
implementation(libs.protobuf.javaUtil)
implementation(projects.wireTestUtils)
Expand Down
2 changes: 1 addition & 1 deletion wire-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies {
implementation(libs.pluginz.kotlin)

testImplementation(libs.junit)
testImplementation(libs.assertj)
testImplementation(libs.assertk)
testImplementation(projects.wireTestUtils)
}

Expand Down
Loading

0 comments on commit 174e8cc

Please sign in to comment.