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

com.bybutter.sisyphus.test.SisyphusTestEngine.kt Maven / Gradle / Ivy

There is a newer version: 2.1.22
Show newest version
package com.bybutter.sisyphus.test

import com.bybutter.sisyphus.spi.ServiceLoader
import com.bybutter.sisyphus.test.descriptor.SisyphusTestDescriptor
import com.bybutter.sisyphus.test.discovery.SisyphusTestSelectorResolver
import com.bybutter.sisyphus.test.extension.Extension
import com.bybutter.sisyphus.test.extension.SelectorResolver
import org.junit.platform.engine.EngineDiscoveryRequest
import org.junit.platform.engine.ExecutionRequest
import org.junit.platform.engine.TestDescriptor
import org.junit.platform.engine.UniqueId
import org.junit.platform.engine.discovery.DiscoverySelectors
import org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver
import org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder
import java.util.Optional

class SisyphusTestEngine : HierarchicalTestEngine() {
    override fun getId(): String {
        return "sisyphus-junit"
    }

    override fun getGroupId(): Optional {
        return Optional.of("com.bybutter.sisyphus")
    }

    override fun getArtifactId(): Optional {
        return Optional.of("sisyphus-test")
    }

    private val extensions = ServiceLoader.load(Extension::class.java)

    override fun discover(discoveryRequest: EngineDiscoveryRequest, uniqueId: UniqueId): TestDescriptor {
        val resolver = EngineDiscoveryRequestResolver.builder()
            .addSelectorResolver(SisyphusTestSelectorResolver())
            .apply {
                extensions.filterIsInstance().forEach {
                    addSelectorResolver(it)
                }
            }
            .build()
        val defaultRequest = LauncherDiscoveryRequestBuilder.request()
            .selectors(DiscoverySelectors.selectPackage("META-INF.sisyphus"))
            .build()

        return SisyphusTestDescriptor(uniqueId).apply {
            resolver.resolve(defaultRequest, this)
            resolver.resolve(discoveryRequest, this)
        }
    }

    override fun createExecutionContext(request: ExecutionRequest): SisyphusTestEngineContext {
        return SisyphusTestRootContext(extensions)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy