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

PSF-9432 Introduce JUnit Arguments Refaster Rule #3

Merged
merged 4 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion error-prone-contrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
werli marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package tech.picnic.errorprone.refastertemplates;

import static org.junit.jupiter.params.provider.Arguments.arguments;

import com.google.errorprone.refaster.ImportPolicy;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import com.google.errorprone.refaster.annotation.Repeated;
import com.google.errorprone.refaster.annotation.UseImportPolicy;
import org.junit.jupiter.params.provider.Arguments;

/**
* Refaster templates which replaces argument creation for parametrized JUnit tests using {@link
* Arguments#of} with statically imported {@link Arguments#arguments} calls.
*/
werli marked this conversation as resolved.
Show resolved Hide resolved
final class JUnitArgumentsTemplates {
private JUnitArgumentsTemplates() {}

/** Prefer statically imported {@link Arguments#arguments} over {@link Arguments#of} calls. */
static final class ArgumentsReplace<T> {
@BeforeTemplate
Arguments before(@Repeated T objs) {
return Arguments.of(objs);
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
Arguments after(@Repeated T objs) {
return arguments(objs);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public final class RefasterCheckTest {
"ImmutableSortedMultiset",
"ImmutableSortedSet",
"IntStream",
"JUnitArguments",
"LongStream",
"MapEntry",
"Mockito",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package tech.picnic.errorprone.bugpatterns;

import java.util.stream.Stream;
import org.junit.jupiter.params.provider.Arguments;

final class JUnitTemplatesTest implements RefasterTemplateTestCase {
Arguments testSingle() {
return Arguments.of("foo");
}

Arguments testMultiple() {
return Arguments.of(1, "foo", 2, "bar");
}

Stream<Arguments> testSingleInStream() {
return Stream.of(Arguments.of("foo"));
}

Stream<Arguments> testMultipleInStream() {
return Stream.of(Arguments.of(1, "foo", 2, "bar"));
}
werli marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package tech.picnic.errorprone.bugpatterns;

import static org.junit.jupiter.params.provider.Arguments.arguments;

import java.util.stream.Stream;
import org.junit.jupiter.params.provider.Arguments;

final class JUnitTemplatesTest implements RefasterTemplateTestCase {
Arguments testSingle() {
return arguments("foo");
}

Arguments testMultiple() {
return arguments(1, "foo", 2, "bar");
}

Stream<Arguments> testSingleInStream() {
return Stream.of(arguments("foo"));
}

Stream<Arguments> testMultipleInStream() {
return Stream.of(arguments(1, "foo", 2, "bar"));
}
}