Introduce object creation using builders for fuzzers#2583
Open
Introduce object creation using builders for fuzzers#2583
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
We introduce new
BuilderObjectValueProviderfor Java that finds any method, that can create a value of given type. Together withAbstractObjectValueProviderit works only when ObjectValueProvider and others fails to build a value.The provider searches any method from any class that can return object of this type or any type that can be inferenced from the given one. It doesn't matter if this method static or not, but if this method is not static, that we suppose that we have a builder class for it. As a builder class we try to find other methods that returns an instance of this builder. This logic added because of default way to create such builder, where any set or add method returns the instance of builder to support chain calling. This builder should work to find methods for factories and singletones as well.
To support this provider, we introduce new routine in fuzzer's API called
Modify(the name maybe is not final). It is added forSeed.Recurisveand works as follows: it accepts a sequence of routines that changes or creates new object with given this instance and fuzzed values. For example, we firstly create builder's object and update it with builder method, then finally we call the method, that creates an object using this builder. This sequence is always called when creating an object and never changed its ordering.In addition, you can use this method, apply some method to the instance and return the instance object itself, for example, to always close a
Closableobject.As a result,
ContestEstimatorcovers 53% of guava project code, before it covers only 43%.How to test
Automated tests
All fuzzer tests should pass.
Manual tests
You can try to generate tests for this little project:
Self-check list
Check off the item if the statement is true. Hint: [x] is a marked item.
Please do not delete the list or its items.