All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmTest.com.bkahlert.kommons.test.junit.MethodNameOnlyDisplayNameGeneratorTest.kt Maven / Gradle / Ivy

There is a newer version: 2.8.0
Show newest version
package com.bkahlert.kommons.test.junit

import com.bkahlert.kommons.test.test
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.DisplayNameGenerator
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInfo
import kotlin.reflect.jvm.javaMethod

class MethodNameOnlyDisplayNameGeneratorTest {

    private val generator = MethodNameOnlyDisplayNameGenerator()
    private val standardGenerator = DisplayNameGenerator.Standard()

    @Test fun generate_display_name_for_class() = test {
        generator.generateDisplayNameForClass(OuterClass::class.java)
            .shouldBe(standardGenerator.generateDisplayNameForClass(OuterClass::class.java))
    }

    @Test fun generate_display_name_for_nested_class() = test {
        generator.generateDisplayNameForNestedClass(OuterClass.NestedClass::class.java)
            .shouldBe(standardGenerator.generateDisplayNameForNestedClass(OuterClass.NestedClass::class.java))
    }

    @Test fun generate_display_name_for_method() = test {
        generator.generateDisplayNameForMethod(
            OuterClass::class.java,
            checkNotNull(OuterClass::method.javaMethod),
        ).shouldBe("method")
        generator.generateDisplayNameForMethod(
            OuterClass::class.java,
            checkNotNull(OuterClass::methodWithParameters.javaMethod),
        ).shouldBe("methodWithParameters")
        generator.generateDisplayNameForMethod(
            OuterClass.NestedClass::class.java,
            checkNotNull(OuterClass.NestedClass::method.javaMethod),
        ).shouldBe("method")
        generator.generateDisplayNameForMethod(
            OuterClass.NestedClass::class.java,
            checkNotNull(OuterClass.NestedClass::methodWithParameters.javaMethod),
        ).shouldBe("methodWithParameters")
    }
}

private class OuterClass {

    inner class NestedClass {
        @Test fun method() = Unit
        @Test fun methodWithParameters(@Suppress("UNUSED_PARAMETER") baz: TestInfo) = Unit
    }

    @Test fun method() = Unit
    @Test fun methodWithParameters(@Suppress("UNUSED_PARAMETER") baz: TestInfo) = Unit
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy