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