File tree Expand file tree Collapse file tree 3 files changed +13
-1
lines changed
utbot-framework/src/main/kotlin/org/utbot/framework/codegen Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,8 @@ internal val doNothingMethodId = builtinStaticMethodId(
97
97
internal val whenStubberMethodId = builtinMethodId(
98
98
classId = stubberClassId,
99
99
name = " when" ,
100
- returnType = objectClassId,
100
+ returnType = stubberClassId,
101
+ arguments = arrayOf(objectClassId)
101
102
)
102
103
103
104
// TODO: for this method and other static methods implement some utils that allow calling
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import org.utbot.framework.codegen.domain.builtin.getTargetException
10
10
import org.utbot.framework.codegen.domain.builtin.invoke
11
11
import org.utbot.framework.codegen.domain.builtin.newInstance
12
12
import org.utbot.framework.codegen.domain.builtin.setAccessible
13
+ import org.utbot.framework.codegen.domain.builtin.stubberClassId
13
14
import org.utbot.framework.codegen.domain.context.CgContext
14
15
import org.utbot.framework.codegen.domain.context.CgContextOwner
15
16
import org.utbot.framework.codegen.domain.models.CgAllocateArray
@@ -192,8 +193,16 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
192
193
when {
193
194
// method of the current test class can be called on its 'this' instance
194
195
currentTestClass == executable.classId && this isThisInstanceOf currentTestClass -> true
196
+
195
197
// method of a class can be called on an object of this class or any of its subtypes
196
198
this .type isSubtypeOf executable.classId -> true
199
+
200
+ // We allow callers with [stubberClassId] classId to call any executable.
201
+ // Example to see why: doNothing().when(entityManagerMock).persist(any()).
202
+ // Here [persist()] cannot be called on [doNothing().when(entityManagerMock)],
203
+ // because it requires [EntityManager] classId caller.
204
+ this .type == stubberClassId -> true
205
+
197
206
else -> false
198
207
}
199
208
Original file line number Diff line number Diff line change @@ -202,6 +202,8 @@ private class MockitoMocker(context: CgContext) : ObjectMocker(context) {
202
202
// We would like to mark that this field is used and must not be removed from test class.
203
203
// Without `doNothing` call Intellij Idea suggests removing this field as unused.
204
204
is MethodId -> {
205
+ // We allow [stubberClassId] to be a receiver of [executable].
206
+ // See [CgExpression.canBeReceiverOf]
205
207
+ mockitoClassId[doNothingMethodId]()[whenStubberMethodId](mockObject)[executable](* matchers)
206
208
}
207
209
else -> error(" Only MethodId and ConstructorId was expected to appear in simple mocker but got $executable " )
You can’t perform that action at this time.
0 commit comments