com.github.mictaege.arete_gradle.JUnitExt.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of arete-gradle Show documentation
Show all versions of arete-gradle Show documentation
Gradle reporting plugin for the Arete JUnit5 testing framework.
The newest version!
package com.github.mictaege.arete_gradle
import org.junit.platform.engine.support.descriptor.ClassSource
import org.junit.platform.engine.support.descriptor.MethodSource
import org.junit.platform.launcher.TestIdentifier
import java.lang.reflect.Method
fun TestIdentifier.testClass(): Class<*>? {
return when (val source = this.source.orElse(null)) {
is ClassSource -> source.javaClass
is MethodSource -> source.javaClass
else -> null
}
}
fun TestIdentifier.testMethod(): Method? {
return when (val source = this.source.orElse(null)) {
is MethodSource -> source.javaMethod
else -> null
}
}
fun TestIdentifier.isAnnotated(annotation: Class): Boolean {
return when (val source = this.source.orElse(null)) {
is ClassSource -> source.javaClass.isAnnotationPresent(annotation)
is MethodSource -> source.javaMethod.isAnnotationPresent(annotation)
else -> false
}
}
fun TestIdentifier.getAnnotation(annotation: Class): A? {
return when (val source = this.source.orElse(null)) {
is ClassSource -> source.javaClass.getAnnotation(annotation)
is MethodSource -> source.javaMethod.getAnnotation(annotation)
else -> null
}
}