-
Notifications
You must be signed in to change notification settings - Fork 471
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
Best-effort error reporting for interactions on final methods #2040
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2040 +/- ##
============================================
+ Coverage 80.44% 81.89% +1.44%
- Complexity 4337 4651 +314
============================================
Files 441 450 +9
Lines 13534 14531 +997
Branches 1707 1835 +128
============================================
+ Hits 10888 11900 +1012
+ Misses 2008 1954 -54
- Partials 638 677 +39 ☔ View full report in Codecov by Sentry. |
2b54442
to
a50eb7f
Compare
spock-core/src/main/java/org/spockframework/mock/runtime/BaseMockInterceptor.java
Outdated
Show resolved
Hide resolved
spock-core/src/main/java/org/spockframework/mock/runtime/BaseMockInterceptor.java
Outdated
Show resolved
Hide resolved
spock-core/src/main/java/org/spockframework/mock/runtime/GroovyMockMetaClass.java
Outdated
Show resolved
Hide resolved
spock-core/src/main/java/org/spockframework/mock/runtime/IMockInteractionValidation.java
Outdated
Show resolved
Hide resolved
spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Issue("https://github.com/spockframework/spock/issues/2039") | ||
def "cannot stub final methods with byteBuddy without error message when one overload is non final"() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method name suggests that we should get an error here, but the test does not reflect that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fails to mock the method,. because one of the overloads is final, so there is not error message, because the parameters could have matched both the final or the non-final method, so we can't detect that right now => No error message.
This is the best-effort part of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this doesn't become obvious. The confusing part is what without error message
refers to. It can be read in two ways: one, that you can't do this without getting an error message, or it is a scenario where you don't expect to get an error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might help to use block labels in the test.
spock-core/src/main/java/org/spockframework/mock/runtime/IMockInteractionValidation.java
Outdated
Show resolved
Hide resolved
...k-core/src/main/java/org/spockframework/mock/runtime/ByteBuddyMockInteractionValidation.java
Outdated
Show resolved
Hide resolved
* @author Andreas Turban | ||
*/ | ||
@ThreadSafe | ||
final class ByteBuddyMockInteractionValidation implements IMockInteractionValidation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really specific to ByteBuddy, or does it apply to CgLib as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also work for the cglib
mock maker, but I did not want to implement the static field cache in cglib, because it is already deprecated.
If you want that supported, let me know, then I will have a look.
spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaStubs.groovy
Show resolved
Hide resolved
I didn't have time for a proper review, but is the validation done at compile-time or runtime? |
@Vampire It is done at runtime. During runtime, the expensive operation of calculating the The final methods For each interaction specification the cost is to loop over the contained For |
Add error reporting code to the byte-buddy` mock maker to report interaction on final methods, which can't be handled. The IMockInteractionValidator interface allows IMockMakers to implement different kinds of validations on mock interactions. Fixes spockframework#2039
spock-core/src/main/java/org/spockframework/mock/runtime/BaseMockInterceptor.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Issue("https://github.com/spockframework/spock/issues/2039") | ||
def "cannot stub final methods with byteBuddy without error message when one overload is non final"() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this doesn't become obvious. The confusing part is what without error message
refers to. It can be read in two ways: one, that you can't do this without getting an error message, or it is a scenario where you don't expect to get an error message.
spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaMocks.groovy
Outdated
Show resolved
Hide resolved
spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaMocks.groovy
Outdated
Show resolved
Hide resolved
spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaMocks.groovy
Outdated
Show resolved
Hide resolved
…ockInterceptor.java Co-authored-by: Leonard Brünings <[email protected]>
…Mocks.groovy Co-authored-by: Leonard Brünings <[email protected]>
…Mocks.groovy Co-authored-by: Leonard Brünings <[email protected]>
…Mocks.groovy Co-authored-by: Leonard Brünings <[email protected]>
Add error reporting code to the byte-buddy mock maker to report interaction on final methods, which can't be handled.
The
IMockInteractionValidator
interface allows IMockMakers to implement different kinds of validations on mock interactions.