Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Spring Java fuzzer fallback to null value when nothing else works #2448

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.utbot.framework.plugin.api.util.utContext
import org.utbot.fuzzer.IdentityPreservingIdGenerator
import org.utbot.fuzzing.JavaValueProvider
import org.utbot.fuzzing.ValueProvider
import org.utbot.fuzzing.providers.AnyDepthNullValueProvider
import org.utbot.fuzzing.providers.FieldValueProvider
import org.utbot.fuzzing.providers.ObjectValueProvider
import org.utbot.fuzzing.providers.anyObjectValueProvider
Expand Down Expand Up @@ -93,6 +94,7 @@ class SpringIntegrationTestConcreteExecutionContext(
.with(springBeanValueProvider)
.with(createSavedEntityValueProviders(relevantRepositories, idGenerator))
.with(createFieldValueProviders(relevantRepositories, idGenerator))
.withFallback(AnyDepthNullValueProvider)
}

private fun createSavedEntityValueProviders(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ object NullValueProvider : ValueProvider<FuzzedType, FuzzedValue, FuzzedDescript
}
}

/**
* Unlike [NullValueProvider] can generate `null` values at any depth.
*
* Intended to be used as a last fallback.
*/
object AnyDepthNullValueProvider : ValueProvider<FuzzedType, FuzzedValue, FuzzedDescription> {

override fun accept(type: FuzzedType) = type.classId.isRefType

override fun generate(
description: FuzzedDescription,
type: FuzzedType
) = sequenceOf<Seed<FuzzedType, FuzzedValue>>(Seed.Simple(nullFuzzedValue(classClassId)))
}

/**
* Finds and create object from implementations of abstract classes or interfaces.
*/
Expand Down