Skip to content
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

Allow delegating to non-public methods for AdditionalAnswers#delegatesTo #1536

Merged
merged 2 commits into from
Nov 20, 2018

Conversation

li-wjohnson
Copy link
Contributor

Fixes an issue where doing "delegatesTo(new AnonymousClass() {})" would cause an IllegalAccessException, and other access-related issues.

(See #1535 - Sorry, wasn't aware that you can't change the PR source branch.)

Fixes an issue where doing "delegatesTo(new AnonymousClass() {})" would cause an IllegalAccessException, and other access-related issues.
@codecov-io
Copy link

codecov-io commented Nov 20, 2018

Codecov Report

Merging #1536 into release/2.x will decrease coverage by 0.01%.
The diff coverage is 66.66%.

Impacted file tree graph

@@                Coverage Diff                @@
##             release/2.x    #1536      +/-   ##
=================================================
- Coverage          88.59%   88.58%   -0.02%     
  Complexity          2402     2402              
=================================================
  Files                299      299              
  Lines               6041     6044       +3     
  Branches             734      734              
=================================================
+ Hits                5352     5354       +2     
- Misses               510      511       +1     
  Partials             179      179
Impacted Files Coverage Δ Complexity Δ
...l/stubbing/defaultanswers/ForwardsInvocations.java 95.23% <66.66%> (-4.77%) 8 <0> (ø)

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 5a0269c...2a68497. Read the comment docs.

@li-wjohnson
Copy link
Contributor Author

Oof, what do I do with code coverage check on the "catch (SecurityException ignore)" line?

Copy link
Member

@mockitoguy mockitoguy left a comment

Choose a reason for hiding this comment

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

I like the change a lot. Can you help us put together an e2e test?


import static org.junit.Assert.assertEquals;

public class ForwardsInvocationsTest extends TestBase {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this test? Does this test improves coverage on top of the existing ForwardsInvocationsTest?

Copy link
Contributor

Choose a reason for hiding this comment

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

The original problem was the inability to mock anonymous classes. In line 21 of this test, an anonymous class is created. I think this is therefore testing the appropriate codepath?

Copy link
Member

Choose a reason for hiding this comment

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

It is. Please disregard my comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, our comments were cross-posted. I saw your reply the second I posted my comment 😛

@@ -40,6 +40,11 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
}

Object[] rawArguments = ((Invocation) invocation).getRawArguments();
try {
delegateMethod.setAccessible(true);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add an e2e user test? Can you put together a test class that shows that without this change Mockito indeed throws access exceptions?

@mockitoguy
Copy link
Member

Please ignore my earlier comment, I can see the new test is doing what we need to do!

We prefer user e2e tests for such features
@mockitoguy
Copy link
Member

I reworked the test a little bit and will merge once the build is happy. Thank you @li-wjohnson!

@mockitoguy mockitoguy merged commit af2036b into mockito:release/2.x Nov 20, 2018
Copy link
Contributor

@bric3 bric3 left a comment

Choose a reason for hiding this comment

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

Cool thanks for this contribution

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.

None yet

5 participants