From 66fb3c3c933a1614e6f8dcf8b905fb2d36fa0f98 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 8 Nov 2023 16:48:28 +0900 Subject: [PATCH] =?UTF-8?q?test:=20equals=E3=81=A8tostring=E3=81=A7?= =?UTF-8?q?=E3=82=AB=E3=83=90=E3=83=AC=E3=83=83=E3=82=B8=E8=A8=88=E6=B8=AC?= =?UTF-8?q?=E6=99=82=E3=81=AB=E7=84=A1=E8=A6=96=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AA=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0(=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E7=9B=AE=E7=9A=84=E3=81=A8=E3=81=97=E3=81=A6=E3=81=84=E3=81=AA?= =?UTF-8?q?=E3=81=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 8 +++- .../usbharu/hideout/EqualsAndToStringTest.kt | 42 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/test/kotlin/dev/usbharu/hideout/EqualsAndToStringTest.kt diff --git a/build.gradle.kts b/build.gradle.kts index 1c96989a..b72caa33 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -32,6 +32,11 @@ tasks.withType { val cpus = Runtime.getRuntime().availableProcessors() maxParallelForks = max(1, cpus - 1) setForkEvery(4) + doFirst { + jvmArgs = arrayOf( + "--add-opens", "java.base/java.lang=ALL-UNNAMED" + ).toMutableList() + } } tasks.withType>().configureEach { @@ -160,7 +165,8 @@ dependencies { testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") testImplementation("org.mockito:mockito-inline:5.2.0") - + testImplementation("nl.jqno.equalsverifier:equalsverifier:3.15.3") + testImplementation("com.jparams:to-string-verifier:1.4.8") implementation("org.drewcarlson:kjob-core:0.6.0") implementation("org.drewcarlson:kjob-mongo:0.6.0") diff --git a/src/test/kotlin/dev/usbharu/hideout/EqualsAndToStringTest.kt b/src/test/kotlin/dev/usbharu/hideout/EqualsAndToStringTest.kt new file mode 100644 index 00000000..62f68093 --- /dev/null +++ b/src/test/kotlin/dev/usbharu/hideout/EqualsAndToStringTest.kt @@ -0,0 +1,42 @@ +package dev.usbharu.hideout + +import com.jparams.verifier.tostring.ToStringVerifier +import nl.jqno.equalsverifier.EqualsVerifier +import nl.jqno.equalsverifier.Warning +import nl.jqno.equalsverifier.internal.reflection.PackageScanner +import org.junit.jupiter.api.Test +import java.lang.reflect.Modifier +import kotlin.test.assertFails + +class EqualsAndToStringTest { + @Test + fun equalsTest() { + assertFails { + EqualsVerifier + .simple() + .suppress(Warning.INHERITED_DIRECTLY_FROM_OBJECT) + .forPackage("dev.usbharu.hideout", true) + .verify() + } + } + + @Test + fun toStringTest() { + + PackageScanner.getClassesIn("dev.usbharu.hideout", null, true) + .filter { + it != null && !it.isEnum && !it.isInterface && !Modifier.isAbstract(it.modifiers) + } + .forEach { + try { + ToStringVerifier.forClass(it).verify() + } catch (e: AssertionError) { + println(it.name) + e.printStackTrace() + } catch (e: Exception) { + println(it.name) + e.printStackTrace() + } + } + } +}