mirror of https://github.com/usbharu/Hideout.git
test: Equalsのテストを修正
This commit is contained in:
parent
ec848630ca
commit
e8b6b6784c
|
@ -8,21 +8,77 @@ import nl.jqno.equalsverifier.Warning
|
||||||
import nl.jqno.equalsverifier.internal.reflection.PackageScanner
|
import nl.jqno.equalsverifier.internal.reflection.PackageScanner
|
||||||
import org.junit.jupiter.api.DynamicTest
|
import org.junit.jupiter.api.DynamicTest
|
||||||
import org.junit.jupiter.api.DynamicTest.dynamicTest
|
import org.junit.jupiter.api.DynamicTest.dynamicTest
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
import org.junit.jupiter.api.TestFactory
|
import org.junit.jupiter.api.TestFactory
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
import org.springframework.stereotype.Controller
|
||||||
|
import org.springframework.stereotype.Repository
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import java.lang.reflect.Modifier
|
import java.lang.reflect.Modifier
|
||||||
import kotlin.test.assertFails
|
|
||||||
|
|
||||||
class EqualsAndToStringTest {
|
class EqualsAndToStringTest {
|
||||||
@Test
|
@TestFactory
|
||||||
fun equalsTest() {
|
fun equalsTest(): List<DynamicTest> {
|
||||||
assertFails {
|
|
||||||
EqualsVerifier
|
val classes = PackageScanner.getClassesIn("dev.usbharu.hideout", null, true)
|
||||||
.simple()
|
|
||||||
.suppress(Warning.INHERITED_DIRECTLY_FROM_OBJECT)
|
return classes
|
||||||
.forPackage("dev.usbharu.hideout", true)
|
.asSequence()
|
||||||
.verify()
|
.filter {
|
||||||
}
|
it.getAnnotation(Service::class.java) == null
|
||||||
|
}
|
||||||
|
.filter {
|
||||||
|
it.getAnnotation(Repository::class.java) == null
|
||||||
|
}
|
||||||
|
.filter {
|
||||||
|
it.getAnnotation(Component::class.java) == null
|
||||||
|
}
|
||||||
|
.filter {
|
||||||
|
it.getAnnotation(Controller::class.java) == null
|
||||||
|
}
|
||||||
|
.filter {
|
||||||
|
it.getAnnotation(RestController::class.java) == null
|
||||||
|
}
|
||||||
|
.filter {
|
||||||
|
it.getAnnotation(Configuration::class.java) == null
|
||||||
|
}
|
||||||
|
.filterNot {
|
||||||
|
it.packageName.startsWith("dev.usbharu.hideout.domain.mastodon.model.generated")
|
||||||
|
}
|
||||||
|
.filterNot {
|
||||||
|
Throwable::class.java.isAssignableFrom(it)
|
||||||
|
}
|
||||||
|
.filterNot {
|
||||||
|
Modifier.isAbstract(it.modifiers)
|
||||||
|
}
|
||||||
|
.filter {
|
||||||
|
try {
|
||||||
|
it.kotlin.objectInstance == null
|
||||||
|
} catch (_: Exception) {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
.filter {
|
||||||
|
it.superclass == Any::class.java || it.superclass?.packageName?.startsWith("dev.usbharu") ?: true
|
||||||
|
}
|
||||||
|
.map {
|
||||||
|
dynamicTest(it.name) {
|
||||||
|
if (it.isKotlinClass()) {
|
||||||
|
println(" at ${it.name}.toString(${it.simpleName}.kt:1)")
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
EqualsVerifier.simple()
|
||||||
|
.suppress(Warning.INHERITED_DIRECTLY_FROM_OBJECT, Warning.TRANSIENT_FIELDS)
|
||||||
|
.forClass(it)
|
||||||
|
.verify()
|
||||||
|
} catch (e: AssertionError) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestFactory
|
@TestFactory
|
||||||
|
|
Loading…
Reference in New Issue