Skip to content

Do not strip type information from arguments (#871) - #1134

Merged
leonard84 merged 4 commits into
spockframework:masterfrom
Vampire:do-not-strip-type-information-from-arguments-in-mocks
Apr 30, 2020
Merged

leonard84 merged 4 commits into
spockframework:masterfrom
Vampire:do-not-strip-type-information-from-arguments-in-mocks

Conversation

@Vampire

@Vampire Vampire commented Mar 30, 2020 •

Copy link
Copy Markdown
Member

Fixes #871


This change is Reviewable

@Vampire
Vampire force-pushed the do-not-strip-type-information-from-arguments-in-mocks branch from a20a92e to 853e2be Compare March 31, 2020 13:07
@codecov

codecov Bot commented Mar 31, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #1134 into master will decrease coverage by 0.00%.
The diff coverage is 77.41%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1134      +/-   ##
============================================
- Coverage     75.01%   75.00%   -0.01%     
- Complexity     3526     3528       +2     
============================================
  Files           388      388              
  Lines         10872    10876       +4     
  Branches       1347     1348       +1     
============================================
+ Hits           8156     8158       +2     
- Misses         2245     2247       +2     
  Partials        471      471              
Impacted Files Coverage Δ Complexity Δ
.../main/java/org/spockframework/util/RenderUtil.java 85.00% <50.00%> (-6.18%) 19.00 <0.00> (+1.00) ⬇️
...kframework/mock/runtime/GroovyMockInterceptor.java 75.75% <66.66%> (ø) 9.00 <0.00> (ø)
...ockframework/mock/runtime/GroovyMockMetaClass.java 86.04% <88.88%> (+0.33%) 21.00 <10.00> (ø)
...ockframework/mock/runtime/JavaMockInterceptor.java 92.30% <100.00%> (ø) 16.00 <0.00> (ø)
.../org/spockframework/runtime/GroovyRuntimeUtil.java 70.23% <100.00%> (ø) 41.00 <1.00> (ø)
...n/java/org/spockframework/util/ReflectionUtil.java 79.64% <100.00%> (-0.53%) 65.00 <1.00> (-1.00)
...rg/spockframework/mock/runtime/MockInvocation.java 82.14% <0.00%> (+3.57%) 12.00% <0.00%> (+1.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e30462a...da70701. Read the comment docs.

@Vampire
Vampire force-pushed the do-not-strip-type-information-from-arguments-in-mocks branch 2 times, most recently from 46d3775 to ef0338f Compare April 5, 2020 23:13
@Vampire
Vampire force-pushed the do-not-strip-type-information-from-arguments-in-mocks branch 4 times, most recently from f545f05 to 1ad4178 Compare April 20, 2020 22:52
@Vampire
Vampire force-pushed the do-not-strip-type-information-from-arguments-in-mocks branch from 1ad4178 to 0e602fb Compare April 22, 2020 17:33

@leonard84 leonard84 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 8 of 8 files at r1.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @Vampire)


spock-core/src/main/java/org/spockframework/mock/runtime/GroovyMockInterceptor.java, line 48 at r1 (raw file):

    // we do not need the cast information from the wrappers here, the method selection
    // is already done, so unwrap the argument array if there are still wrappers present
    arguments = GroovyRuntimeUtil.asUnwrappedArgumentArray(arguments);

Parameters should be treated as final, even if we omit the final everywhere to avoid clutter. Even if some old code did that, we should clean it up.


spock-core/src/main/java/org/spockframework/mock/runtime/GroovyMockMetaClass.java, line 65 at r1 (raw file):

asArgumentArray

Isn't this redundant here? arguments are already an array.


spock-core/src/main/java/org/spockframework/mock/runtime/JavaMockInterceptor.java, line 53 at r1 (raw file):

asArgumentArray

Isn't this redundant here? arguments are already an array.


spock-core/src/main/java/org/spockframework/runtime/GroovyRuntimeUtil.java, line 228 at r1 (raw file):

  public static Object[] asUnwrappedArgumentArray(Object args) {
    return InvokerHelper.asUnwrappedArray(InvokerHelper.asArray(args).clone());

Maybe document that it does clone the array.


spock-specs/src/test/groovy/org/spockframework/smoke/mock/GroovySpiesThatAreGlobal.groovy, line 244 at r1 (raw file):

    when:
    PersonWithOverloadedMethods.perform(_) >> "Foo"

Maybe split here into a new test, as the result changes and it is not directly obvious.

Can we do this data-driven, or does it not work/reproduce the problem?

where:
action | result
{ PersonWithOverloadedMethods.perform("null string" as String) } | 'String'

@Vampire Vampire left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 3 of 8 files reviewed, 5 unresolved discussions (waiting on @leonard84)


spock-core/src/main/java/org/spockframework/mock/runtime/GroovyMockInterceptor.java, line 48 at r1 (raw file):

Previously, leonard84 (Leonard Brünings) wrote…

Parameters should be treated as final, even if we omit the final everywhere to avoid clutter. Even if some old code did that, we should clean it up.

Done.


spock-core/src/main/java/org/spockframework/mock/runtime/GroovyMockMetaClass.java, line 65 at r1 (raw file):

Previously, leonard84 (Leonard Brünings) wrote…
asArgumentArray

Isn't this redundant here? arguments are already an array.

No, null is translated to an empty array.
It could be replaced by Object[] args = (arguments == null) ? EMPTY_ARGS : arguments though if you prefer.


spock-core/src/main/java/org/spockframework/mock/runtime/JavaMockInterceptor.java, line 53 at r1 (raw file):

Previously, leonard84 (Leonard Brünings) wrote…
asArgumentArray

Isn't this redundant here? arguments are already an array.

Same as above


spock-core/src/main/java/org/spockframework/runtime/GroovyRuntimeUtil.java, line 228 at r1 (raw file):

Previously, leonard84 (Leonard Brünings) wrote…

Maybe document that it does clone the array.

Done.


spock-specs/src/test/groovy/org/spockframework/smoke/mock/GroovySpiesThatAreGlobal.groovy, line 244 at r1 (raw file):

Previously, leonard84 (Leonard Brünings) wrote…

Maybe split here into a new test, as the result changes and it is not directly obvious.

Can we do this data-driven, or does it not work/reproduce the problem?

where:
action | result
{ PersonWithOverloadedMethods.perform("null string" as String) } | 'String'

Hm, maybe I didn't think about closures then.
Changed to two data driven methods.

@Vampire
Vampire requested a review from leonard84 April 24, 2020 15:47

@leonard84 leonard84 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 5 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@leonard84
leonard84 merged commit 03818ed into spockframework:master Apr 30, 2020
@Vampire
Vampire deleted the do-not-strip-type-information-from-arguments-in-mocks branch April 30, 2020 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global mocking not working when receiving null on methods with many signatures

2 participants