Skip to content

Conversation

@Woongi9
Copy link
Contributor

@Woongi9 Woongi9 commented Sep 18, 2025

Fixes #3724

Updated ReturnsEmptyValues#returnValueFor so that for return types
Future, CompletableFuture, and CompletionStage, Mockito now returns
CompletableFuture.completedFuture(null) instead of null.

Tests

  • Added ReturnsEmptyValuesFutureTest to verify the new default behavior:
    • Future<String> returns a completed future with null result.
    • CompletableFuture<Void> returns a completed future that can be joined without exceptions.
    • CompletionStage<Integer> returns a completed stage that can be safely chained.

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 (run ./gradlew spotlessApply for auto-formatting)
  • Mention Fixes #<issue number> in the description if relevant
  • At least one commit should end with Fixes #<issue number> if relevant

@codecov-commenter
Copy link

codecov-commenter commented Sep 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.45%. Comparing base (e6682a3) to head (d3cac6e).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Woongi9 Woongi9 marked this pull request as draft September 22, 2025 00:32
@Woongi9 Woongi9 marked this pull request as ready for review September 22, 2025 00:32
@Woongi9
Copy link
Contributor Author

Woongi9 commented Sep 27, 2025

@TimvdLippe
Reviews and feedback are welcome — I’ll be happy to fix anything needed.

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.

1 nit, the rest LGTM!

}

@Test
public void returnsCompletedFuture_forFuture() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, I’ve moved the tests into ReturnsEmptyValuesTest. Thanks for the review!

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 2503dd1 into mockito:main Sep 27, 2025
19 checks passed
@honnix
Copy link

honnix commented Dec 11, 2025

Looks like this is a breaking change, so maybe worth noting in the release notes (although the minor version bump might already indicate that).

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.

Future<void> methods on mocks throw "type 'Null' is not a subtype of type 'Future<void>'"

4 participants