Skip to content

Commit

Permalink
Apply review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorkaKulikov committed Jul 12, 2022
1 parent 5efe4c1 commit 765cae6
Show file tree
Hide file tree
Showing 135 changed files with 281 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.utbot.analytics.EngineAnalyticsContext
import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.eq
import org.utbot.examples.withFeaturePath
import java.io.File
import java.io.FileInputStream

class FeatureProcessorWithRepetitionTest : UtTestCaseChecker(OnePath::class, false) {
class FeatureProcessorWithRepetitionTest : UtValueTestCaseChecker(OnePath::class, false) {
companion object {
const val featureDir = "src/test/resources/features"
fun reward(coverage: Double, time: Double) = RewardEstimator.reward(coverage, time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class BunchTestGeneratorCommand : GenerateTestsAbstractCommand(

initializeEngine(workingDirectory)

// utContext is used in `generateTestCases`, `generateTest`, `generateReport`
// utContext is used in `generate`, `generateTest`, `generateReport`
withUtContext(UtContext(classLoader)) {

val testClassName = "${classUnderTest.simpleName}Test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
searchDirectory: Path,
chosenClassesToMockAlways: Set<ClassId>
): List<UtTestCase> =
TestCaseGenerator.generateTestCases(
TestCaseGenerator.generate(
targetMethods,
mockStrategy,
chosenClassesToMockAlways,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class GenerateTestsCommand :
if (targetMethods.isEmpty()) {
throw Exception("Nothing to process. No methods were provided")
}
// utContext is used in `generateTestCases`, `generateTest`, `generateReport`
// utContext is used in `generate`, `generateTest`, `generateReport`
withUtContext(UtContext(targetMethods.first().clazz.java.classLoader)) {

val testClassName = output?.toPath()?.toFile()?.nameWithoutExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ object UtBotJavaApi {
FileUtil.isolateClassFiles(classUnderTest.kotlin).toPath(), classpath, dependencyClassPath
)
}
.generateTestCases(
.generate(
methodsForAutomaticGeneration.map {
toUtMethod(
it.methodToBeTestedFromUserInput,
Expand Down Expand Up @@ -191,7 +191,7 @@ object UtBotJavaApi {
init(
FileUtil.isolateClassFiles(classUnderTest.kotlin).toPath(), classpath, dependencyClassPath
)
}.generateTestCases(
}.generate(
methodsForAutomaticGeneration.map {
toUtMethod(
it.methodToBeTestedFromUserInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ object TestCaseGenerator {
}

@Throws(CancellationException::class)
fun generateTestCasesAsync(
fun generateAsync(
controller: EngineController,
method: UtMethod<*>,
mockStrategy: MockStrategyApi,
Expand All @@ -136,7 +136,7 @@ object TestCaseGenerator {
return createDefaultFlow(engine)
}

fun generateTestCases(
fun generate(
methods: List<UtMethod<*>>,
mockStrategy: MockStrategyApi,
chosenClassesToMockAlways: Set<ClassId> = Mocker.javaDefaultClasses.mapTo(mutableSetOf()) { it.id },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class GenerateTestsAndSarifReportFacade(
}

private fun generateTestCases(targetClass: TargetClassWrapper, workingDirectory: Path): List<UtTestCase> =
TestCaseGenerator.generateTestCases(
TestCaseGenerator.generate(
targetClass.targetMethods(),
sarifProperties.mockStrategy,
sarifProperties.classesToMockAlways,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import mu.KotlinLogging
import org.utbot.common.runBlockingWithCancellationPredicate
import org.utbot.common.runIgnoringCancellationException
import org.utbot.engine.EngineController
import org.utbot.engine.UtBotSymbolicEngine
import org.utbot.framework.UtSettings
import org.utbot.framework.plugin.api.MockStrategyApi
import org.utbot.framework.plugin.api.TestCaseGenerator
Expand All @@ -13,10 +14,22 @@ import org.utbot.framework.plugin.api.UtExecution
import org.utbot.framework.plugin.api.UtMethod
import org.utbot.framework.plugin.api.UtTestCase
import org.utbot.framework.util.jimpleBody
import java.nio.file.Path

/**
* Special [UtTestCase] generator for test methods that has a correct
* wrapper for suspend function [TestCaseGenerator.generateAsync].
*/
object TestSpecificTestCaseGenerator {
private val logger = KotlinLogging.logger {}

fun init(buildDir: Path,
classpath: String?,
dependencyPaths: String,
engineActions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf(),
isCanceled: () -> Boolean = { false },
) = TestCaseGenerator.init(buildDir, classpath, dependencyPaths, engineActions, isCanceled)

fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtTestCase {
logger.trace { "UtSettings:${System.lineSeparator()}" + UtSettings.toString() }

Expand All @@ -27,7 +40,7 @@ object TestSpecificTestCaseGenerator {

runIgnoringCancellationException {
runBlockingWithCancellationPredicate(TestCaseGenerator.isCanceled) {
TestCaseGenerator.generateTestCasesAsync(EngineController(), method, mockStrategy).collect {
TestCaseGenerator.generateAsync(EngineController(), method, mockStrategy).collect {
when (it) {
is UtExecution -> executions += it
is UtError -> errors.merge(it.description, 1, Int::plus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.utbot.framework.plugin.api.FieldId
import org.utbot.framework.plugin.api.MockStrategyApi
import org.utbot.framework.plugin.api.MockStrategyApi.NO_MOCKS
import org.utbot.framework.plugin.api.UtAssembleModel
import org.utbot.framework.plugin.api.TestCaseGenerator
import org.utbot.framework.plugin.api.UtCompositeModel
import org.utbot.framework.plugin.api.UtDirectSetFieldModel
import org.utbot.framework.plugin.api.UtExecution
Expand All @@ -39,7 +38,7 @@ import kotlin.reflect.KFunction2
import kotlin.reflect.KFunction3
import org.junit.jupiter.api.Assertions.assertTrue

internal abstract class UtModelChecker(
internal abstract class UtModelTestCaseChecker(
testClass: KClass<*>,
testCodeGeneration: Boolean = true,
languagePipelines: List<CodeGenerationLanguageLastStage> = listOf(
Expand Down Expand Up @@ -136,7 +135,7 @@ internal abstract class UtModelChecker(
buildDir = findPathToClassFiles(classLocation)
previousClassLocation = classLocation
}
TestCaseGenerator.init(buildDir, classpath = null, dependencyPaths = System.getProperty("java.class.path"))
TestSpecificTestCaseGenerator.init(buildDir, classpath = null, dependencyPaths = System.getProperty("java.class.path"))
return TestSpecificTestCaseGenerator.generate(method, mockStrategy)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import org.utbot.framework.plugin.api.MockStrategyApi
import org.utbot.framework.plugin.api.MockStrategyApi.NO_MOCKS
import org.utbot.framework.plugin.api.ObjectMockTarget
import org.utbot.framework.plugin.api.ParameterMockTarget
import org.utbot.framework.plugin.api.TestCaseGenerator
import org.utbot.framework.plugin.api.UtCompositeModel
import org.utbot.framework.plugin.api.UtConcreteValue
import org.utbot.framework.plugin.api.UtInstrumentation
Expand Down Expand Up @@ -72,7 +71,7 @@ import kotlin.reflect.KFunction5

val logger = KotlinLogging.logger {}

abstract class UtTestCaseChecker(
abstract class UtValueTestCaseChecker(
testClass: KClass<*>,
testCodeGeneration: Boolean = true,
languagePipelines: List<CodeGenerationLanguageLastStage> = listOf(
Expand Down Expand Up @@ -2493,7 +2492,7 @@ abstract class UtTestCaseChecker(
mockStrategy: MockStrategyApi,
additionalDependenciesClassPath: String
): UtTestCase {
TestCaseGenerator.init(buildDir, additionalDependenciesClassPath, System.getProperty("java.class.path"))
TestSpecificTestCaseGenerator.init(buildDir, additionalDependenciesClassPath, System.getProperty("java.class.path"))
return TestSpecificTestCaseGenerator.generate(method, mockStrategy)
}

Expand All @@ -2504,7 +2503,7 @@ abstract class UtTestCaseChecker(
): UtTestCase {
val additionalDependenciesClassPath =
computeAdditionalDependenciesClasspathAndBuildDir(method, additionalDependencies)
TestCaseGenerator.init(buildDir, additionalDependenciesClassPath, System.getProperty("java.class.path"))
TestSpecificTestCaseGenerator.init(buildDir, additionalDependenciesClassPath, System.getProperty("java.class.path"))
withUtContext(UtContext(method.clazz.java.classLoader)) {
return TestSpecificTestCaseGenerator.generate(method, mockStrategy)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.examples.algorithms

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.ignoreExecutionsNumber
import org.utbot.examples.isException
import org.utbot.framework.plugin.api.DocCodeStmt
Expand All @@ -9,7 +9,7 @@ import org.utbot.framework.plugin.api.DocRegularStmt
import org.utbot.framework.plugin.api.DocStatement
import org.junit.jupiter.api.Test

class BinarySearchTest : UtTestCaseChecker(testClass = BinarySearch::class,) {
class BinarySearchTest : UtValueTestCaseChecker(testClass = BinarySearch::class,) {
@Test
fun testLeftBinarySearch() {
val fullSummary = listOf<DocStatement>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.examples.algorithms

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.algorithms.CorrectBracketSequences.isBracket
import org.utbot.examples.algorithms.CorrectBracketSequences.isOpen
import org.utbot.examples.eq
Expand All @@ -14,7 +14,7 @@ import org.utbot.framework.plugin.api.DocPreTagStatement
import org.utbot.framework.plugin.api.DocRegularStmt
import org.junit.jupiter.api.Test

internal class CorrectBracketSequencesTest : UtTestCaseChecker(
internal class CorrectBracketSequencesTest : UtValueTestCaseChecker(
testClass = CorrectBracketSequences::class,
testCodeGeneration = true,
languagePipelines = listOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.utbot.examples.algorithms

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.eq
import org.utbot.examples.ignoreExecutionsNumber
import org.utbot.examples.isException
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

internal class GraphTest : UtTestCaseChecker(testClass = GraphExample::class) {
internal class GraphTest : UtValueTestCaseChecker(testClass = GraphExample::class) {
@Test
@Tag("slow")
fun testRunFindCycle() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.examples.algorithms

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.eq
import org.utbot.examples.ge
import org.utbot.examples.ignoreExecutionsNumber
Expand All @@ -12,7 +12,7 @@ import org.utbot.framework.plugin.api.DocRegularStmt
import org.utbot.framework.plugin.api.MockStrategyApi
import org.junit.jupiter.api.Test

internal class SortTest : UtTestCaseChecker(testClass = Sort::class) {
internal class SortTest : UtValueTestCaseChecker(testClass = Sort::class) {
@Test
fun testQuickSort() {
check(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.examples.annotations

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.DoNotCalculate
import org.utbot.examples.annotations.lombok.EnumWithAnnotations
import org.utbot.examples.annotations.lombok.EnumWithoutAnnotations
Expand All @@ -15,7 +15,7 @@ import org.junit.jupiter.api.Test
* (see, i.e. https://stackoverflow.com/questions/44584487/improve-lombok-data-code-coverage)
* and Lombok code is considered to be already tested itself.
*/
class LombokAnnotationTest : UtTestCaseChecker(testClass = EnumWithAnnotations::class) {
class LombokAnnotationTest : UtValueTestCaseChecker(testClass = EnumWithAnnotations::class) {

@Test
fun testGetterWithAnnotations() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.utbot.examples.annotations

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.eq
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

internal class NotNullAnnotationTest : UtTestCaseChecker(testClass = NotNullAnnotation::class) {
internal class NotNullAnnotationTest : UtValueTestCaseChecker(testClass = NotNullAnnotation::class) {
@Test
fun testDoesNotThrowNPE() {
check(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.examples.arrays

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.DoNotCalculate
import org.utbot.examples.atLeast
import org.utbot.examples.casts.ColoredPoint
Expand All @@ -11,7 +11,7 @@ import org.utbot.examples.withoutMinimization
import org.junit.jupiter.api.Test

@Suppress("NestedLambdaShadowedImplicitParameter")
internal class ArrayOfArraysTest : UtTestCaseChecker(testClass = ArrayOfArrays::class) {
internal class ArrayOfArraysTest : UtValueTestCaseChecker(testClass = ArrayOfArrays::class) {
@Test
fun testDefaultValues() {
check(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.examples.arrays

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.DoNotCalculate
import org.utbot.examples.atLeast
import org.utbot.examples.between
Expand All @@ -13,7 +13,7 @@ import org.utbot.framework.plugin.api.CodegenLanguage
import org.junit.jupiter.api.Test

// TODO failed Kotlin compilation SAT-1332
internal class ArrayOfObjectsTest : UtTestCaseChecker(
internal class ArrayOfObjectsTest : UtValueTestCaseChecker(
testClass = ArrayOfObjects::class,
testCodeGeneration = true,
languagePipelines = listOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.utbot.examples.arrays

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.eq
import org.utbot.framework.codegen.CodeGeneration
import org.utbot.framework.plugin.api.CodegenLanguage
import org.junit.jupiter.api.Test

// TODO failed Kotlin compilation SAT-1332
class ArraysOverwriteValueTest : UtTestCaseChecker(
class ArraysOverwriteValueTest : UtValueTestCaseChecker(
testClass = ArraysOverwriteValue::class,
testCodeGeneration = true,
languagePipelines = listOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.utbot.examples.arrays

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.ignoreExecutionsNumber
import org.junit.jupiter.api.Test

internal class FinalStaticFieldArrayTest : UtTestCaseChecker(testClass = FinalStaticFieldArray::class) {
internal class FinalStaticFieldArrayTest : UtValueTestCaseChecker(testClass = FinalStaticFieldArray::class) {

@Test
fun testFactorial() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.examples.arrays

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.eq
import org.utbot.examples.ge
import org.utbot.examples.ignoreExecutionsNumber
Expand All @@ -10,7 +10,7 @@ import org.utbot.framework.plugin.api.CodegenLanguage
import org.junit.jupiter.api.Test

// TODO failed Kotlin compilation SAT-1332
internal class IntArrayBasicsTest : UtTestCaseChecker(
internal class IntArrayBasicsTest : UtValueTestCaseChecker(
testClass = IntArrayBasics::class,
testCodeGeneration = true,
languagePipelines = listOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.examples.arrays

import org.utbot.examples.UtTestCaseChecker
import org.utbot.examples.UtValueTestCaseChecker
import org.utbot.examples.atLeast
import org.utbot.examples.eq
import org.utbot.examples.isException
Expand All @@ -9,7 +9,7 @@ import org.utbot.framework.plugin.api.CodegenLanguage
import org.junit.jupiter.api.Test

// TODO failed Kotlin compilation SAT-1332
internal class PrimitiveArraysTest : UtTestCaseChecker(
internal class PrimitiveArraysTest : UtValueTestCaseChecker(
testClass = PrimitiveArrays::class,
testCodeGeneration = true,
languagePipelines = listOf(
Expand Down
Loading

0 comments on commit 765cae6

Please sign in to comment.