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

Fixes #1967: Correctly handle mocks with limited life-cycle in listeners. #1968

Merged
merged 1 commit into from Jul 16, 2020

Conversation

raphw
Copy link
Member

@raphw raphw commented Jul 12, 2020

Due to the limited lifetime of static mocks, they cannot be validated within a Mockito session since they might have expired when the validation is applied. This patch excludes static mocks from all validation. To support static mocks in the regular session validation, we would rather need to trigger the validation upon release of any static mock.

Copy link
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.

It's not clear to me how the test reproduces the issue as reported in #1967 Can we instead copy the code as reported in the issue and add that to our test suite?

@raphw
Copy link
Member Author

raphw commented Jul 12, 2020

It only tests part of the issue. For actually testing it, we would need to run the JUnit tests with the inline mock maker and create subprojects for it. I am going on a two week vacation tomorrow, so I did not want to open that barrel of wine tonight but I validated the working manually. If you have some time, could you add additional subprojects? I validated the runners manually, however.

@TimvdLippe
Copy link
Contributor

Ah okay. I got confused as the commit mentions that the issue is fixed, so that's why I thought we had test the whole scenario. Please go on vacation, we can figure it out later 😄

@codecov-commenter
Copy link

codecov-commenter commented Jul 12, 2020

Codecov Report

Merging #1968 into release/3.x will increase coverage by 0.01%.
The diff coverage is 65.21%.

Impacted file tree graph

@@                Coverage Diff                @@
##             release/3.x    #1968      +/-   ##
=================================================
+ Coverage          85.28%   85.30%   +0.01%     
- Complexity          2591     2594       +3     
=================================================
  Files                322      322              
  Lines               7483     7492       +9     
  Branches             892      895       +3     
=================================================
+ Hits                6382     6391       +9     
  Misses               862      862              
  Partials             239      239              
Impacted Files Coverage Δ Complexity Δ
src/main/java/org/mockito/MockedStatic.java 100.00% <ø> (ø) 1.00 <0.00> (ø)
...in/java/org/mockito/internal/MockedStaticImpl.java 74.66% <0.00%> (-2.05%) 9.00 <0.00> (ø)
...ternal/invocation/finder/AllInvocationsFinder.java 87.50% <0.00%> (-12.50%) 4.00 <0.00> (ø)
...kito/internal/framework/DefaultMockitoSession.java 87.50% <76.92%> (-4.61%) 8.00 <2.00> (ø)
...nternal/configuration/MockAnnotationProcessor.java 88.88% <83.33%> (+18.05%) 11.00 <0.00> (+3.00)
...to/internal/util/concurrent/WeakConcurrentMap.java 41.48% <0.00%> (+2.12%) 11.00% <0.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 05b39bf...e4e7aa9. Read the comment docs.

@raphw
Copy link
Member Author

raphw commented Jul 16, 2020

I added an additional project for the JUnit Jupiter extension and added a JUnit rule for the inline mock maker tests. I hope this should avoid any future regressions.

@raphw raphw merged commit be220bb into release/3.x Jul 16, 2020
@raphw raphw deleted the runner-fix branch July 18, 2020 18:42
ksankeerth added a commit to ksankeerth/shardingsphere that referenced this pull request Jan 30, 2022
In Mocktio 3.4.0, static mocks causes NotAMockException. They are fixed in 3.4.2.
[1] : mockito/mockito#1968
[2]: mockito/mockito#1967
terrymanu pushed a commit to apache/shardingsphere that referenced this pull request Jan 30, 2022
* Fixed test cases of MySQLDataSourcePreparer (Git issue : 14246)

* Changed the mockito version to 3.4.2 (Git issue : 14246)
In Mocktio 3.4.0, static mocks causes NotAMockException. They are fixed in 3.4.2.
[1] : mockito/mockito#1968
[2]: mockito/mockito#1967

* Fixed test MySQLDataSourcePreparerTest (Git issue : 14246)
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

3 participants