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(
9797internal val whenStubberMethodId = builtinMethodId(
9898 classId = stubberClassId,
9999 name = " when" ,
100- returnType = objectClassId,
100+ returnType = stubberClassId,
101+ arguments = arrayOf(objectClassId)
101102)
102103
103104// 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
1010import org.utbot.framework.codegen.domain.builtin.invoke
1111import org.utbot.framework.codegen.domain.builtin.newInstance
1212import org.utbot.framework.codegen.domain.builtin.setAccessible
13+ import org.utbot.framework.codegen.domain.builtin.stubberClassId
1314import org.utbot.framework.codegen.domain.context.CgContext
1415import org.utbot.framework.codegen.domain.context.CgContextOwner
1516import org.utbot.framework.codegen.domain.models.CgAllocateArray
@@ -192,8 +193,16 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
192193 when {
193194 // method of the current test class can be called on its 'this' instance
194195 currentTestClass == executable.classId && this isThisInstanceOf currentTestClass -> true
196+
195197 // method of a class can be called on an object of this class or any of its subtypes
196198 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+
197206 else -> false
198207 }
199208
Original file line number Diff line number Diff line change @@ -202,6 +202,8 @@ private class MockitoMocker(context: CgContext) : ObjectMocker(context) {
202202 // We would like to mark that this field is used and must not be removed from test class.
203203 // Without `doNothing` call Intellij Idea suggests removing this field as unused.
204204 is MethodId -> {
205+ // We allow [stubberClassId] to be a receiver of [executable].
206+ // See [CgExpression.canBeReceiverOf]
205207 + mockitoClassId[doNothingMethodId]()[whenStubberMethodId](mockObject)[executable](* matchers)
206208 }
207209 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