Skip to content

Fixed unavailable mock classes #1066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ import org.utbot.framework.plugin.api.DocPreTagStatement
import org.utbot.framework.plugin.api.DocRegularStmt
import org.utbot.framework.plugin.api.MockStrategyApi
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.testcheckers.eq
import org.utbot.testcheckers.ge

internal class SortTest : UtValueTestCaseChecker(testClass = Sort::class) {
import org.utbot.tests.infrastructure.CodeGeneration

// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88
internal class SortTest : UtValueTestCaseChecker(
testClass = Sort::class,
testCodeGeneration = true,
languagePipelines = listOf(
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA),
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
)
) {
@Test
fun testQuickSort() {
check(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ import org.utbot.framework.plugin.api.UtCompositeModel
import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation
import java.util.Random
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.testcheckers.eq

internal class MockRandomTest : UtValueTestCaseChecker(testClass = MockRandomExamples::class) {
import org.utbot.tests.infrastructure.CodeGeneration

// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88
internal class MockRandomTest : UtValueTestCaseChecker(
testClass = MockRandomExamples::class,
testCodeGeneration = true,
languagePipelines = listOf(
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA),
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
)
) {
@Test
fun testRandomAsParameter() {
val method: Random.() -> Int = Random::nextInt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ import org.utbot.framework.util.singleModel
import org.utbot.framework.util.singleStaticMethod
import org.utbot.framework.util.singleValue
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.testcheckers.eq
import org.utbot.tests.infrastructure.CodeGeneration

internal class MockStaticMethodExampleTest : UtValueTestCaseChecker(testClass = MockStaticMethodExample::class) {
// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88
internal class MockStaticMethodExampleTest : UtValueTestCaseChecker(
testClass = MockStaticMethodExample::class,
testCodeGeneration = true,
languagePipelines = listOf(
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA),
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
)
) {
@Test
fun testUseStaticMethod() {
checkMocksAndInstrumentation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ package org.utbot.examples.natives
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
import org.utbot.tests.infrastructure.DoNotCalculate
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.testcheckers.eq
import org.utbot.testcheckers.ge
import org.utbot.testcheckers.withSolverTimeoutInMillis
import org.utbot.tests.infrastructure.CodeGeneration

internal class NativeExamplesTest : UtValueTestCaseChecker(testClass = NativeExamples::class) {
// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88
internal class NativeExamplesTest : UtValueTestCaseChecker(
testClass = NativeExamples::class,
testCodeGeneration = true,
languagePipelines = listOf(
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA),
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
)
) {

@Test
fun testFindAndPrintSum() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ import org.utbot.framework.plugin.api.DocStatement
import kotlin.math.pow
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.testcheckers.eq
import org.utbot.testcheckers.ge
import org.utbot.tests.infrastructure.CodeGeneration

internal class RecursionTest : UtValueTestCaseChecker(testClass = Recursion::class) {
// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88
internal class RecursionTest : UtValueTestCaseChecker(
testClass = Recursion::class,
testCodeGeneration = true,
languagePipelines = listOf(
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA),
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
)
) {
@Test
fun testFactorial() {
val factorialSummary = listOf<DocStatement>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1316,21 +1316,20 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
resources.forEach {
// First argument for mocked resource declaration initializer is a target type.
// Pass this argument as a type parameter for the mocked resource

// TODO this type parameter (required for Kotlin test) is unused until the proper implementation
// of generics in code generation https://github.com/UnitTestBot/UTBotJava/issues/88
@Suppress("UNUSED_VARIABLE")
val typeParameter = when (val firstArg = (it.initializer as CgMethodCall).arguments.first()) {
is CgGetJavaClass -> firstArg.classId
is CgVariable -> firstArg.type
else -> error("Unexpected mocked resource declaration argument $firstArg")
}
val varType = CgClassId(
it.variableType,
TypeParameters(listOf(typeParameter)),
isNullable = true,
)

+CgDeclaration(
varType,
it.variableType,
it.variableName,
// guard initializer to reuse typecast creation logic
initializer = guardExpression(varType, nullLiteral()).expression,
initializer = nullLiteral(),
isMutable = true,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
mockClassCounter.variable
)
val mockedConstructionDeclaration = CgDeclaration(
CgClassId(MockitoStaticMocking.mockedConstructionClassId),
MockitoStaticMocking.mockedConstructionClassId,
variableConstructor.constructVarName(MOCKED_CONSTRUCTION_NAME),
mockConstructionInitializer
)
Expand Down Expand Up @@ -295,7 +295,7 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
val classMockStaticCall = mockStatic(modelClass)
val mockedStaticVariableName = variableConstructor.constructVarName(MOCKED_STATIC_NAME)
CgDeclaration(
CgClassId(MockitoStaticMocking.mockedStaticClassId),
MockitoStaticMocking.mockedStaticClassId,
mockedStaticVariableName,
classMockStaticCall
).also {
Expand Down