mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
PSF-9432 Introduce JUnit Arguments Refaster rule (#3)
This commit is contained in:
@@ -130,7 +130,7 @@
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<scope>test</scope>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
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 related to JUnit expressions and statements. */
|
||||
final class JUnitTemplates {
|
||||
private JUnitTemplates() {}
|
||||
|
||||
/** Prefer statically imported {@link Arguments#arguments} over {@link Arguments#of} calls. */
|
||||
static final class ArgumentsEnumeration<T> {
|
||||
@BeforeTemplate
|
||||
Arguments before(@Repeated T objects) {
|
||||
return Arguments.of(objects);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
|
||||
Arguments after(@Repeated T objects) {
|
||||
return arguments(objects);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@ public final class RefasterCheckTest {
|
||||
"ImmutableSortedMultiset",
|
||||
"ImmutableSortedSet",
|
||||
"IntStream",
|
||||
"JUnit",
|
||||
"LongStream",
|
||||
"MapEntry",
|
||||
"Mockito",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
final class JUnitTemplatesTest implements RefasterTemplateTestCase {
|
||||
ImmutableSet<Arguments> testArgumentsEnumeration() {
|
||||
return ImmutableSet.of(
|
||||
Arguments.of("foo"), Arguments.of(1, "foo", 2, "bar"), Arguments.of(new Object()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
final class JUnitTemplatesTest implements RefasterTemplateTestCase {
|
||||
ImmutableSet<Arguments> testArgumentsEnumeration() {
|
||||
return ImmutableSet.of(
|
||||
arguments("foo"), arguments(1, "foo", 2, "bar"), arguments(new Object()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user