@@ -13,20 +13,36 @@ import org.utbot.fuzzer.fuzzed
1313import org.utbot.fuzzing.FuzzedDescription
1414import org.utbot.fuzzing.JavaValueProvider
1515import org.utbot.fuzzing.Routine
16+ import org.utbot.fuzzing.Scope
17+ import org.utbot.fuzzing.ScopeProperty
1618import org.utbot.fuzzing.Seed
1719import org.utbot.fuzzing.toFuzzerType
1820
21+ val INJECT_MOCK_FLAG = ScopeProperty <Unit >(
22+ " INJECT_MOCK_FLAG is present if composite model should be used (i.e. thisInstance is being created)"
23+ )
24+
1925/* *
2026 * Models created by this class can be used with `@InjectMock` annotation, because
2127 * they are [UtCompositeModel]s similar to the ones created by the symbolic engine.
28+ *
29+ * This class only creates models for thisInstance of type [classUnderTest].
2230 */
2331class InjectMockValueProvider (
2432 private val idGenerator : IdGenerator <Int >,
25- private val classToUseCompositeModelFor : ClassId
33+ private val classUnderTest : ClassId
2634) : JavaValueProvider {
27- override fun accept (type : FuzzedType ): Boolean = type.classId == classToUseCompositeModelFor
35+ override fun enrich (description : FuzzedDescription , type : FuzzedType , scope : Scope ) {
36+ // any value except this
37+ if (description.description.isStatic == false && scope.parameterIndex == 0 && scope.recursionDepth == 1 ) {
38+ scope.putProperty(INJECT_MOCK_FLAG , Unit )
39+ }
40+ }
41+
42+ override fun accept (type : FuzzedType ): Boolean = type.classId == classUnderTest
2843
2944 override fun generate (description : FuzzedDescription , type : FuzzedType ): Sequence <Seed <FuzzedType , FuzzedValue >> {
45+ if (description.scope?.getProperty(INJECT_MOCK_FLAG ) == null ) return emptySequence()
3046 val fields = type.classId.allDeclaredFieldIds.filterNot { it.isStatic && it.isFinal }.toList()
3147 return sequenceOf(Seed .Recursive (
3248 construct = Routine .Create (types = fields.map { toFuzzerType(it.jField.genericType, description.typeCache) }) { values ->
0 commit comments