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

Initializes spies within constructors of a mock instance for the inline mock maker. #2002

Closed
wants to merge 4 commits into from

Conversation

raphw
Copy link
Member

@raphw raphw commented Aug 13, 2020

Doing so, Mockito initializes fields for a spy from within the spy instance's constructor. This avoids using setter reflection on final fields what will no longer work once effectively final fields prohibit setting final fields from outside a constructor.

Fixes #1782 and #1325.

@codecov-commenter
Copy link

codecov-commenter commented Aug 13, 2020

Codecov Report

Merging #2002 into release/3.x will decrease coverage by 0.19%.
The diff coverage is 81.53%.

Impacted file tree graph

@@                Coverage Diff                @@
##             release/3.x    #2002      +/-   ##
=================================================
- Coverage          85.23%   85.04%   -0.20%     
- Complexity          2604     2665      +61     
=================================================
  Files                323      324       +1     
  Lines               7520     7958     +438     
  Branches             899      961      +62     
=================================================
+ Hits                6410     6768     +358     
- Misses               873      925      +52     
- Partials             237      265      +28     
Impacted Files Coverage Δ Complexity Δ
src/main/java/org/mockito/MockedStatic.java 100.00% <ø> (ø) 1.00 <0.00> (ø)
...in/java/org/mockito/internal/MockedStaticImpl.java 78.66% <ø> (ø) 11.00 <0.00> (ø)
.../creation/bytebuddy/SubclassBytecodeGenerator.java 83.47% <0.00%> (-0.70%) 24.00 <0.00> (ø)
...reation/bytebuddy/inject/MockMethodDispatcher.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...nternal/creation/bytebuddy/ByteBuddyMockMaker.java 81.81% <50.00%> (-7.08%) 7.00 <1.00> (+1.00) ⬇️
...nal/configuration/IndependentAnnotationEngine.java 85.00% <71.42%> (ø) 14.00 <7.00> (ø)
...a/org/mockito/internal/MockedConstructionImpl.java 72.22% <72.22%> (ø) 6.00 <6.00> (?)
...rc/main/java/org/mockito/internal/MockitoCore.java 93.18% <72.72%> (-1.86%) 43.00 <2.00> (+2.00) ⬇️
src/main/java/org/mockito/Mockito.java 91.02% <73.33%> (-4.22%) 55.00 <10.00> (+10.00) ⬇️
...l/creation/bytebuddy/InlineByteBuddyMockMaker.java 68.37% <79.39%> (+10.38%) 47.00 <29.00> (+29.00)
... and 10 more

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

@raphw
Copy link
Member Author

raphw commented Aug 15, 2020

Already contained.

@raphw raphw closed this Aug 15, 2020
@raphw raphw deleted the spy-mock branch August 15, 2020 23:15
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.

Spying on ArrayList generates Illegal reflective access warning with Java 11
2 participants