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

Introduce validator for Refaster template collections and tests #43

Merged
merged 43 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d3a2bac
Move `RefasterCheckTest` to `.refastertemplates` package
rickie May 25, 2022
238d91b
Suggestions
Stephan202 May 28, 2022
31ece7e
Alternative suggestion
Stephan202 May 28, 2022
66ae36b
Introduce validator for Refaster template collections and tests
rickie Jan 10, 2022
c896710
Remove validation in `error-prone-contrib`
rickie Mar 9, 2022
73a6b47
Apply suggestions
rickie Mar 21, 2022
42d05d3
Minor improvements and move class
rickie Mar 28, 2022
384de95
Apply suggestions
rickie Mar 28, 2022
be1967f
Add explanation in `RefasterCollectionTestUtilTest.java`
rickie Mar 31, 2022
0e48bdf
First version of README.md
rickie Apr 1, 2022
3aee016
README suggestions
rickie Apr 4, 2022
5b781cf
Minor README tweaks
Badbond Apr 4, 2022
6ebcda1
Global fmt configuration and wrap lines in README
rickie May 21, 2022
79b9e31
Suggestions
Stephan202 May 22, 2022
73381fd
Improve the `RefasterValidateTests` BugPattern
rickie May 23, 2022
f9584eb
Suggestions
Stephan202 May 29, 2022
4995840
Apply feedback
rickie May 31, 2022
22644e9
`s/RefasterValidateTests/RefasterTemplateCollectionValidator`
rickie May 31, 2022
2795daf
Add more happy flow examples
rickie May 31, 2022
b417c10
Post-rebase fix
rickie May 31, 2022
7098ea3
Add Refaster tests for `error-prone-contrib` and introduce `CodeTrans…
rickie Jun 1, 2022
299c6e9
Apply feedback
rickie Jun 1, 2022
8d564de
Suggestions
Stephan202 Jun 1, 2022
a714ddc
As suggested
Stephan202 Jun 2, 2022
35d9f7d
Improvements to make downstream users work
rickie Jun 3, 2022
d672444
Suggestion
Stephan202 Jun 4, 2022
c3f178c
Rename test methods, more honest dependency scoping
Stephan202 Jun 4, 2022
47c862c
Make sure `RefasterCheck` actually runs during the build
Stephan202 Jun 6, 2022
b103881
Handle deserialization failure
Stephan202 Jun 6, 2022
f36df73
Get the build to pass
Stephan202 Jun 6, 2022
47acea7
Post-rebase fixes
Stephan202 Aug 1, 2022
a8bc585
Suggestions
Stephan202 Aug 1, 2022
53ffe2b
Apply feedback and update `README.md`
rickie Aug 4, 2022
b0a8658
Javadoc tweak
Stephan202 Aug 4, 2022
1dcd659
Merge branch 'master' into rossendrijver/junit_extension_refaster_tests
Stephan202 Aug 7, 2022
93785fb
Semi-related fix
Stephan202 Aug 7, 2022
b8e3fd8
Suggestions (partial README review)
Stephan202 Aug 9, 2022
dca5a6b
Apply subset of README.md suggestions
Badbond Aug 9, 2022
f60da11
PSM-1299 Partially apply feedback from Pieter
rickie Aug 9, 2022
4bcd8fb
Pieter's suggestions
Stephan202 Aug 9, 2022
b514ad9
Suggestions
Stephan202 Aug 10, 2022
9b7beb3
Apply Pieter's suggestion
Stephan202 Aug 10, 2022
fa0f49a
Merge branch 'master' into rossendrijver/junit_extension_refaster_tests
Stephan202 Aug 10, 2022
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
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