GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fixes #2201 : Fixed checking of declared exceptions. by andrey-kozel · Pull Request #2547 · mockito/mockito

Conversation

@andrey-kozel

@andrey-kozel andrey-kozel commented Jan 23, 2022

Copy link
Copy Markdown
Contributor

Fixed checking of declared exceptions. In case when parent contains throws keyword on its method and child overrides this method removing throws, it should be possible to mock throwing exception from child

Description.

Lets assume that we have the following interface

public interface Foo {
        void bar() throws IOException; 
    }

And we have class that extends the interface, removing throws exception

public class Baz implements Foo {
        @Override
        public void bar() {
            
        }
    }

When we trying to mock exception throw, it wasn't possible

Foo mock = Mockito.spy(new Baz());
Mockito.doThrow(new IOException())
    .when(mock)
    .bar();

Now this behavior fixed

Checklist

  • Read the contributing guide
  • PR should be motivated, i.e. what does it fix, why, and if relevant how
  • If possible / relevant include an example in the description, that could help all readers
    including project members to get a better picture of the change
  • Avoid other runtime dependencies
  • Meaningful commit history ; intention is important please rebase your commit history so that each
    commit is meaningful and help the people that will explore a change in 2 years
  • The pull request follows coding style
  • Mention Fixes #<issue number> in the description if relevant
  • At least one commit should mention Fixes #<issue number> if relevant

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Andrey Kozel
Fixes mockito#2201 : Fixed checking of declared exceptions. In case w…
d86cb6b
…hen parent contains throws keyword on its method and child overrides this method removing throws, it should be possible to mock throwing exception from child
ruslanzianevich
ruslanzianevich approved these changes Jan 23, 2022
View reviewed changes
@codecov-commenter

codecov-commenter commented Jan 23, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #2547 (81c71a8) into main (faa6e92) will decrease coverage by 0.15%.
The diff coverage is 100.00%.

❗ Current head 81c71a8 differs from pull request most recent head 792da83. Consider uploading reports for the commit 792da83 to get more accurate results
Impacted file tree graph

@@             Coverage Diff              @@
##               main    #2547      +/-   ##
============================================
- Coverage     86.69%   86.54%   -0.16%     
- Complexity     2782     2790       +8     
============================================
  Files           320      320              
  Lines          8344     8359      +15     
  Branches       1022     1023       +1     
============================================
  Hits           7234     7234              
- Misses          840      857      +17     
+ Partials        270      268       -2     
Impacted Files Coverage Δ
.../internal/creation/bytebuddy/MockMethodAdvice.java 80.28% <100.00%> (+0.40%) ⬆️
...kito/internal/stubbing/answers/InvocationInfo.java 100.00% <100.00%> (ø)
...ito/internal/creation/proxy/MethodHandleProxy.java 54.54% <0.00%> (-45.46%) ⬇️
...ckito/internal/creation/proxy/ProxyRealMethod.java 42.85% <0.00%> (-28.58%) ⬇️

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 faa6e92...792da83. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aglumova

aglumova commented Jan 24, 2022

Copy link
Copy Markdown

WOW Amazing!!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

TimvdLippe
TimvdLippe suggested changes Jan 24, 2022
View reviewed changes

@TimvdLippe TimvdLippe left a comment

Copy link
Copy Markdown
Contributor

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.

Thanks for the PR! I think we are nearly there, but there are some more edge cases we need to handle.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/mockito/internal/stubbing/answers/InvocationInfo.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@andrey-kozel
andrey-kozel force-pushed the feature/issue-2201 branch from 0e0e577 to 77f7dbd Compare January 26, 2022 19:59
@andrey-kozel

andrey-kozel commented Jan 26, 2022

Copy link
Copy Markdown
Contributor Author

Thanks for the PR! I think we are nearly there, but there are some more edge cases we need to handle.

Thank you for the comment. I've extended checking for exceptions and added tests for all the cases you've mentioned

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrey-kozel
andrey-kozel force-pushed the feature/issue-2201 branch from 77f7dbd to 66146e6 Compare January 26, 2022 20:00
Andrey Kozel
Fixes mockito#2201 : Code review fixes
792da83
@andrey-kozel
andrey-kozel force-pushed the feature/issue-2201 branch from 66146e6 to 792da83 Compare January 26, 2022 20:04
@andrey-kozel
andrey-kozel requested a review from TimvdLippe January 26, 2022 20:16
TimvdLippe
TimvdLippe approved these changes Jan 26, 2022
View reviewed changes

@TimvdLippe TimvdLippe left a comment

Copy link
Copy Markdown
Contributor

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.

Nice work and regression tests, thanks! 🎉

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@TimvdLippe
TimvdLippe merged commit f6ce1bb into mockito:main Jan 26, 2022
@theaspect theaspect mentioned this pull request Mar 15, 2022
Bump mockito-core from 4.3.1 to 4.4.0 theaspect/sandbox#41
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

2 more reviewers
@TimvdLippe TimvdLippe TimvdLippe approved these changes
@ruslanzianevich ruslanzianevich ruslanzianevich approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@andrey-kozel @codecov-commenter @aglumova @TimvdLippe @ruslanzianevich
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.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.