GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fixed unavailable mock classes by Damtev · Pull Request #1066 · UnitTestBot/UTBotJava

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.

Sign up for GitHub

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
Damtev merged 2 commits into main from damtev/static_mocks_fix
Oct 5, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

Fixed unavailable mock classes #1066

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
a53d179
Fixed error with unavailable mock classes from mock framework
Damtev Oct 4, 2022
4c29331
Disabled Kotlin codegen tests with static mocks
Damtev Oct 4, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

14 changes: 12 additions & 2 deletions 14 utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt
Show comments
View file
Open in desktop
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
14 changes: 12 additions & 2 deletions 14 utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt
Show comments
View file
Open in desktop
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
12 changes: 11 additions & 1 deletion 12 utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt
Show comments
View file
Open in desktop
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
12 changes: 11 additions & 1 deletion 12 utbot-framework-test/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt
Show comments
View file
Open in desktop
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
12 changes: 11 additions & 1 deletion 12 utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt
Show comments
View file
Open in desktop
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
15 changes: 7 additions & 8 deletions 15 ...src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt
Show comments
View file
Open in desktop
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
4 changes: 2 additions & 2 deletions 4 ...rc/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/MockFrameworkManager.kt
Show comments
View file
Open in desktop
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
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.