Description
When user tries to use mocking for external classes UTBot creates var mockedConstruction = null which usage in the code cause type compatibility errors
To Reproduce
Steps to reproduce the behavior:
- In UTBot settings set
Generated test language to Kotlin other leave default - Enable
Force mocking static methods - Generate tests for following code
importjava.util.RandomclassRandomInt {
funmultByRandom(x:Int): Int {
val random:Random=Random();
return x * random.nextInt();
}
}Expected behavior
Compilable code is generated
Actual behavior
Generated test cannot be compiled. See its beginning below.
@Test
funtestMultByRandom1() {
var mockedConstruction =nulltry {
val mockClassCounter =AtomicInteger()
mockedConstruction = mockConstruction(Random::class.java) { RandomMock:Random,
context:MockedConstruction.Context->when (mockClassCounter.get()) {
0-> {
(`when`(RandomMock.nextInt())).thenReturn(0)
}
}
mockClassCounter.getAndIncrement()
}Visual proofs (screenshots, logs, images)

Description
When user tries to use mocking for external classes UTBot creates
var mockedConstruction = nullwhich usage in the code cause type compatibility errorsTo Reproduce
Steps to reproduce the behavior:
Generated test languagetoKotlinother leave defaultForce mocking static methodsExpected behavior
Compilable code is generated
Actual behavior
Generated test cannot be compiled. See its beginning below.
Visual proofs (screenshots, logs, images)