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 #1578: outer class mocks unavailable from inner class #1596

Merged
merged 1 commit into from Jan 31, 2019
Merged

Fixes #1578: outer class mocks unavailable from inner class #1596

merged 1 commit into from Jan 31, 2019

Conversation

mouyang
Copy link
Contributor

@mouyang mouyang commented Jan 20, 2019

I opened issue #1578 a few weeks ago that went without an correspondence, so I apologize if submitting a PR isn't the ideal method of moving this issue forward. However I am hoping I can get this fix incorporated into an official version without implementing temporary workarounds.

The PR should clearly show the issue I am trying to fix, but I had to introduce a testCompile snapshot dependency. The dependent project has a fix required to demonstrate the issue within Mockito but it unfortunately has not been incorporated into an official release, and I can't think of another way to reproduce the issue. I have contacted the owner of the dependent project but I haven't received a response from them either.

I am looking for guidance on next steps for what I believe to be regression (reported to be working in #353). The only other solution I can think of is to merge this without a unit test but I highly doubt that is desirable.

Git Commit Message

  • problem - JUnitRule detects an unfinished mocking session when an inner class is detected
  • fix - if a MockitoSession has been established for JUnitRule, then use that and init mocks of the inner class.
  • tests - within an inner class ... ensure mocks are accessible, override outer class values when desired, retain original values if not overwritten
  • demonstrated with de.bechte.junit:junit-hierarchicalcontextrunner:4.12.2-SNAPSHOT

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.

The fix seems fine, but we need some additional work for the test. Could you also merge release/2.x in here, as we fixed an issue with Java 11 there?

build.gradle Outdated Show resolved Hide resolved
- Problem - JUnitRule detects an unfinished mocking session when the apply method is invoked more than once.  This commonly happens with Runners that enable developers to write nested test classes.
- Fix - If a MockitoSession has been established for JUnitRule, then use that and initialize any new mocks (typically from a nested test class).
- Test - Instantiate one @rule and assign it to a second one.  This will simulate the apply method being invoked more than once without introducing a new test dependency.
@codecov-io
Copy link

codecov-io commented Jan 31, 2019

Codecov Report

Merging #1596 into release/2.x will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@                Coverage Diff                @@
##             release/2.x    #1596      +/-   ##
=================================================
+ Coverage          87.54%   87.54%   +<.01%     
  Complexity          2437     2437              
=================================================
  Files                300      300              
  Lines               6255     6257       +2     
  Branches             775      776       +1     
=================================================
+ Hits                5476     5478       +2     
  Misses               582      582              
  Partials             197      197
Impacted Files Coverage Δ Complexity Δ
...ain/java/org/mockito/internal/junit/JUnitRule.java 96.29% <100%> (+0.29%) 4 <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 7a64410...d9bdfe6. Read the comment docs.

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.

Thanks!

@TimvdLippe TimvdLippe merged commit 4affa66 into mockito:release/2.x Jan 31, 2019
SamBarker pushed a commit to SamBarker/mockito that referenced this pull request Feb 25, 2019
…ckito#1596)

- Problem - JUnitRule detects an unfinished mocking session when the apply method is invoked more than once.  This commonly happens with Runners that enable developers to write nested test classes.
- Fix - If a MockitoSession has been established for JUnitRule, then use that and initialize any new mocks (typically from a nested test class).
- Test - Instantiate one @rule and assign it to a second one.  This will simulate the apply method being invoked more than once without introducing a new test dependency.
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