@@ -13,20 +13,36 @@ import org.utbot.fuzzer.fuzzed
13
13
import org.utbot.fuzzing.FuzzedDescription
14
14
import org.utbot.fuzzing.JavaValueProvider
15
15
import org.utbot.fuzzing.Routine
16
+ import org.utbot.fuzzing.Scope
17
+ import org.utbot.fuzzing.ScopeProperty
16
18
import org.utbot.fuzzing.Seed
17
19
import org.utbot.fuzzing.toFuzzerType
18
20
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
+
19
25
/* *
20
26
* Models created by this class can be used with `@InjectMock` annotation, because
21
27
* 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].
22
30
*/
23
31
class InjectMockValueProvider (
24
32
private val idGenerator : IdGenerator <Int >,
25
- private val classToUseCompositeModelFor : ClassId
33
+ private val classUnderTest : ClassId
26
34
) : 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
28
43
29
44
override fun generate (description : FuzzedDescription , type : FuzzedType ): Sequence <Seed <FuzzedType , FuzzedValue >> {
45
+ if (description.scope?.getProperty(INJECT_MOCK_FLAG ) == null ) return emptySequence()
30
46
val fields = type.classId.allDeclaredFieldIds.filterNot { it.isStatic && it.isFinal }.toList()
31
47
return sequenceOf(Seed .Recursive (
32
48
construct = Routine .Create (types = fields.map { toFuzzerType(it.jField.genericType, description.typeCache) }) { values ->
0 commit comments