Skip to content

Further Hamcrest to AssertJ migration recipes #357

@timtebeek

Description

@timtebeek

What problem are you trying to solve?

After #355 we already support some ~50 Hamcrest Matcher to AssertJ migrations. Not all Hamcrest Matchers are covered however, for a potentially incomplete (but non-breaking) migration. Below is a quick overview of cases we might want to cover still, depending on how common they are, and the effort needed to convert those automatically.

Sub matchers allOf(Matcher...), anyOf(Matcher...), ...

Matchers that take subsequent matchers as argument are not yet covered, and likely need a dedicated recipe for each case. Here's a likely quick overview of such Matchers:

allOf(Iterable<Matcher<? super T>> matchers)
anyOf(Iterable<Matcher<? super T>> matchers)
both(Matcher<? super LHS> matcher)
either(Matcher<? super LHS> matcher)
everyItem(Matcher<U> itemMatcher)
hasItem(Matcher<? super T> itemMatcher)
hasItems(Matcher<? super T>... itemMatchers)
aMapWithSize(Matcher<? super Integer> sizeMatcher)
hasSize(Matcher<? super Integer> sizeMatcher)
contains(Matcher<? super E> itemMatcher)
contains(Matcher<? super E>... itemMatchers)
containsInAnyOrder(Matcher<? super T>... itemMatchers)
containsInRelativeOrder(Matcher<? super E>... itemMatchers)
iterableWithSize(Matcher<? super Integer> sizeMatcher)
hasEntry(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher)
hasKey(Matcher<? super K> keyMatcher)
hasValue(Matcher<? super V> valueMatcher)
hasToString(Matcher<? super String> toStringMatcher)

More inverted matches with not

There's likely more direct replacement options in AssertJ for some of the inverted not(Matcher) that we don't already cover. Not all will have direct replacements, and for those cases we might need more complicated constructs.

not(Matcher<T> matcher)

Matchers for arrays

array(Matcher<? super T>... elementMatchers)
arrayContaining(List itemMatchers)
arrayContaining(Matcher<? super E>... itemMatchers)
arrayContainingInAnyOrder(Collection itemMatchers)
arrayContainingInAnyOrder(Matcher<? super E>... itemMatchers)
arrayWithSize(Matcher<? super Integer> sizeMatcher)
hasItemInArray(Matcher<? super T> elementMatcher)

Any additional context

There's an additional issue to convert to JUnit Jupiter, which could serve as inspiration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions