-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support mock strategies and type replacement in Spring unit test fuzz…
…ing (#2561) * Support mock strategies and type replacement in Spring unit test fuzzing * Avoid mocking replaced types * Only use `InjectMockValueProvider` for `thisInstance` * Disallow non-mocks when mock can be used * Move all value provider decorators to one package * Improve adding of `ReplacedFuzzedTypeFlag` * Make `map` and `except` apply transformer/filter to ALL value providers * Avoid using `anyObjectValueProvider` that is removed in #2583 * Make `AnyObjectValueProvider` not extend any interfaces, remove unrelated comment * Fix compilation after rebase
- Loading branch information
1 parent
dd787d0
commit 36c23ff
Showing
19 changed files
with
218 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 29 additions & 19 deletions
48
...framework/src/main/kotlin/org/utbot/framework/context/custom/MockingJavaFuzzingContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...fuzzing/src/main/kotlin/org/utbot/fuzzing/spring/decorators/SeedFilteringValueProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.utbot.fuzzing.spring.decorators | ||
|
||
import org.utbot.fuzzing.Description | ||
import org.utbot.fuzzing.Seed | ||
import org.utbot.fuzzing.ValueProvider | ||
|
||
fun <T, R, D : Description<T>> ValueProvider<T, R, D>.filterSeeds(predicate: (Seed<T, R>) -> Boolean) = | ||
SeedFilteringValueProvider(delegate = this, predicate) | ||
|
||
class SeedFilteringValueProvider<T, R, D : Description<T>>( | ||
delegate: ValueProvider<T, R, D>, | ||
private val predicate: (Seed<T, R>) -> Boolean | ||
) : ValueProviderDecorator<T, R, D>(delegate) { | ||
override fun wrap(provider: ValueProvider<T, R, D>): ValueProvider<T, R, D> = | ||
provider.filterSeeds(predicate) | ||
|
||
override fun generate(description: D, type: T): Sequence<Seed<T, R>> = | ||
delegate.generate(description, type).filter(predicate) | ||
} |
18 changes: 18 additions & 0 deletions
18
...fuzzing/src/main/kotlin/org/utbot/fuzzing/spring/decorators/TypeFilteringValueProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.utbot.fuzzing.spring.decorators | ||
|
||
import org.utbot.fuzzing.Description | ||
import org.utbot.fuzzing.ValueProvider | ||
|
||
fun <T, R, D : Description<T>> ValueProvider<T, R, D>.filterTypes(predicate: (T) -> Boolean) = | ||
TypeFilteringValueProvider(delegate = this, predicate) | ||
|
||
class TypeFilteringValueProvider<T, R, D : Description<T>>( | ||
delegate: ValueProvider<T, R, D>, | ||
private val predicate: (T) -> Boolean | ||
) : ValueProviderDecorator<T, R, D>(delegate) { | ||
override fun wrap(provider: ValueProvider<T, R, D>): ValueProvider<T, R, D> = | ||
provider.filterTypes(predicate) | ||
|
||
override fun accept(type: T): Boolean = | ||
predicate(type) && super.accept(type) | ||
} |
28 changes: 28 additions & 0 deletions
28
...fuzzing/src/main/kotlin/org/utbot/fuzzing/spring/decorators/TypeReplacingValueProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.utbot.fuzzing.spring.decorators | ||
|
||
import org.utbot.fuzzing.Description | ||
import org.utbot.fuzzing.Scope | ||
import org.utbot.fuzzing.Seed | ||
import org.utbot.fuzzing.ValueProvider | ||
|
||
fun <T, R, D : Description<T>> ValueProvider<T, R, D>.replaceTypes(typeReplacer: (D, T) -> T) = | ||
TypeReplacingValueProvider(delegate = this, typeReplacer) | ||
|
||
class TypeReplacingValueProvider<T, R, D : Description<T>>( | ||
delegate: ValueProvider<T, R, D>, | ||
private val typeReplacer: (D, T) -> T | ||
) : ValueProviderDecorator<T, R, D>(delegate) { | ||
override fun wrap(provider: ValueProvider<T, R, D>): ValueProvider<T, R, D> = | ||
provider.replaceTypes(typeReplacer) | ||
|
||
override fun enrich(description: D, type: T, scope: Scope) = | ||
super.enrich(description, typeReplacer(description, type), scope) | ||
|
||
override fun accept(type: T): Boolean = true | ||
|
||
override fun generate(description: D, type: T): Sequence<Seed<T, R>> = | ||
if (super.accept(typeReplacer(description, type))) | ||
super.generate(description, typeReplacer(description, type)) | ||
else | ||
emptySequence() | ||
} |
Oops, something went wrong.