From ede0f886cfe8bc4be24be2493ca2f3067b29eafb Mon Sep 17 00:00:00 2001 From: Nicklas Ansman Date: Tue, 11 Apr 2023 21:26:39 -0400 Subject: [PATCH] Switch from truth to assertk --- .../se/ansman/kotshi/TestKotshiUtils.kt | 4 +- .../src/main/kotlin/library.gradle.kts | 2 +- .../src/main/kotlin/test-library.gradle.kts | 2 + libs.versions.toml | 2 +- .../se/ansman/kotshi/BaseGeneratorTest.kt | 157 +++++++++--------- .../kotshi/ClassWithManyPropertiesTest.kt | 7 +- .../se/ansman/kotshi/IgnoredPropertiesTest.kt | 3 +- .../kotshi/ManuallyRegisteredAdapterTest.kt | 9 +- .../SealedClassWithComplexGenericTest.kt | 3 +- .../kotshi/SealedClassWithGenericTest.kt | 3 +- .../TestClassWithQualifierWithEmptyArrays.kt | 13 +- .../kotshi/TestQualifiersWithDefaults.kt | 10 +- .../se/ansman/kotshi/assertions/arrays.kt | 72 ++++++++ .../se/ansman/kotshi/assertions/classes.kt | 16 ++ 14 files changed, 208 insertions(+), 95 deletions(-) create mode 100644 tests/src/test/kotlin/se/ansman/kotshi/assertions/arrays.kt create mode 100644 tests/src/test/kotlin/se/ansman/kotshi/assertions/classes.kt diff --git a/api/src/test/kotlin/se/ansman/kotshi/TestKotshiUtils.kt b/api/src/test/kotlin/se/ansman/kotshi/TestKotshiUtils.kt index 041f4e9f..3b84c949 100644 --- a/api/src/test/kotlin/se/ansman/kotshi/TestKotshiUtils.kt +++ b/api/src/test/kotlin/se/ansman/kotshi/TestKotshiUtils.kt @@ -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 diff --git a/gradle-plugin/src/main/kotlin/library.gradle.kts b/gradle-plugin/src/main/kotlin/library.gradle.kts index 1a03118c..ad3f7f99 100644 --- a/gradle-plugin/src/main/kotlin/library.gradle.kts +++ b/gradle-plugin/src/main/kotlin/library.gradle.kts @@ -29,6 +29,6 @@ tasks.withType { enabled = false } dependencies { testImplementation(libs.junit) - testImplementation(libs.truth) + testImplementation(libs.assertk) testImplementation(libs.kotlin.test.junit) } \ No newline at end of file diff --git a/gradle-plugin/src/main/kotlin/test-library.gradle.kts b/gradle-plugin/src/main/kotlin/test-library.gradle.kts index 46233c88..2f222cb7 100644 --- a/gradle-plugin/src/main/kotlin/test-library.gradle.kts +++ b/gradle-plugin/src/main/kotlin/test-library.gradle.kts @@ -16,6 +16,7 @@ sourceSets { } tasks.withType().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", @@ -28,6 +29,7 @@ tasks.withType().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")) diff --git a/libs.versions.toml b/libs.versions.toml index e1805721..5a58f413 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -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" } diff --git a/tests/src/test/kotlin/se/ansman/kotshi/BaseGeneratorTest.kt b/tests/src/test/kotlin/se/ansman/kotshi/BaseGeneratorTest.kt index 9f9229ea..6229a55b 100644 --- a/tests/src/test/kotlin/se/ansman/kotshi/BaseGeneratorTest.kt +++ b/tests/src/test/kotlin/se/ansman/kotshi/BaseGeneratorTest.kt @@ -1,6 +1,9 @@ package se.ansman.kotshi -import com.google.common.truth.Truth.assertThat +import assertk.assertThat +import assertk.assertions.contains +import assertk.assertions.hasSize +import assertk.assertions.isEqualTo import com.squareup.moshi.JsonAdapter import com.tschuchort.compiletesting.KotlinCompilation import com.tschuchort.compiletesting.SourceFile @@ -22,8 +25,8 @@ import se.ansman.kotshi.Errors.privateDataClassConstructor import se.ansman.kotshi.Errors.privateDataClassProperty import se.ansman.kotshi.Errors.transientDataClassPropertyWithoutDefaultValue import se.ansman.kotshi.Errors.unsupportedSerializableType +import se.ansman.kotshi.assertions.isAssignableTo import java.io.File -import kotlin.test.assertEquals abstract class BaseGeneratorTest { @Rule @@ -39,8 +42,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.JsonSerializable private data class Foo(val property: String) """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(privateClass) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(privateClass) } @Test @@ -50,8 +53,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.JsonSerializable data class Foo private constructor(val property: String) """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(privateDataClassConstructor) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(privateDataClassConstructor) } @Test @@ -60,8 +63,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.JsonSerializable data class Foo(private val property: String) """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(privateDataClassProperty("property")) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(privateDataClassProperty("property")) } @Test @@ -70,8 +73,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.JsonSerializable data class Foo(@Transient val property: String) """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(transientDataClassPropertyWithoutDefaultValue("property")) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(transientDataClassPropertyWithoutDefaultValue("property")) } @Test @@ -80,8 +83,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.JsonSerializable data class Foo(@com.squareup.moshi.Json(ignore = true) val property: String) """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(ignoredDataClassPropertyWithoutDefaultValue("property")) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(ignoredDataClassPropertyWithoutDefaultValue("property")) } @Test @@ -90,8 +93,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.JsonSerializable data class Foo(@com.squareup.moshi.Json(ignore = false) @Transient val property: String) """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(nonIgnoredDataClassPropertyMustNotBeTransient("property")) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(nonIgnoredDataClassPropertyMustNotBeTransient("property")) } @Test @@ -104,8 +107,8 @@ abstract class BaseGeneratorTest { data class Implementation(val value: String) : SealedClass() } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.sealedClassMustBePolymorphic) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.sealedClassMustBePolymorphic) } @Test @@ -119,8 +122,8 @@ abstract class BaseGeneratorTest { data class Implementation(val value: T) : SealedClass() } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.sealedSubclassMustNotHaveGeneric("T")) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.sealedSubclassMustNotHaveGeneric("T")) } @Test @@ -134,8 +137,8 @@ abstract class BaseGeneratorTest { data class Implementation(val value: T) : SealedClass() } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.defaultSealedValueIsGeneric) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.defaultSealedValueIsGeneric) } @Test @@ -155,8 +158,8 @@ abstract class BaseGeneratorTest { object Default : SealedClass() } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.multipleJsonDefaultValueInSealedClass) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.multipleJsonDefaultValueInSealedClass) } @Test @@ -169,8 +172,8 @@ abstract class BaseGeneratorTest { data class Implementation(val value: String) : SealedClass() } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.polymorphicClassMustHaveJsonSerializable) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.polymorphicClassMustHaveJsonSerializable) } @Test @@ -180,8 +183,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.Polymorphic("type") sealed class SealedClass """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.noSealedSubclasses) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.noSealedSubclasses) } @Test @@ -194,8 +197,8 @@ abstract class BaseGeneratorTest { data class Implementation(val value: String) : SealedClass() } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.polymorphicSubclassMustHaveJsonSerializable) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.polymorphicSubclassMustHaveJsonSerializable) } @Test @@ -208,8 +211,8 @@ abstract class BaseGeneratorTest { data class Implementation(val value: String) : SealedClass() } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.polymorphicSubclassMustHavePolymorphicLabel) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.polymorphicSubclassMustHavePolymorphicLabel) } @Test @@ -220,8 +223,8 @@ abstract class BaseGeneratorTest { sealed inner class Inner(val value: String) } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.dataClassCannotBeInner) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.dataClassCannotBeInner) } @Test @@ -230,8 +233,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.JsonSerializable private object Singleton """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(privateClass) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(privateClass) } @Test @@ -245,8 +248,8 @@ abstract class BaseGeneratorTest { data class Implementation(val value: String) : SealedClass() } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(privateClass) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(privateClass) } @Test @@ -265,8 +268,8 @@ abstract class BaseGeneratorTest { } } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(jsonDefaultValueAppliedToInvalidType) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(jsonDefaultValueAppliedToInvalidType) } @Test @@ -283,8 +286,8 @@ abstract class BaseGeneratorTest { } } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(nestedSealedClassMustBePolymorphic) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(nestedSealedClassMustBePolymorphic) } @Test @@ -303,8 +306,8 @@ abstract class BaseGeneratorTest { } } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(nestedSealedClassHasPolymorphicLabel) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(nestedSealedClassHasPolymorphicLabel) } @Test @@ -322,8 +325,8 @@ abstract class BaseGeneratorTest { } } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(nestedSealedClassMissingPolymorphicLabel) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(nestedSealedClassMissingPolymorphicLabel) } @Test @@ -334,8 +337,8 @@ abstract class BaseGeneratorTest { Value1, } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(privateClass) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(privateClass) } @Test @@ -349,8 +352,8 @@ abstract class BaseGeneratorTest { Value2 } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(multipleJsonDefaultValueInEnum) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(multipleJsonDefaultValueInEnum) } @Test @@ -359,8 +362,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.JsonSerializable interface Interface """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(unsupportedSerializableType) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(unsupportedSerializableType) } @Test @@ -369,8 +372,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.JsonSerializable class JavaType {} """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(javaClassNotSupported) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(javaClassNotSupported) } @Test @@ -381,8 +384,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.KotshiJsonAdapterFactory object Factory2 : com.squareup.moshi.JsonAdapter.Factory """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.multipleFactories(listOf("Factory1", "Factory2"))) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.multipleFactories(listOf("Factory1", "Factory2"))) } @Test @@ -391,7 +394,7 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.KotshiJsonAdapterFactory abstract class Factory : com.squareup.moshi.JsonAdapter.Factory """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) val kotshiFactory = result.tryLoadClass("KotshiFactory") if (kotshiFactory != null) { assertThat(kotshiFactory).isAssignableTo(result.classLoader.loadClass("Factory")) @@ -404,21 +407,25 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.KotshiJsonAdapterFactory object Factory : com.squareup.moshi.JsonAdapter.Factory by KotshiFactory """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) val factory = result.tryLoadClass("KotshiFactory") if (factory != null) { - assertThat(factory).isAssignableTo(JsonAdapter.Factory::class.java) + assertThat(factory).isAssignableTo() } } @Test fun `factories can be interfaces`() { - val result = compile(kotlin("source.kt", """ + val result = compile( + kotlin( + "source.kt", """ @se.ansman.kotshi.KotshiJsonAdapterFactory interface Factory : com.squareup.moshi.JsonAdapter.Factory - """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) - assertThat(result.messages).contains(Errors.abstractFactoriesAreDeprecated) + """ + ) + ) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) + assertThat(result::messages).contains(Errors.abstractFactoriesAreDeprecated) val kotshiFactory = result.tryLoadClass("KotshiFactory") if (kotshiFactory != null) { assertThat(kotshiFactory).isAssignableTo(result.classLoader.loadClass("Factory")) @@ -431,8 +438,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.KotshiJsonAdapterFactory interface Factory extends com.squareup.moshi.JsonAdapter.Factory {} """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(javaClassNotSupported) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(javaClassNotSupported) } @Test @@ -441,8 +448,8 @@ abstract class BaseGeneratorTest { @se.ansman.kotshi.KotshiJsonAdapterFactory abstract class Adapter extends com.squareup.moshi.JsonAdapter {} """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(javaClassNotSupported) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(javaClassNotSupported) } @Test @@ -453,8 +460,8 @@ abstract class BaseGeneratorTest { object Type } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.invalidRegisterAdapterType) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.invalidRegisterAdapterType) } @Test @@ -467,8 +474,8 @@ abstract class BaseGeneratorTest { object Type } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.invalidRegisterAdapterVisibility) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.invalidRegisterAdapterVisibility) } @Test @@ -481,8 +488,8 @@ abstract class BaseGeneratorTest { object Type } """)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.registeredAdapterWithoutFactory) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.registeredAdapterWithoutFactory) } @Test @@ -511,7 +518,7 @@ abstract class BaseGeneratorTest { """) val annotationClass = "javax.annotation.Generated" val result = compile(generated, source, options = mapOf("kotshi.generatedAnnotation" to annotationClass)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) result.generatedFiles .plus(extraGeneratedFiles) .filter { it.name.endsWith(".kt") && "Kotshi" in it.name } @@ -535,7 +542,7 @@ abstract class BaseGeneratorTest { """) val annotationClass = "javax.annotation.processing.Generated" val result = compile(source, options = mapOf("kotshi.generatedAnnotation" to annotationClass)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) result.generatedFiles .plus(extraGeneratedFiles) .filter { it.name.endsWith(".kt") && "Kotshi" in it.name } @@ -558,8 +565,8 @@ abstract class BaseGeneratorTest { """) val annotationClass = "foo.bar.Generated" val result = compile(source, options = mapOf("kotshi.generatedAnnotation" to annotationClass)) - assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) - assertThat(result.messages).contains(Errors.invalidGeneratedAnnotation(annotationClass)) + assertThat(result::exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) + assertThat(result::messages).contains(Errors.invalidGeneratedAnnotation(annotationClass)) } protected fun compile(vararg sources: SourceFile, options: Map = emptyMap()) = diff --git a/tests/src/test/kotlin/se/ansman/kotshi/ClassWithManyPropertiesTest.kt b/tests/src/test/kotlin/se/ansman/kotshi/ClassWithManyPropertiesTest.kt index b285463a..0bd6f3b4 100644 --- a/tests/src/test/kotlin/se/ansman/kotshi/ClassWithManyPropertiesTest.kt +++ b/tests/src/test/kotlin/se/ansman/kotshi/ClassWithManyPropertiesTest.kt @@ -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 @@ -13,6 +15,7 @@ class ClassWithManyPropertiesTest { @Test fun canReadJson() { assertThat(adapter.fromJson("{}")) - .isEqualTo(ClassWithManyProperties()) + .isNotNull() + .isDataClassEqualTo(ClassWithManyProperties()) } } \ No newline at end of file diff --git a/tests/src/test/kotlin/se/ansman/kotshi/IgnoredPropertiesTest.kt b/tests/src/test/kotlin/se/ansman/kotshi/IgnoredPropertiesTest.kt index 0ceb142c..a830fa69 100644 --- a/tests/src/test/kotlin/se/ansman/kotshi/IgnoredPropertiesTest.kt +++ b/tests/src/test/kotlin/se/ansman/kotshi/IgnoredPropertiesTest.kt @@ -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 diff --git a/tests/src/test/kotlin/se/ansman/kotshi/ManuallyRegisteredAdapterTest.kt b/tests/src/test/kotlin/se/ansman/kotshi/ManuallyRegisteredAdapterTest.kt index ae69c78b..57da68cb 100644 --- a/tests/src/test/kotlin/se/ansman/kotshi/ManuallyRegisteredAdapterTest.kt +++ b/tests/src/test/kotlin/se/ansman/kotshi/ManuallyRegisteredAdapterTest.kt @@ -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 @@ -18,7 +22,7 @@ class ManuallyRegisteredAdapterTest { @Test fun testRegistersRegularAdapter() { assertThat(moshi.adapter(ManuallyRegisteredAdapter.Type::class.java)) - .isSameInstanceAs(ManuallyRegisteredAdapter) + .isSameAs(ManuallyRegisteredAdapter) } @OptIn(ExperimentalStdlibApi::class) @@ -61,7 +65,6 @@ class ManuallyRegisteredAdapterTest { assertIs>(adapter) assertSame(moshi, adapter.moshi) assertThat(adapter.types) - .asList() .containsExactly(Int::class.javaObjectType) } diff --git a/tests/src/test/kotlin/se/ansman/kotshi/SealedClassWithComplexGenericTest.kt b/tests/src/test/kotlin/se/ansman/kotshi/SealedClassWithComplexGenericTest.kt index 0eee902e..32d9fede 100644 --- a/tests/src/test/kotlin/se/ansman/kotshi/SealedClassWithComplexGenericTest.kt +++ b/tests/src/test/kotlin/se/ansman/kotshi/SealedClassWithComplexGenericTest.kt @@ -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 diff --git a/tests/src/test/kotlin/se/ansman/kotshi/SealedClassWithGenericTest.kt b/tests/src/test/kotlin/se/ansman/kotshi/SealedClassWithGenericTest.kt index 85a53439..28112ff5 100644 --- a/tests/src/test/kotlin/se/ansman/kotshi/SealedClassWithGenericTest.kt +++ b/tests/src/test/kotlin/se/ansman/kotshi/SealedClassWithGenericTest.kt @@ -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 diff --git a/tests/src/test/kotlin/se/ansman/kotshi/TestClassWithQualifierWithEmptyArrays.kt b/tests/src/test/kotlin/se/ansman/kotshi/TestClassWithQualifierWithEmptyArrays.kt index 3d2ccc48..852cf868 100644 --- a/tests/src/test/kotlin/se/ansman/kotshi/TestClassWithQualifierWithEmptyArrays.kt +++ b/tests/src/test/kotlin/se/ansman/kotshi/TestClassWithQualifierWithEmptyArrays.kt @@ -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 { @@ -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() } diff --git a/tests/src/test/kotlin/se/ansman/kotshi/TestQualifiersWithDefaults.kt b/tests/src/test/kotlin/se/ansman/kotshi/TestQualifiersWithDefaults.kt index e686bf29..7e2a16e2 100644 --- a/tests/src/test/kotlin/se/ansman/kotshi/TestQualifiersWithDefaults.kt +++ b/tests/src/test/kotlin/se/ansman/kotshi/TestQualifiersWithDefaults.kt @@ -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 @@ -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) } diff --git a/tests/src/test/kotlin/se/ansman/kotshi/assertions/arrays.kt b/tests/src/test/kotlin/se/ansman/kotshi/assertions/arrays.kt new file mode 100644 index 00000000..3d2cbb14 --- /dev/null +++ b/tests/src/test/kotlin/se/ansman/kotshi/assertions/arrays.kt @@ -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.isEmpty() { + prop(BooleanArray::isEmpty).isTrue() +} + +@JvmName("isByteArrayEmpty") +fun Assert.isEmpty() { + prop(ByteArray::isEmpty).isTrue() +} + +@JvmName("isUByteArrayEmpty") +fun Assert.isEmpty() { + prop(UByteArray::isEmpty).isTrue() +} + +@JvmName("isCharArrayEmpty") +fun Assert.isEmpty() { + prop(CharArray::isEmpty).isTrue() +} + +@JvmName("isShortArrayEmpty") +fun Assert.isEmpty() { + prop(ShortArray::isEmpty).isTrue() +} + +@JvmName("isUShortArrayEmpty") +fun Assert.isEmpty() { + prop(UShortArray::isEmpty).isTrue() +} + +@JvmName("isIntArrayEmpty") +fun Assert.isEmpty() { + prop(IntArray::isEmpty).isTrue() +} + +@JvmName("isUIntArrayEmpty") +fun Assert.isEmpty() { + prop(UIntArray::isEmpty).isTrue() +} + +@JvmName("isLongArrayEmpty") +fun Assert.isEmpty() { + prop(LongArray::isEmpty).isTrue() +} + +@JvmName("isULongArrayEmpty") +fun Assert.isEmpty() { + prop(ULongArray::isEmpty).isTrue() +} + +@JvmName("isFloatArrayEmpty") +fun Assert.isEmpty() { + prop(FloatArray::isEmpty).isTrue() +} + +@JvmName("isDoubleArrayEmpty") +fun Assert.isEmpty() { + prop(DoubleArray::isEmpty).isTrue() +} + +@JvmName("isArrayEmpty") +fun Assert>.isEmpty() { + prop(Array<*>::isEmpty).isTrue() +} \ No newline at end of file diff --git a/tests/src/test/kotlin/se/ansman/kotshi/assertions/classes.kt b/tests/src/test/kotlin/se/ansman/kotshi/assertions/classes.kt new file mode 100644 index 00000000..d4cd1766 --- /dev/null +++ b/tests/src/test/kotlin/se/ansman/kotshi/assertions/classes.kt @@ -0,0 +1,16 @@ +package se.ansman.kotshi.assertions + +import assertk.Assert +import assertk.assertions.support.expected + +inline fun Assert>.isAssignableTo() { + isAssignableTo(T::class.java) +} + +fun Assert>.isAssignableTo(other: Class<*>) { + given { + if (!other.isAssignableFrom(it)) { + expected("$it to be assignable to $other") + } + } +} \ No newline at end of file