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 org.junit.jupiter.api.DynamicTest
|
||||
import org.junit.jupiter.api.DynamicTest.dynamicTest
|
||||
import org.junit.jupiter.api.Test
|
||||
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 kotlin.test.assertFails
|
||||
|
||||
class EqualsAndToStringTest {
|
||||
@Test
|
||||
fun equalsTest() {
|
||||
assertFails {
|
||||
EqualsVerifier
|
||||
.simple()
|
||||
.suppress(Warning.INHERITED_DIRECTLY_FROM_OBJECT)
|
||||
.forPackage("dev.usbharu.hideout", true)
|
||||
.verify()
|
||||
@TestFactory
|
||||
fun equalsTest(): List<DynamicTest> {
|
||||
|
||||
val classes = PackageScanner.getClassesIn("dev.usbharu.hideout", null, true)
|
||||
|
||||
return classes
|
||||
.asSequence()
|
||||
.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
|
||||
|
|
Loading…
Reference in New Issue