1
1
package org.utbot.framework.context.custom
2
2
3
3
import org.utbot.framework.context.JavaFuzzingContext
4
+ import org.utbot.framework.plugin.api.UtNullModel
4
5
import org.utbot.framework.plugin.api.ExecutableId
5
6
import org.utbot.fuzzer.FuzzedType
6
7
import org.utbot.fuzzing.JavaValueProvider
8
+ import org.utbot.fuzzing.Seed
7
9
import org.utbot.fuzzing.providers.AnyDepthNullValueProvider
8
- import org.utbot.fuzzing.providers.MapValueProvider
10
+ import org.utbot.fuzzing.providers.AnyObjectValueProvider
9
11
import org.utbot.fuzzing.spring.unit.MockValueProvider
10
- import org.utbot.fuzzing.providers.NullValueProvider
11
- import org.utbot.fuzzing.providers.ObjectValueProvider
12
- import org.utbot.fuzzing.providers.StringValueProvider
13
- import org.utbot.fuzzing.providers.anyObjectValueProvider
12
+ import org.utbot.fuzzing.spring.decorators.filterSeeds
14
13
import org.utbot.fuzzing.spring.decorators.filterTypes
15
14
import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult
16
15
17
16
/* *
18
17
* Makes fuzzer to use mocks in accordance with [mockPredicate].
19
18
*
20
19
* NOTE:
21
- * - fuzzer won't mock types, that have *specific* value providers (e.g. [MapValueProvider] and [StringValueProvider])
22
- * - [ObjectValueProvider] and [NullValueProvider] do not count as *specific* value providers
23
- * - fuzzer may still resort to mocks despite [mockPredicate] if it can't create other non-null values or at runtime
20
+ * - fuzzer won't mock types, that have *specific* value providers
21
+ * (i.e. ones that do not implement [AnyObjectValueProvider])
22
+ * - fuzzer may still resort to mocks despite [mockPredicate] and *specific*
23
+ * value providers if it can't create other non-null values or at runtime
24
24
*/
25
25
fun JavaFuzzingContext.useMocks (mockPredicate : (FuzzedType ) -> Boolean ) =
26
26
MockingJavaFuzzingContext (delegateContext = this , mockPredicate)
@@ -32,17 +32,20 @@ class MockingJavaFuzzingContext(
32
32
private val mockValueProvider = MockValueProvider (delegateContext.idGenerator)
33
33
34
34
override val valueProvider: JavaValueProvider =
35
- // NOTE: we first remove `NullValueProvider` and `ObjectValueProvider` from `delegateContext.valueProvider`
36
- // and then add them back as a part of our `withFallback` so they have the same priority as
37
- // `mockValueProvider`, otherwise mocks will never be used where `null` or new object can be used.
35
+
38
36
delegateContext.valueProvider
39
- .except { it is NullValueProvider }
40
- .except { it is ObjectValueProvider }
37
+ // NOTE: we first remove `AnyObjectValueProvider` and `NullValueProvider` from `delegateContext.valueProvider`
38
+ // and then add them back as a part of our `withFallback` so they have the same priority as
39
+ // `mockValueProvider`, otherwise mocks will never be used where `null` or new object can be used.
40
+ .except { it is AnyObjectValueProvider }
41
41
.withFallback(
42
42
mockValueProvider.filterTypes(mockPredicate)
43
- .with (anyObjectValueProvider(idGenerator).filterTypes { ! mockPredicate(it) })
43
+ .with (
44
+ delegateContext.valueProvider
45
+ .filterTypes { ! mockPredicate(it) }
46
+ .filterSeeds { (it as ? Seed .Simple )?.value?.model !is UtNullModel }
47
+ )
44
48
.withFallback(mockValueProvider.with (AnyDepthNullValueProvider ))
45
- .with (NullValueProvider )
46
49
)
47
50
48
51
override fun handleFuzzedConcreteExecutionResult (
0 commit comments