-
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
Extend {Is,Non}NullFunction
Refaster rules
#1494
Conversation
Looks good. No mutations were possible for these changes. |
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.
Tnx @werli! I added a commit. Suggested commit message:
Extend `{Is,Non}NullFunction` Refaster rules (#1494)
While there, simplify the associated tests.
@@ -111,7 +112,7 @@ Predicate<T> after() { | |||
static final class NonNullFunction<T> { | |||
@BeforeTemplate | |||
Predicate<T> before() { | |||
return o -> o != null; | |||
return Refaster.anyOf(o -> o != null, not(Objects::isNull)); |
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.
Nice, three occurrences of this in the internal code base.
import java.util.stream.Stream; | ||
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; | ||
|
||
final class NullRulesTest implements RefasterRuleCollectionTestCase { | ||
@Override | ||
public ImmutableSet<Object> elidedTypesAndStaticImports() { | ||
return ImmutableSet.of(MoreObjects.class, Optional.class); | ||
return ImmutableSet.of(MoreObjects.class, Optional.class, Predicate.class, not(null)); |
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.
Looks like we can omit Predicate
here :)
long testIsNullFunction() { | ||
return Stream.of("foo").filter(s -> s == null).count(); | ||
ImmutableSet<Long> testIsNullFunction() { | ||
return ImmutableSet.of( | ||
Stream.of("foo").filter(s -> s == null).count(), | ||
Stream.of("bar").filter(not(Objects::nonNull)).count()); | ||
} | ||
|
||
long testNonNullFunction() { | ||
return Stream.of("foo").filter(s -> s != null).count(); | ||
ImmutableSet<Long> testNonNullFunction() { | ||
return ImmutableSet.of( | ||
Stream.of("foo").filter(s -> s != null).count(), | ||
Stream.of("bar").filter(not(Objects::isNull)).count()); | ||
} |
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.
I see that these tests were a bit more complicated than how we usually write them; will use this opportunity to simplify.
@@ -98,7 +99,7 @@ T after(T object, Supplier<S> supplier) { | |||
static final class IsNullFunction<T> { |
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.
Let's also update the associated comments.
Looks good. No mutations were possible for these changes. |
Quality Gate passedIssues Measures |
Pretty trivial extension after I saw this construct in the wild.
Suggested commit message: