Skip to content

Fixes #2489 : Fixed issue related to exceptions thrown from the nested spies#2546

Merged
TimvdLippe merged 2 commits intomockito:mainfrom
andrey-kozel:bugfix/issue-2489
Jan 22, 2022
Merged

Fixes #2489 : Fixed issue related to exceptions thrown from the nested spies#2546
TimvdLippe merged 2 commits intomockito:mainfrom
andrey-kozel:bugfix/issue-2489

Conversation

@andrey-kozel
Copy link
Copy Markdown
Contributor

Description

Fixed issue related to exceptions thrown from the nested spies.

What changed

Behavior of the filtering redundant method calls from stacktrace was changed.
Now it removes only lines that have the same method name and line number.
I've checked the history of this feature, there were two implementations, each one had some minor defects.

The first one. Let assume that we have the next stacktrace:

  • mock1:line1
  • internal calls....
  • mock1:line1
  • mock1:line2
  • internal calls....
  • mock2:line1
  • mock2:line2
  • internal calls....
  • mock2:line2
    This implementation gets difference between current stacktrace and stacktrace from exception, and filters some rows from the beginning. Due to this mock1:line1 was removed in some cases

The second one worked viceversa, it started filtering from the end of the stacktrace before it find the first iteration of the desired. Let assume that we have the next stacktrace:

  • mock1:line1
  • internal calls....
  • mock1:line1
  • mock1:line2
  • internal calls....
  • mock2:line1
  • mock2:line2
  • internal calls....
  • mock2:line2

This lines will be removed:

  • internal calls....
  • mock2:line1
  • mock2:line2
  • internal calls....
  • mock2:line2

In current implementation I'm checking the lines with the same method name and number and remove them from the list, so
from the stack trace provided above only two items will be removed:

  • mock1:line1
  • mock2:line2

I don't have many information about this feature since it contains not so many information, so if I made something wrong, please, give me a clue, how could I fix it :)

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

…e nested spies. Behaviour of the filtering redundant method calls from stacktrace was changed. Now it removes only lines that have the same method name and line number
@TimvdLippe
Copy link
Copy Markdown
Contributor

@andrey-kozel Please run ./gradlew spotlessApply` locally to automatically format all source code

@andrey-kozel
Copy link
Copy Markdown
Contributor Author

@andrey-kozel Please run ./gradlew spotlessApply` locally to automatically format all source code

Done. Thank you!

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 22, 2022

Codecov Report

Merging #2546 (7ec800d) into main (faa6e92) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #2546      +/-   ##
============================================
+ Coverage     86.69%   86.71%   +0.01%     
- Complexity     2782     2784       +2     
============================================
  Files           320      320              
  Lines          8344     8341       -3     
  Branches       1022     1021       -1     
============================================
- Hits           7234     7233       -1     
  Misses          840      840              
+ Partials        270      268       -2     
Impacted Files Coverage Δ
.../internal/creation/bytebuddy/MockMethodAdvice.java 80.28% <100.00%> (+0.40%) ⬆️

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...7ec800d. Read the comment docs.

Copy link
Copy Markdown
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

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.

3 participants