Skip to content

Commit

Permalink
Introduce utilities to validate Refaster template collections (#43)
Browse files Browse the repository at this point in the history
The `Refaster` check is now located in the new `refaster-runner` Maven module.

The new `refaster-test-support` module exposes
`RefasterTemplateCollection#validate`, which for a given template collection
validates:
- That there exist corresponding `*Test{Input,Output}.java` files.
- That each template is exercised by precisely one method in these files.
  • Loading branch information
rickie authored Aug 10, 2022
1 parent ef562c1 commit b06945b
Show file tree
Hide file tree
Showing 131 changed files with 1,387 additions and 281 deletions.
17 changes: 3 additions & 14 deletions error-prone-contrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>refaster-compiler</artifactId>
<!-- This dependency is declared only as a hint to Maven that
compilation depends on it; see the `maven-compiler-plugin`'s
`annotationProcessorPaths` configuration below. -->
<artifactId>refaster-support</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>refaster-support</artifactId>
<artifactId>refaster-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down Expand Up @@ -205,15 +203,6 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<configuration>
<additionalSourceDirectories>
<additionalSourceDirectory>${basedir}/src/test/resources</additionalSourceDirectory>
</additionalSourceDirectories>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Optional<T> after(Iterator<T> it) {
/** Prefer {@link Optional#filter(Predicate)} over usage of the ternary operator. */
// XXX: This rule may introduce a compilation error: the `test` expression may reference a
// non-effectively final variable, which is not allowed in the replacement lambda expression.
// Maybe our RefasterCheck should test `compilesWithFix`?
// Maybe our `Refaster` checker should test `compilesWithFix`?
abstract static class TernaryOperatorOptionalPositiveFiltering<T> {
@Placeholder
abstract boolean test(T value);
Expand All @@ -133,7 +133,7 @@ Optional<T> after(T input) {
/** Prefer {@link Optional#filter(Predicate)} over usage of the ternary operator. */
// XXX: This rule may introduce a compilation error: the `test` expression may reference a
// non-effectively final variable, which is not allowed in the replacement lambda expression.
// Maybe our RefasterCheck should test `compilesWithFix`?
// Maybe our `Refaster` checker should test `compilesWithFix`?
abstract static class TernaryOperatorOptionalNegativeFiltering<T> {
@Placeholder
abstract boolean test(T value);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package tech.picnic.errorprone.refastertemplates;

import static java.util.function.Predicate.not;

import com.google.common.collect.ImmutableSet;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import tech.picnic.errorprone.refaster.test.RefasterTemplateCollection;

final class RefasterTemplatesTest {
/** The names of all Refaster template groups defined in this module. */
private static final ImmutableSet<Class<?>> TEMPLATE_COLLECTIONS =
ImmutableSet.of(
AssertJTemplates.class,
AssertJBigDecimalTemplates.class,
AssertJBigIntegerTemplates.class,
AssertJBooleanTemplates.class,
AssertJByteTemplates.class,
AssertJCharSequenceTemplates.class,
AssertJDoubleTemplates.class,
AssertJEnumerableTemplates.class,
AssertJFloatTemplates.class,
AssertJIntegerTemplates.class,
AssertJLongTemplates.class,
AssertJNumberTemplates.class,
AssertJMapTemplates.class,
AssertJObjectTemplates.class,
AssertJOptionalTemplates.class,
AssertJShortTemplates.class,
AssertJStringTemplates.class,
AssertJThrowingCallableTemplates.class,
AssortedTemplates.class,
BigDecimalTemplates.class,
CollectionTemplates.class,
ComparatorTemplates.class,
DoubleStreamTemplates.class,
EqualityTemplates.class,
ImmutableListTemplates.class,
ImmutableListMultimapTemplates.class,
ImmutableMapTemplates.class,
ImmutableMultisetTemplates.class,
ImmutableSetTemplates.class,
ImmutableSetMultimapTemplates.class,
ImmutableSortedMapTemplates.class,
ImmutableSortedMultisetTemplates.class,
ImmutableSortedSetTemplates.class,
IntStreamTemplates.class,
JUnitTemplates.class,
LongStreamTemplates.class,
MapEntryTemplates.class,
MockitoTemplates.class,
MultimapTemplates.class,
NullTemplates.class,
OptionalTemplates.class,
PrimitiveTemplates.class,
ReactorTemplates.class,
RxJava2AdapterTemplates.class,
StreamTemplates.class,
StringTemplates.class,
TestNGToAssertJTemplates.class,
TimeTemplates.class,
WebClientTemplates.class);

// XXX: Create a JUnit extension to automatically discover the template collections in a given
// context to make sure the list is exhaustive.
private static Stream<Arguments> validateTemplateCollectionTestCases() {
// XXX: Drop the filter once we have added tests for AssertJ! We can then also replace this
// method with `@ValueSource(classes = {...})`.
return TEMPLATE_COLLECTIONS.stream()
.filter(not(AssertJTemplates.class::equals))
.map(Arguments::arguments);
}

@MethodSource("validateTemplateCollectionTestCases")
@ParameterizedTest
void validateTemplateCollection(Class<?> clazz) {
RefasterTemplateCollection.validate(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.collect.ImmutableSet;
import java.math.BigDecimal;
import org.assertj.core.api.AbstractBigDecimalAssert;
import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase;

final class AssertJBigDecimalTemplatesTest implements RefasterTemplateTestCase {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.collect.ImmutableSet;
import java.math.BigDecimal;
import org.assertj.core.api.AbstractBigDecimalAssert;
import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase;

final class AssertJBigDecimalTemplatesTest implements RefasterTemplateTestCase {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.collect.ImmutableSet;
import java.math.BigInteger;
import org.assertj.core.api.AbstractBigIntegerAssert;
import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase;

final class AssertJBigIntegerTemplatesTest implements RefasterTemplateTestCase {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.collect.ImmutableSet;
import java.math.BigInteger;
import org.assertj.core.api.AbstractBigIntegerAssert;
import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase;

final class AssertJBigIntegerTemplatesTest implements RefasterTemplateTestCase {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.google.common.collect.ImmutableSet;
import org.assertj.core.api.AbstractBooleanAssert;
import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase;

final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase {
AbstractBooleanAssert<?> testAbstractBooleanAssertIsEqualTo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.google.common.collect.ImmutableSet;
import org.assertj.core.api.AbstractBooleanAssert;
import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase;

final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase {
AbstractBooleanAssert<?> testAbstractBooleanAssertIsEqualTo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.google.common.collect.ImmutableSet;
import org.assertj.core.api.AbstractByteAssert;
import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase;

final class AssertJByteTemplatesTest implements RefasterTemplateTestCase {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.google.common.collect.ImmutableSet;
import org.assertj.core.api.AbstractByteAssert;
import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase;

final class AssertJByteTemplatesTest implements RefasterTemplateTestCase {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.google.common.collect.ImmutableSet;
import org.assertj.core.api.AbstractAssert;
import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase;

final class AssertJCharSequenceTemplatesTest implements RefasterTemplateTestCase {
void testAssertThatCharSequenceIsEmpty() {
Expand Down
Loading

0 comments on commit b06945b

Please sign in to comment.