Return completed futures for unstubbed Future/CompletionStage in ReturnsEmptyValues#3727
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3727 +/- ##
=========================================
Coverage 86.45% 86.45%
- Complexity 2984 2987 +3
=========================================
Files 341 341
Lines 9030 9032 +2
Branches 1111 1112 +1
=========================================
+ Hits 7807 7809 +2
Misses 942 942
Partials 281 281 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@TimvdLippe |
TimvdLippe
left a comment
There was a problem hiding this comment.
1 nit, the rest LGTM!
| } | ||
|
|
||
| @Test | ||
| public void returnsCompletedFuture_forFuture() throws Exception { |
There was a problem hiding this comment.
These tests look good to me. Rather than a separate test suite, can you move them into mockito-core/src/test/java/org/mockito/internal/stubbing/defaultanswers/ReturnsEmptyValuesTest.java instead?
There was a problem hiding this comment.
Done, I’ve moved the tests into ReturnsEmptyValuesTest. Thanks for the review!
|
Looks like this is a breaking change, so maybe worth noting in the release notes (although the minor version bump might already indicate that). |
Fixes #3724
Updated
ReturnsEmptyValues#returnValueForso that for return typesFuture,CompletableFuture, andCompletionStage, Mockito now returnsCompletableFuture.completedFuture(null)instead ofnull.Tests
ReturnsEmptyValuesFutureTestto verify the new default behavior:Future<String>returns a completed future withnullresult.CompletableFuture<Void>returns a completed future that can be joined without exceptions.CompletionStage<Integer>returns a completed stage that can be safely chained.Checklist
including project members to get a better picture of the change
commit is meaningful and help the people that will explore a change in 2 years
./gradlew spotlessApplyfor auto-formatting)Fixes #<issue number>in the description if relevantFixes #<issue number>if relevant