@@ -2,38 +2,48 @@ package org.utbot.framework.context.custom
2
2
3
3
import org.utbot.framework.context.JavaFuzzingContext
4
4
import org.utbot.fuzzing.JavaValueProvider
5
+ import org.utbot.fuzzing.providers.AnyDepthNullValueProvider
5
6
import org.utbot.fuzzing.providers.MapValueProvider
6
7
import org.utbot.fuzzing.spring.unit.MockValueProvider
7
8
import org.utbot.fuzzing.providers.NullValueProvider
8
9
import org.utbot.fuzzing.providers.ObjectValueProvider
9
10
import org.utbot.fuzzing.providers.StringValueProvider
11
+ import org.utbot.fuzzing.providers.anyObjectValueProvider
12
+ import org.utbot.fuzzing.spring.decorators.filterTypes
10
13
import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult
11
14
12
15
/* *
13
- * Makes fuzzer mock all types that don't have *specific* [JavaValueProvider],
14
- * like [MapValueProvider] or [StringValueProvider].
16
+ * Allows fuzzer to use mocks in accordance with [JavaFuzzingContext.mockStrategy].
15
17
*
16
- * NOTE: the caller is responsible for providing some *specific* [JavaValueProvider]
17
- * that can create values for class under test (otherwise it will be mocked),
18
- * [ObjectValueProvider] and [NullValueProvider] do not count as *specific*.
18
+ * NOTE:
19
+ * - fuzzer won't mock types, that have *specific* value providers (e.g. [MapValueProvider] and [StringValueProvider])
20
+ * - [ObjectValueProvider] and [NullValueProvider] do not count as *specific* value providers
19
21
*/
20
- fun JavaFuzzingContext.mockAllTypesWithoutSpecificValueProvider () =
22
+ fun JavaFuzzingContext.allowMocks () =
21
23
MockingJavaFuzzingContext (delegateContext = this )
22
24
23
25
class MockingJavaFuzzingContext (
24
- val delegateContext : JavaFuzzingContext
26
+ val delegateContext : JavaFuzzingContext ,
25
27
) : JavaFuzzingContext by delegateContext {
26
28
private val mockValueProvider = MockValueProvider (delegateContext.idGenerator)
27
29
28
30
override val valueProvider: JavaValueProvider =
29
- // NOTE: we first remove `NullValueProvider` from `delegateContext.valueProvider` and then
30
- // add it back as a part of our `withFallback` so it has the same priority as
31
- // `mockValueProvider`, otherwise mocks will never be used where `null` can be used.
31
+ // NOTE: we first remove `NullValueProvider` and `ObjectValueProvider` from `delegateContext.valueProvider`
32
+ // and then add them back as a part of our `withFallback` so they have the same priority as
33
+ // `mockValueProvider`, otherwise mocks will never be used where `null` or new object can be used.
32
34
delegateContext.valueProvider
33
35
.except { it is NullValueProvider }
34
36
.except { it is ObjectValueProvider }
35
37
.withFallback(
36
38
mockValueProvider
39
+ .filterTypes { type ->
40
+ mockStrategy.eligibleToMock(
41
+ classToMock = type.classId,
42
+ classUnderTest = classUnderTest
43
+ )
44
+ }
45
+ .with (anyObjectValueProvider(idGenerator))
46
+ .withFallback(mockValueProvider.with (AnyDepthNullValueProvider ))
37
47
.with (NullValueProvider )
38
48
)
39
49
0 commit comments