Skip to content

Add Hamcrest to AssertJ recipes for hasProperty, everyItem, and hasItem(Matcher)#916

Merged
timtebeek merged 3 commits intomainfrom
timtebeek/fix-issue-915
Feb 23, 2026
Merged

Add Hamcrest to AssertJ recipes for hasProperty, everyItem, and hasItem(Matcher)#916
timtebeek merged 3 commits intomainfrom
timtebeek/fix-issue-915

Conversation

@timtebeek
Copy link
Member

@timtebeek timtebeek commented Feb 23, 2026

Summary

  • Fixes Hamcrest to AssertJ unhandled cases (instanceOf, hasProperty and hasItem) #915 by adding three new recipes to handle previously unhandled Hamcrest matchers that were preventing full migration to AssertJ:

  • HamcrestHasPropertyToAssertJ: Converts hasProperty() to AssertJ's hasFieldOrProperty() or hasFieldOrPropertyWithValue()

  • HamcrestEveryItemToAssertJ: Converts everyItem() to hasOnlyElementsOfType() for instanceOf matchers or allSatisfy() for general matchers

  • HamcrestHasItemMatcherToAssertJ: Converts hasItem(Matcher) to hasAtLeastOneElementOfType() for instanceOf matchers or anySatisfy() for general matchers

All three recipes support optional reason arguments and properly handle import management.

Test plan

  • All 11 new tests pass (3 test classes with various scenarios)
  • All existing hamcrest migration tests continue to pass
  • Recipes are integrated into the MigrateHamcrestToAssertJ composite recipe

…em(Matcher)

Fixes #915 by adding three new recipes to handle previously unhandled Hamcrest matchers:
- HamcrestHasPropertyToAssertJ: converts hasProperty() to hasFieldOrProperty() or hasFieldOrPropertyWithValue()
- HamcrestEveryItemToAssertJ: converts everyItem() to hasOnlyElementsOfType() or allSatisfy()
- HamcrestHasItemMatcherToAssertJ: converts hasItem(Matcher) to hasAtLeastOneElementOfType() or anySatisfy()

Each recipe handles optional reason arguments and includes comprehensive tests.
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Feb 23, 2026
@timtebeek timtebeek merged commit a850e44 into main Feb 23, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Feb 23, 2026
@timtebeek timtebeek deleted the timtebeek/fix-issue-915 branch February 23, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Hamcrest to AssertJ unhandled cases (instanceOf, hasProperty and hasItem)

1 participant