-
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.95% +1.50%
- Complexity 4337 4647 +310
============================================
Files 441 450 +9
Lines 13534 14513 +979
Branches 1707 1834 +127
============================================
+ Hits 10888 11894 +1006
+ Misses 2008 1942 -66
- 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
@@ -53,17 +56,17 @@ public Object invokeConstructor(Object[] arguments) { | |||
|
|||
@Override | |||
public Object getProperty(Object target, String property) { | |||
String methodName = GroovyRuntimeUtil.propertyToMethodName("is", property); | |||
String methodName = GroovyRuntimeUtil.propertyToMethodName(IS, property); |
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.
🤔 I wonder if we should have three dedicated methods instead that delegate to this. propteryToGetterMethodName
/propteryToSetterMethodName
/ propteryToIsMethodName
(not sure about the last one.)
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.
I introduced propertyToGetterMethodName
, propertyToSetterMethodName
and propertyToBooleanGetterMethodName
.
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.
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
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 #2039