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

One more assertj refaster #889

Closed
wants to merge 2 commits into from
Closed

One more assertj refaster #889

wants to merge 2 commits into from

Conversation

iamdanfox
Copy link
Contributor

Before this PR

I saw a codebase with exactly this before state, which can easily be replaced with a version that produces a nicer error message!

After this PR

==COMMIT_MSG==
refaster replacement for assertj hasSize(foo.size) -> hasSameSizeAs
==COMMIT_MSG==

Possible downsides?

n/a

@iamdanfox iamdanfox requested a review from a team as a code owner September 24, 2019 22:28
public final class AssertjCollectionHasSameSizeAs<T,U> {

@BeforeTemplate
IterableAssert<T> before(IterableAssert<T> assertInProgress, List<U> expected) {
Copy link
Contributor

@carterkozak carterkozak Sep 24, 2019

Choose a reason for hiding this comment

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

List can be Collection

Copy link
Contributor Author

@iamdanfox iamdanfox Sep 24, 2019

Choose a reason for hiding this comment

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

Iterable doesn't have the .size() method, so I used Collection initially, but I can't even get my test to pass with this :/

Currently dying in RefasterScanner - think I may have borked my IDE a bit. Might try again tomorrow!

image

Copy link
Contributor

Choose a reason for hiding this comment

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

I think refaster requires an exact match on the assert type returned by AssertThat:

This should work:

@BeforeTemplate
ListAssert<T> before(ListAssert<T> assertInProgress, Collection<U> expected) {
    return assertInProgress.hasSize(expected.size());
}

However it won't apply to collections or iterable targerrs

Copy link
Contributor

Choose a reason for hiding this comment

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

Based on #881 it may or may not work in java 11...

@iamdanfox
Copy link
Contributor Author

Closing out because I can't get this to work and it doesn't seem that high value.

@iamdanfox iamdanfox closed this Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants