-
Notifications
You must be signed in to change notification settings - Fork 39
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
Introduce assorted Iterator
and Iterable
Refaster rules
#1487
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change goes towards resolving #1088.
// XXX: In practice this rule isn't very useful, as it only matches invocations of | ||
// `assertThat(E)`. In most cases a more specific overload of `assertThat` is invoked, in which | ||
// case this rule won't match. Look into a more robust approach. | ||
static final class AssertThatIterableHasOneElementEqualTo<S, E extends S> { | ||
@BeforeTemplate | ||
ObjectAssert<S> before(Iterable<S> iterable, E element) { | ||
return assertThat(Iterables.getOnlyElement(iterable)).isEqualTo(element); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
IterableAssert<S> after(Iterable<S> iterable, E element) { | ||
return assertThat(iterable).containsExactly(element); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from AssertJRules
, mostly to keep track of this caveat.
// XXX: This overload is here because `assertThat` has an overload for `Comparable` types. | ||
// Unfortunately this still doesn't convince Refaster to match this rule in the context of | ||
// Comparable types. Figure out why! Note that this also affects the `AssertThatOptional` rule. | ||
static final class AssertThatIterableHasOneComparableElementEqualTo< | ||
S extends Comparable<? super S>, T extends S> { | ||
@BeforeTemplate | ||
AbstractComparableAssert<?, S> before(Iterable<S> iterable, T element) { | ||
return assertThat(Iterables.getOnlyElement(iterable)).isEqualTo(element); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
IterableAssert<S> after(Iterable<S> iterable, T element) { | ||
return assertThat(iterable).containsExactly(element); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped this variant, since in practice it added little.
Looks good. No mutations were possible for these changes. |
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📁
Validated that these changes do not impact the integration tests. |
Suggested commit message: