Skip to content

Commit cb633a4

Browse files
committed
Add JavaLangObjectValueProvider that uses class under test in place of java.lang.Objects
1 parent be47d83 commit cb633a4

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/context/utils/ApplicationContextUtils.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.utbot.framework.context.utils
22

33
import org.utbot.framework.context.ApplicationContext
44
import org.utbot.framework.context.ConcreteExecutionContext
5+
import org.utbot.framework.context.ConcreteExecutionContext.FuzzingContextParams
56
import org.utbot.fuzzing.JavaValueProvider
67

78
fun ApplicationContext.transformConcreteExecutionContext(
@@ -18,5 +19,5 @@ fun ApplicationContext.transformConcreteExecutionContext(
1819
}
1920

2021
fun ApplicationContext.transformValueProvider(
21-
transformer: (JavaValueProvider) -> JavaValueProvider
22+
transformer: FuzzingContextParams.(JavaValueProvider) -> JavaValueProvider
2223
) = transformConcreteExecutionContext { it.transformValueProvider(transformer) }

utbot-framework/src/main/kotlin/org/utbot/framework/context/utils/ConcreteExecutionContextUtils.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ fun ConcreteExecutionContext.transformJavaFuzzingContext(
1414
}
1515

1616
fun ConcreteExecutionContext.transformValueProvider(
17-
transformer: (JavaValueProvider) -> JavaValueProvider
18-
) = transformJavaFuzzingContext { it.transformValueProvider(transformer) }
17+
transformer: FuzzingContextParams.(JavaValueProvider) -> JavaValueProvider
18+
) = transformJavaFuzzingContext { javaFuzzingContext ->
19+
javaFuzzingContext.transformValueProvider { valueProvider -> transformer(valueProvider) }
20+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.utbot.fuzzing.spring
2+
3+
import org.utbot.framework.plugin.api.ClassId
4+
import org.utbot.framework.plugin.api.util.jClass
5+
import org.utbot.framework.plugin.api.util.objectClassId
6+
import org.utbot.fuzzer.FuzzedType
7+
import org.utbot.fuzzer.FuzzedValue
8+
import org.utbot.fuzzer.toTypeParametrizedByTypeVariables
9+
import org.utbot.fuzzing.FuzzedDescription
10+
import org.utbot.fuzzing.JavaValueProvider
11+
import org.utbot.fuzzing.Routine
12+
import org.utbot.fuzzing.Seed
13+
import org.utbot.fuzzing.providers.nullRoutine
14+
import org.utbot.fuzzing.toFuzzerType
15+
16+
class JavaLangObject(
17+
private val classesToTryUsingAsJavaLangObject: List<ClassId>,
18+
) : JavaValueProvider {
19+
override fun accept(type: FuzzedType): Boolean {
20+
return type.classId == objectClassId
21+
}
22+
23+
override fun generate(description: FuzzedDescription, type: FuzzedType): Sequence<Seed<FuzzedType, FuzzedValue>> =
24+
classesToTryUsingAsJavaLangObject.map { classToUseAsObject ->
25+
val fuzzedType = toFuzzerType(
26+
type = classToUseAsObject.jClass.toTypeParametrizedByTypeVariables(),
27+
cache = description.typeCache
28+
)
29+
Seed.Recursive(
30+
construct = Routine.Create(listOf(fuzzedType)) { (value) -> value },
31+
modify = emptySequence(),
32+
empty = nullRoutine(type.classId)
33+
)
34+
}.asSequence()
35+
}

utbot-spring-framework/src/main/kotlin/org/utbot/framework/context/spring/SpringApplicationContextImpl.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import org.utbot.framework.plugin.api.util.SpringModelUtils.entityClassIds
2626
import org.utbot.framework.plugin.api.util.allSuperTypes
2727
import org.utbot.framework.plugin.api.util.id
2828
import org.utbot.framework.plugin.api.util.jClass
29+
import org.utbot.framework.plugin.api.util.objectClassId
2930
import org.utbot.framework.plugin.api.util.utContext
31+
import org.utbot.fuzzing.spring.JavaLangObject
3032
import org.utbot.fuzzing.spring.FuzzedTypeFlag
3133
import org.utbot.fuzzing.spring.addProperties
3234
import org.utbot.fuzzing.spring.decorators.replaceTypes
@@ -58,7 +60,11 @@ class SpringApplicationContextImpl(
5860
var delegateConcreteExecutionContext = delegateContext.createConcreteExecutionContext(
5961
fullClasspath,
6062
classpathWithoutDependencies
61-
)
63+
).transformValueProvider { valueProvider ->
64+
valueProvider.with(JavaLangObject(
65+
classesToTryUsingAsJavaLangObject = listOf(objectClassId, classUnderTest)
66+
))
67+
}
6268

6369
// to avoid filtering out all coverage, we only filter
6470
// coverage when `classpathWithoutDependencies` is provided

0 commit comments

Comments
 (0)