diff --git a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/commons/LoggerUtils.kt b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/commons/LoggerUtils.kt index 9fd70df36..c5e8e8d2f 100644 --- a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/commons/LoggerUtils.kt +++ b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/commons/LoggerUtils.kt @@ -37,7 +37,7 @@ object LoggerUtils { System.getProperty(JAVA_UTIL_LOGGING_CONFIG_FILE_SYSTEM_PROPERTY) ?: return - val logger = getLogger(LoggerUtils::class.java) + val logger = createLogger() try { val propertiesFilePath = Paths.get(loggingPropertiesFilePathString) if (!propertiesFilePath.toFile().exists()) { @@ -59,4 +59,10 @@ object LoggerUtils { */ @JvmStatic fun getLogger(clazz: Class<*>) = Logger.getLogger(clazz.name) + + /** + * Creates a logger for the given class. + */ + @JvmStatic + fun Any.createLogger(): Logger = Logger.getLogger(this::class.java.name) } diff --git a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/executor/AvailableTests.kt b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/executor/AvailableTests.kt index 7bade2049..67e7d7a51 100644 --- a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/executor/AvailableTests.kt +++ b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/executor/AvailableTests.kt @@ -3,6 +3,7 @@ package com.teamscale.test_impacted.engine.executor import com.teamscale.client.ClusteredTestDetails import com.teamscale.client.PrioritizableTest import com.teamscale.client.StringUtils.levenshteinDistance +import com.teamscale.test_impacted.commons.LoggerUtils.createLogger import com.teamscale.test_impacted.commons.LoggerUtils.getLogger import org.junit.platform.engine.UniqueId import java.util.* @@ -13,6 +14,8 @@ import java.util.logging.Logger * by the Teamscale server to unique IDs used in JUnit Platform. */ class AvailableTests { + private val LOGGER = createLogger() + /** * A mapping from the tests uniform path (Teamscale internal representation) to unique id (JUnit internal * representation). @@ -43,8 +46,4 @@ class AvailableTests { } return Optional.ofNullable(clusterUniqueId) } - - companion object { - private val LOGGER: Logger = getLogger(AvailableTests::class.java) - } } diff --git a/impacted-test-engine/src/main/java/com/teamscale/test_impacted/engine/executor/ITestSorter.java b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/executor/ITestSorter.kt similarity index 52% rename from impacted-test-engine/src/main/java/com/teamscale/test_impacted/engine/executor/ITestSorter.java rename to impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/executor/ITestSorter.kt index 4bbb8f7a1..2fb604a3f 100644 --- a/impacted-test-engine/src/main/java/com/teamscale/test_impacted/engine/executor/ITestSorter.java +++ b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/executor/ITestSorter.kt @@ -1,14 +1,12 @@ -package com.teamscale.test_impacted.engine.executor; +package com.teamscale.test_impacted.engine.executor -import org.junit.platform.engine.TestDescriptor; - -/** Interface for implementing different ways of ordering tests. */ -public interface ITestSorter { +import org.junit.platform.engine.TestDescriptor +/** Interface for implementing different ways of ordering tests. */ +interface ITestSorter { /** * Removes any tests from the test descriptor that should not be executed and changes the execution order of the * remaining tests. */ - void selectAndSort(TestDescriptor testDescriptor); - + fun selectAndSort(testDescriptor: TestDescriptor) } diff --git a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/options/TestEngineOptions.kt b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/options/TestEngineOptions.kt index 1f3ae1e4c..d95910578 100644 --- a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/options/TestEngineOptions.kt +++ b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/options/TestEngineOptions.kt @@ -104,7 +104,7 @@ class TestEngineOptions { File(reportDirectory, "server-request.txt") ) return ImpactedTestsProvider( - client, baseline, baselineRevision, endCommit, endRevision, repository, partition, + client, baseline!!, baselineRevision!!, endCommit!!, endRevision!!, repository!!, partition!!, runAllTests, includeAddedTests, includeFailedAndSkipped ) } diff --git a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/CucumberPickleDescriptorResolver.kt b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/CucumberPickleDescriptorResolver.kt index ed7f2275b..b99e3b8d2 100644 --- a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/CucumberPickleDescriptorResolver.kt +++ b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/CucumberPickleDescriptorResolver.kt @@ -1,17 +1,18 @@ package com.teamscale.test_impacted.test_descriptor -import com.teamscale.test_impacted.commons.LoggerUtils.getLogger +import com.teamscale.test_impacted.commons.LoggerUtils.createLogger import com.teamscale.test_impacted.test_descriptor.TestDescriptorUtils.getUniqueIdSegment import org.junit.platform.engine.TestDescriptor import java.lang.reflect.Field import java.util.* -import java.util.logging.Logger /** * Test descriptor resolver for Cucumber. For details how we extract the uniform path, see comment in * [getPickleName]. The cluster id is the .feature file in which the tests are defined. */ class CucumberPickleDescriptorResolver : ITestDescriptorResolver { + private val LOGGER = createLogger() + override fun getUniformPath(descriptor: TestDescriptor): Optional { val featurePath = descriptor.featurePath() LOGGER.fine { "Resolved feature: $featurePath" } @@ -145,8 +146,6 @@ class CucumberPickleDescriptorResolver : ITestDescriptorResolver { /** Type of the unique id segment of a test descriptor representing a cucumber feature file */ const val FEATURE_SEGMENT_TYPE = "feature" - private val LOGGER: Logger = getLogger(CucumberPickleDescriptorResolver::class.java) - /** * Escapes slashes (/) in a given input (usually a scenario name) with a backslash (\). *



diff --git a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/JUnitClassBasedTestDescriptorResolverBase.kt b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/JUnitClassBasedTestDescriptorResolverBase.kt index db5d15487..0832f6b56 100644 --- a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/JUnitClassBasedTestDescriptorResolverBase.kt +++ b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/JUnitClassBasedTestDescriptorResolverBase.kt @@ -1,11 +1,13 @@ package com.teamscale.test_impacted.test_descriptor -import com.teamscale.test_impacted.commons.LoggerUtils.getLogger +import com.teamscale.test_impacted.commons.LoggerUtils.createLogger import org.junit.platform.engine.TestDescriptor import java.util.* /** Test descriptor resolver for JUnit based [org.junit.platform.engine.TestEngine]s. */ abstract class JUnitClassBasedTestDescriptorResolverBase : ITestDescriptorResolver { + private val LOGGER = createLogger() + override fun getUniformPath(descriptor: TestDescriptor): Optional = descriptor.getClassName().map { className -> val dotName = className.replace(".", "/") @@ -28,8 +30,4 @@ abstract class JUnitClassBasedTestDescriptorResolverBase : ITestDescriptorResolv /** Returns the test class containing the test. */ protected abstract fun TestDescriptor.getClassName(): Optional - - companion object { - private val LOGGER = getLogger(JUnitClassBasedTestDescriptorResolverBase::class.java) - } } diff --git a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/JUnitPlatformSuiteDescriptorResolver.kt b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/JUnitPlatformSuiteDescriptorResolver.kt index c182460ce..bf823ac45 100644 --- a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/JUnitPlatformSuiteDescriptorResolver.kt +++ b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/JUnitPlatformSuiteDescriptorResolver.kt @@ -1,5 +1,6 @@ package com.teamscale.test_impacted.test_descriptor +import com.teamscale.test_impacted.commons.LoggerUtils.createLogger import com.teamscale.test_impacted.commons.LoggerUtils.getLogger import org.junit.platform.engine.TestDescriptor import org.junit.platform.engine.UniqueId @@ -24,7 +25,7 @@ class JUnitPlatformSuiteDescriptorResolver : ITestDescriptorResolver { get() = "junit-platform-suite" companion object { - private val LOGGER = getLogger(JUnitPlatformSuiteDescriptorResolver::class.java) + private val LOGGER = createLogger() /** Type of the unique id segment of a test descriptor representing a test suite */ private const val SUITE_SEGMENT_TYPE: String = "suite" diff --git a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/TestDescriptorResolverRegistry.kt b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/TestDescriptorResolverRegistry.kt index 09e642d19..1e3a602e2 100644 --- a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/TestDescriptorResolverRegistry.kt +++ b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/TestDescriptorResolverRegistry.kt @@ -1,5 +1,6 @@ package com.teamscale.test_impacted.test_descriptor +import com.teamscale.test_impacted.commons.LoggerUtils.createLogger import com.teamscale.test_impacted.commons.LoggerUtils.getLogger import org.junit.platform.commons.util.ClassLoaderUtils import java.util.* @@ -9,7 +10,7 @@ import java.util.* * [ServiceLoader]. */ object TestDescriptorResolverRegistry { - private val LOGGER = getLogger(TestDescriptorResolverRegistry::class.java) + private val LOGGER = createLogger() private val TEST_DESCRIPTOR_RESOLVER_BY_ENGINE_ID = mutableMapOf() diff --git a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/TestDescriptorUtils.kt b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/TestDescriptorUtils.kt index a9a02250c..032f8769a 100644 --- a/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/TestDescriptorUtils.kt +++ b/impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/test_descriptor/TestDescriptorUtils.kt @@ -2,6 +2,7 @@ package com.teamscale.test_impacted.test_descriptor import com.teamscale.client.ClusteredTestDetails import com.teamscale.test_impacted.commons.IndentingWriter +import com.teamscale.test_impacted.commons.LoggerUtils.createLogger import com.teamscale.test_impacted.commons.LoggerUtils.getLogger import com.teamscale.test_impacted.engine.executor.AvailableTests import org.junit.platform.engine.TestDescriptor @@ -13,7 +14,7 @@ import java.util.stream.Stream /** Class containing utility methods for [TestDescriptor]s. */ object TestDescriptorUtils { - private val LOGGER = getLogger(TestDescriptorUtils::class.java) + private val LOGGER = createLogger() /** Returns the test descriptor as a formatted string with indented children. */ @JvmStatic diff --git a/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineTestBase.kt b/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineTestBase.kt index 20132ac16..09252463f 100644 --- a/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineTestBase.kt +++ b/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineTestBase.kt @@ -14,17 +14,11 @@ import org.mockito.Mockito.mock /** Base class for testing specific scenarios in the impacted test engine. */ abstract class ImpactedTestEngineTestBase { private val testEngineRegistry = mock() - private val testDataWriter = mock() - private val impactedTestsProvider = mock() - private val discoveryRequest = mock() - private val executionRequest = mock() - private val executionListener = mock() - private val teamscaleAgentNotifier = mock() @Test diff --git a/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineWithDynamicTestsTest.kt b/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineWithDynamicTestsTest.kt index daa425c82..bf086de98 100644 --- a/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineWithDynamicTestsTest.kt +++ b/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineWithDynamicTestsTest.kt @@ -35,9 +35,9 @@ internal class ImpactedTestEngineWithDynamicTestsTest : ImpactedTestEngineTestBa ) private val testRoot = SimpleTestDescriptor.testContainer(engineRootId, dynamicTestClassCase) - override val engines get() = listOf(DummyEngine(testRoot)) + override val engines = listOf(DummyEngine(testRoot)) - override val impactedTests get() = + override val impactedTests = listOf( PrioritizableTestCluster( "example/DynamicTest", diff --git a/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineWithTwoEnginesTest.kt b/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineWithTwoEnginesTest.kt index 02f5e7b0b..a527cab2f 100644 --- a/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineWithTwoEnginesTest.kt +++ b/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/ImpactedTestEngineWithTwoEnginesTest.kt @@ -99,12 +99,12 @@ internal class ImpactedTestEngineWithTwoEnginesTest : ImpactedTestEngineTestBase private val testEngine2Root = SimpleTestDescriptor.testContainer(engine2RootId, otherTestClass) - override val engines get() = listOf( + override val engines = listOf( DummyEngine(testEngine1Root), DummyEngine(testEngine2Root) ) - override val impactedTests get() = + override val impactedTests = listOf( PrioritizableTestCluster( FIRST_TEST_CLASS, diff --git a/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/NoImpactedTestsTest.kt b/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/NoImpactedTestsTest.kt index be21cbd55..7e5bbd385 100644 --- a/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/NoImpactedTestsTest.kt +++ b/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/NoImpactedTestsTest.kt @@ -29,8 +29,8 @@ internal class NoImpactedTestsTest : ImpactedTestEngineTestBase() { private val testEngine1Root = SimpleTestDescriptor.testContainer(engine1RootId, firstTestClass) - override val engines get() = listOf(DummyEngine(testEngine1Root)) - override val impactedTests get() = emptyList() + override val engines = listOf(DummyEngine(testEngine1Root)) + override val impactedTests = emptyList() override fun verifyCallbacks(executionListener: EngineExecutionListener) {} diff --git a/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/executor/TestwiseCoverageCollectingExecutionListenerTest.kt b/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/executor/TestwiseCoverageCollectingExecutionListenerTest.kt index bac8c9e57..921decf29 100644 --- a/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/executor/TestwiseCoverageCollectingExecutionListenerTest.kt +++ b/impacted-test-engine/src/test/kotlin/com/teamscale/test_impacted/engine/executor/TestwiseCoverageCollectingExecutionListenerTest.kt @@ -57,7 +57,7 @@ internal class TestwiseCoverageCollectingExecutionListenerTest { executionListener.executionStarted(testClass) Mockito.verify(executionListenerMock).executionStarted(testClass) - // Execution of impacted test case. + // Execution of an impacted test case. executionListener.executionStarted(impactedTestCase) Mockito.verify(mockApi).startTest("MyClass/impactedTestCase()") Mockito.verify(executionListenerMock).executionStarted(impactedTestCase) @@ -99,10 +99,10 @@ internal class TestwiseCoverageCollectingExecutionListenerTest { val testCase1Id = testClassId.append("TEST_CASE", "testCase1()") val testCase2Id = testClassId.append("TEST_CASE", "testCase2()") - val testCase1: TestDescriptor = SimpleTestDescriptor.testCase(testCase1Id) - val testCase2: TestDescriptor = SimpleTestDescriptor.testCase(testCase2Id) - val testClass: TestDescriptor = SimpleTestDescriptor.testContainer(testClassId, testCase1, testCase2) - val testRoot: TestDescriptor = SimpleTestDescriptor.testContainer(rootId, testClass) + val testCase1 = SimpleTestDescriptor.testCase(testCase1Id) + val testCase2 = SimpleTestDescriptor.testCase(testCase2Id) + val testClass = SimpleTestDescriptor.testContainer(testClassId, testCase1, testCase2) + val testRoot = SimpleTestDescriptor.testContainer(rootId, testClass) Mockito.`when`(resolver.getUniformPath(testCase1)) .thenReturn(Optional.of("MyClass/testCase1()"))