Skip to content

Commit

Permalink
Switch from truth to assertk
Browse files Browse the repository at this point in the history
  • Loading branch information
ansman committed Apr 12, 2023
1 parent 4e33bdf commit ede0f88
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 95 deletions.
4 changes: 3 additions & 1 deletion api/src/test/kotlin/se/ansman/kotshi/TestKotshiUtils.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package se.ansman.kotshi

import com.google.common.truth.Truth.assertThat
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEqualTo
import com.squareup.moshi.JsonQualifier
import org.junit.Test
import se.ansman.kotshi.KotshiUtils.createJsonQualifierImplementation
Expand Down
2 changes: 1 addition & 1 deletion gradle-plugin/src/main/kotlin/library.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ tasks.withType<Javadoc> { enabled = false }

dependencies {
testImplementation(libs.junit)
testImplementation(libs.truth)
testImplementation(libs.assertk)
testImplementation(libs.kotlin.test.junit)
}
2 changes: 2 additions & 0 deletions gradle-plugin/src/main/kotlin/test-library.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sourceSets {
}

tasks.withType<Test>().configureEach {
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1)
jvmArgs(
"--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
Expand All @@ -28,6 +29,7 @@ tasks.withType<Test>().configureEach {
"--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
)
}

dependencies {
implementation(project(":api"))
Expand Down
2 changes: 1 addition & 1 deletion libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlin
kotlinx-metadata = "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0"

junit = "junit:junit:4.12"
truth = "com.google.truth:truth:1.1.3"
assertk = "com.willowtreeapps.assertk:assertk-jvm:0.25"

compileTesting-core = { module = "com.github.tschuchortdev:kotlin-compile-testing", version.ref = "compileTesting" }
compileTesting-ksp = { module = "com.github.tschuchortdev:kotlin-compile-testing-ksp", version.ref = "compileTesting" }
Expand Down
157 changes: 82 additions & 75 deletions tests/src/test/kotlin/se/ansman/kotshi/BaseGeneratorTest.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package se.ansman.kotshi

import com.google.common.truth.Truth.assertThat
import assertk.assertThat
import assertk.assertions.isDataClassEqualTo
import assertk.assertions.isNotNull
import com.squareup.moshi.Moshi
import org.junit.Test

Expand All @@ -13,6 +15,7 @@ class ClassWithManyPropertiesTest {
@Test
fun canReadJson() {
assertThat(adapter.fromJson("{}"))
.isEqualTo(ClassWithManyProperties())
.isNotNull()
.isDataClassEqualTo(ClassWithManyProperties())
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package se.ansman.kotshi

import com.google.common.truth.Truth.assertThat
import assertk.assertThat
import assertk.assertions.isEqualTo
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package se.ansman.kotshi

import com.google.common.truth.Truth.assertThat
import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isInstanceOf
import assertk.assertions.isNotInstanceOf
import assertk.assertions.isSameAs
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapter
import org.junit.Test
Expand All @@ -18,7 +22,7 @@ class ManuallyRegisteredAdapterTest {
@Test
fun testRegistersRegularAdapter() {
assertThat(moshi.adapter(ManuallyRegisteredAdapter.Type::class.java))
.isSameInstanceAs(ManuallyRegisteredAdapter)
.isSameAs(ManuallyRegisteredAdapter)
}

@OptIn(ExperimentalStdlibApi::class)
Expand Down Expand Up @@ -61,7 +65,6 @@ class ManuallyRegisteredAdapterTest {
assertIs<ManuallyRegisteredGenericAdapter<*>>(adapter)
assertSame(moshi, adapter.moshi)
assertThat(adapter.types)
.asList()
.containsExactly(Int::class.javaObjectType)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package se.ansman.kotshi

import com.google.common.truth.Truth.assertThat
import assertk.assertThat
import assertk.assertions.isEqualTo
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package se.ansman.kotshi

import com.google.common.truth.Truth.assertThat
import assertk.assertThat
import assertk.assertions.isEqualTo
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package se.ansman.kotshi

import com.google.common.truth.Truth.assertThat
import assertk.all
import assertk.assertThat
import assertk.assertions.isInstanceOf
import com.squareup.moshi.Moshi
import org.junit.Test
import se.ansman.kotshi.assertions.isEmpty
import kotlin.test.assertEquals

class TestClassWithQualifierWithEmptyArrays {
Expand All @@ -21,23 +24,23 @@ class TestClassWithQualifierWithEmptyArrays {
val annotation = annotations.single() as QualifierWithArrays
assertThat(annotation.booleanArrayArg).isEmpty()
assertThat(annotation.byteArrayArg).isEmpty()
assertThat(annotation.ubyteArrayArg).apply {
assertThat(annotation.ubyteArrayArg).all {
isInstanceOf(UByteArray::class.java)
isEmpty()
}
assertThat(annotation.charArrayArg).isEmpty()
assertThat(annotation.shortArrayArg).isEmpty()
assertThat(annotation.ushortArrayArg).apply {
assertThat(annotation.ushortArrayArg).all {
isInstanceOf(UShortArray::class.java)
isEmpty()
}
assertThat(annotation.intArrayArg).isEmpty()
assertThat(annotation.uintArrayArg).apply {
assertThat(annotation.uintArrayArg).all {
isInstanceOf(UIntArray::class.java)
isEmpty()
}
assertThat(annotation.longArrayArg).isEmpty()
assertThat(annotation.ulongArrayArg).apply {
assertThat(annotation.ulongArrayArg).all {
isInstanceOf(ULongArray::class.java)
isEmpty()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package se.ansman.kotshi

import com.google.common.truth.Truth.assertThat
import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isEqualTo
import com.squareup.moshi.Moshi
import org.junit.Test
import kotlin.test.assertEquals
Expand All @@ -18,21 +20,21 @@ class TestQualifiersWithDefaults {
String::class.java -> {
++callCount
val annotation = annotations.single() as QualifierWithDefaults
assertThat(annotation.vararg).isEqualTo(arrayOf("vararg"))
assertThat(annotation.vararg).containsExactly("vararg")
assertThat(annotation.string).isEqualTo("Hello")
moshi.adapter(String::class.java)
}
Int::class.javaObjectType -> {
++callCount
val annotation = annotations.single() as QualifierWithDefaults
assertThat(annotation.vararg).isEqualTo(arrayOf("not", "default"))
assertThat(annotation.vararg).containsExactly("not", "default")
assertThat(annotation.string).isEqualTo("Hello")
moshi.adapter(Int::class.java)
}
Boolean::class.javaObjectType -> {
++callCount
val annotation = annotations.single() as QualifierWithDefaults
assertThat(annotation.vararg).isEqualTo(arrayOf("vararg"))
assertThat(annotation.vararg).containsExactly("vararg")
assertThat(annotation.string).isEqualTo("not default")
moshi.adapter(Boolean::class.java)
}
Expand Down
72 changes: 72 additions & 0 deletions tests/src/test/kotlin/se/ansman/kotshi/assertions/arrays.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@file:OptIn(ExperimentalUnsignedTypes::class)

package se.ansman.kotshi.assertions

import assertk.Assert
import assertk.assertions.isTrue
import assertk.assertions.prop

@JvmName("isBooleanArrayEmpty")
fun Assert<BooleanArray>.isEmpty() {
prop(BooleanArray::isEmpty).isTrue()
}

@JvmName("isByteArrayEmpty")
fun Assert<ByteArray>.isEmpty() {
prop(ByteArray::isEmpty).isTrue()
}

@JvmName("isUByteArrayEmpty")
fun Assert<UByteArray>.isEmpty() {
prop(UByteArray::isEmpty).isTrue()
}

@JvmName("isCharArrayEmpty")
fun Assert<CharArray>.isEmpty() {
prop(CharArray::isEmpty).isTrue()
}

@JvmName("isShortArrayEmpty")
fun Assert<ShortArray>.isEmpty() {
prop(ShortArray::isEmpty).isTrue()
}

@JvmName("isUShortArrayEmpty")
fun Assert<UShortArray>.isEmpty() {
prop(UShortArray::isEmpty).isTrue()
}

@JvmName("isIntArrayEmpty")
fun Assert<IntArray>.isEmpty() {
prop(IntArray::isEmpty).isTrue()
}

@JvmName("isUIntArrayEmpty")
fun Assert<UIntArray>.isEmpty() {
prop(UIntArray::isEmpty).isTrue()
}

@JvmName("isLongArrayEmpty")
fun Assert<LongArray>.isEmpty() {
prop(LongArray::isEmpty).isTrue()
}

@JvmName("isULongArrayEmpty")
fun Assert<ULongArray>.isEmpty() {
prop(ULongArray::isEmpty).isTrue()
}

@JvmName("isFloatArrayEmpty")
fun Assert<FloatArray>.isEmpty() {
prop(FloatArray::isEmpty).isTrue()
}

@JvmName("isDoubleArrayEmpty")
fun Assert<DoubleArray>.isEmpty() {
prop(DoubleArray::isEmpty).isTrue()
}

@JvmName("isArrayEmpty")
fun Assert<Array<*>>.isEmpty() {
prop(Array<*>::isEmpty).isTrue()
}
16 changes: 16 additions & 0 deletions tests/src/test/kotlin/se/ansman/kotshi/assertions/classes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package se.ansman.kotshi.assertions

import assertk.Assert
import assertk.assertions.support.expected

inline fun <reified T : Any> Assert<Class<*>>.isAssignableTo() {
isAssignableTo(T::class.java)
}

fun Assert<Class<*>>.isAssignableTo(other: Class<*>) {
given {
if (!other.isAssignableFrom(it)) {
expected("$it to be assignable to $other")
}
}
}

0 comments on commit ede0f88

Please sign in to comment.