Skip to content

Commit 765cae6

Browse files
committed
Apply review fixes
1 parent 5efe4c1 commit 765cae6

File tree

135 files changed

+281
-270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+281
-270
lines changed

utbot-analytics/src/test/kotlin/org/utbot/features/FeatureProcessorWithRepetitionTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import org.junit.jupiter.api.Assertions
55
import org.junit.jupiter.api.BeforeAll
66
import org.junit.jupiter.api.Test
77
import org.utbot.analytics.EngineAnalyticsContext
8-
import org.utbot.examples.UtTestCaseChecker
8+
import org.utbot.examples.UtValueTestCaseChecker
99
import org.utbot.examples.eq
1010
import org.utbot.examples.withFeaturePath
1111
import java.io.File
1212
import java.io.FileInputStream
1313

14-
class FeatureProcessorWithRepetitionTest : UtTestCaseChecker(OnePath::class, false) {
14+
class FeatureProcessorWithRepetitionTest : UtValueTestCaseChecker(OnePath::class, false) {
1515
companion object {
1616
const val featureDir = "src/test/resources/features"
1717
fun reward(coverage: Double, time: Double) = RewardEstimator.reward(coverage, time)

utbot-cli/src/main/kotlin/org/utbot/cli/BunchTestGeneratorCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class BunchTestGeneratorCommand : GenerateTestsAbstractCommand(
9999

100100
initializeEngine(workingDirectory)
101101

102-
// utContext is used in `generateTestCases`, `generateTest`, `generateReport`
102+
// utContext is used in `generate`, `generateTest`, `generateReport`
103103
withUtContext(UtContext(classLoader)) {
104104

105105
val testClassName = "${classUnderTest.simpleName}Test"

utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
159159
searchDirectory: Path,
160160
chosenClassesToMockAlways: Set<ClassId>
161161
): List<UtTestCase> =
162-
TestCaseGenerator.generateTestCases(
162+
TestCaseGenerator.generate(
163163
targetMethods,
164164
mockStrategy,
165165
chosenClassesToMockAlways,

utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class GenerateTestsCommand :
9797
if (targetMethods.isEmpty()) {
9898
throw Exception("Nothing to process. No methods were provided")
9999
}
100-
// utContext is used in `generateTestCases`, `generateTest`, `generateReport`
100+
// utContext is used in `generate`, `generateTest`, `generateReport`
101101
withUtContext(UtContext(targetMethods.first().clazz.java.classLoader)) {
102102

103103
val testClassName = output?.toPath()?.toFile()?.nameWithoutExtension

utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ object UtBotJavaApi {
127127
FileUtil.isolateClassFiles(classUnderTest.kotlin).toPath(), classpath, dependencyClassPath
128128
)
129129
}
130-
.generateTestCases(
130+
.generate(
131131
methodsForAutomaticGeneration.map {
132132
toUtMethod(
133133
it.methodToBeTestedFromUserInput,
@@ -191,7 +191,7 @@ object UtBotJavaApi {
191191
init(
192192
FileUtil.isolateClassFiles(classUnderTest.kotlin).toPath(), classpath, dependencyClassPath
193193
)
194-
}.generateTestCases(
194+
}.generate(
195195
methodsForAutomaticGeneration.map {
196196
toUtMethod(
197197
it.methodToBeTestedFromUserInput,

utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ object TestCaseGenerator {
125125
}
126126

127127
@Throws(CancellationException::class)
128-
fun generateTestCasesAsync(
128+
fun generateAsync(
129129
controller: EngineController,
130130
method: UtMethod<*>,
131131
mockStrategy: MockStrategyApi,
@@ -136,7 +136,7 @@ object TestCaseGenerator {
136136
return createDefaultFlow(engine)
137137
}
138138

139-
fun generateTestCases(
139+
fun generate(
140140
methods: List<UtMethod<*>>,
141141
mockStrategy: MockStrategyApi,
142142
chosenClassesToMockAlways: Set<ClassId> = Mocker.javaDefaultClasses.mapTo(mutableSetOf()) { it.id },

utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class GenerateTestsAndSarifReportFacade(
7070
}
7171

7272
private fun generateTestCases(targetClass: TargetClassWrapper, workingDirectory: Path): List<UtTestCase> =
73-
TestCaseGenerator.generateTestCases(
73+
TestCaseGenerator.generate(
7474
targetClass.targetMethods(),
7575
sarifProperties.mockStrategy,
7676
sarifProperties.classesToMockAlways,

utbot-framework/src/test/kotlin/org/utbot/examples/TestSpecificTestCaseGenerator.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import mu.KotlinLogging
55
import org.utbot.common.runBlockingWithCancellationPredicate
66
import org.utbot.common.runIgnoringCancellationException
77
import org.utbot.engine.EngineController
8+
import org.utbot.engine.UtBotSymbolicEngine
89
import org.utbot.framework.UtSettings
910
import org.utbot.framework.plugin.api.MockStrategyApi
1011
import org.utbot.framework.plugin.api.TestCaseGenerator
@@ -13,10 +14,22 @@ import org.utbot.framework.plugin.api.UtExecution
1314
import org.utbot.framework.plugin.api.UtMethod
1415
import org.utbot.framework.plugin.api.UtTestCase
1516
import org.utbot.framework.util.jimpleBody
17+
import java.nio.file.Path
1618

19+
/**
20+
* Special [UtTestCase] generator for test methods that has a correct
21+
* wrapper for suspend function [TestCaseGenerator.generateAsync].
22+
*/
1723
object TestSpecificTestCaseGenerator {
1824
private val logger = KotlinLogging.logger {}
1925

26+
fun init(buildDir: Path,
27+
classpath: String?,
28+
dependencyPaths: String,
29+
engineActions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf(),
30+
isCanceled: () -> Boolean = { false },
31+
) = TestCaseGenerator.init(buildDir, classpath, dependencyPaths, engineActions, isCanceled)
32+
2033
fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtTestCase {
2134
logger.trace { "UtSettings:${System.lineSeparator()}" + UtSettings.toString() }
2235

@@ -27,7 +40,7 @@ object TestSpecificTestCaseGenerator {
2740

2841
runIgnoringCancellationException {
2942
runBlockingWithCancellationPredicate(TestCaseGenerator.isCanceled) {
30-
TestCaseGenerator.generateTestCasesAsync(EngineController(), method, mockStrategy).collect {
43+
TestCaseGenerator.generateAsync(EngineController(), method, mockStrategy).collect {
3144
when (it) {
3245
is UtExecution -> executions += it
3346
is UtError -> errors.merge(it.description, 1, Int::plus)

utbot-framework/src/test/kotlin/org/utbot/examples/UtModelChecker.kt renamed to utbot-framework/src/test/kotlin/org/utbot/examples/UtModelTestCaseChecker.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import org.utbot.framework.plugin.api.FieldId
1515
import org.utbot.framework.plugin.api.MockStrategyApi
1616
import org.utbot.framework.plugin.api.MockStrategyApi.NO_MOCKS
1717
import org.utbot.framework.plugin.api.UtAssembleModel
18-
import org.utbot.framework.plugin.api.TestCaseGenerator
1918
import org.utbot.framework.plugin.api.UtCompositeModel
2019
import org.utbot.framework.plugin.api.UtDirectSetFieldModel
2120
import org.utbot.framework.plugin.api.UtExecution
@@ -39,7 +38,7 @@ import kotlin.reflect.KFunction2
3938
import kotlin.reflect.KFunction3
4039
import org.junit.jupiter.api.Assertions.assertTrue
4140

42-
internal abstract class UtModelChecker(
41+
internal abstract class UtModelTestCaseChecker(
4342
testClass: KClass<*>,
4443
testCodeGeneration: Boolean = true,
4544
languagePipelines: List<CodeGenerationLanguageLastStage> = listOf(
@@ -136,7 +135,7 @@ internal abstract class UtModelChecker(
136135
buildDir = findPathToClassFiles(classLocation)
137136
previousClassLocation = classLocation
138137
}
139-
TestCaseGenerator.init(buildDir, classpath = null, dependencyPaths = System.getProperty("java.class.path"))
138+
TestSpecificTestCaseGenerator.init(buildDir, classpath = null, dependencyPaths = System.getProperty("java.class.path"))
140139
return TestSpecificTestCaseGenerator.generate(method, mockStrategy)
141140
}
142141

utbot-framework/src/test/kotlin/org/utbot/examples/UtTestCaseChecker.kt renamed to utbot-framework/src/test/kotlin/org/utbot/examples/UtValueTestCaseChecker.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import org.utbot.framework.plugin.api.MockStrategyApi
4242
import org.utbot.framework.plugin.api.MockStrategyApi.NO_MOCKS
4343
import org.utbot.framework.plugin.api.ObjectMockTarget
4444
import org.utbot.framework.plugin.api.ParameterMockTarget
45-
import org.utbot.framework.plugin.api.TestCaseGenerator
4645
import org.utbot.framework.plugin.api.UtCompositeModel
4746
import org.utbot.framework.plugin.api.UtConcreteValue
4847
import org.utbot.framework.plugin.api.UtInstrumentation
@@ -72,7 +71,7 @@ import kotlin.reflect.KFunction5
7271

7372
val logger = KotlinLogging.logger {}
7473

75-
abstract class UtTestCaseChecker(
74+
abstract class UtValueTestCaseChecker(
7675
testClass: KClass<*>,
7776
testCodeGeneration: Boolean = true,
7877
languagePipelines: List<CodeGenerationLanguageLastStage> = listOf(
@@ -2493,7 +2492,7 @@ abstract class UtTestCaseChecker(
24932492
mockStrategy: MockStrategyApi,
24942493
additionalDependenciesClassPath: String
24952494
): UtTestCase {
2496-
TestCaseGenerator.init(buildDir, additionalDependenciesClassPath, System.getProperty("java.class.path"))
2495+
TestSpecificTestCaseGenerator.init(buildDir, additionalDependenciesClassPath, System.getProperty("java.class.path"))
24972496
return TestSpecificTestCaseGenerator.generate(method, mockStrategy)
24982497
}
24992498

@@ -2504,7 +2503,7 @@ abstract class UtTestCaseChecker(
25042503
): UtTestCase {
25052504
val additionalDependenciesClassPath =
25062505
computeAdditionalDependenciesClasspathAndBuildDir(method, additionalDependencies)
2507-
TestCaseGenerator.init(buildDir, additionalDependenciesClassPath, System.getProperty("java.class.path"))
2506+
TestSpecificTestCaseGenerator.init(buildDir, additionalDependenciesClassPath, System.getProperty("java.class.path"))
25082507
withUtContext(UtContext(method.clazz.java.classLoader)) {
25092508
return TestSpecificTestCaseGenerator.generate(method, mockStrategy)
25102509
}

0 commit comments

Comments
 (0)