Skip to content

Commit de7732d

Browse files
committed
Everything that gets passed to StepHarness now gets round-tripped.
1 parent 13fbf78 commit de7732d

File tree

3 files changed

+6
-48
lines changed

3 files changed

+6
-48
lines changed

testlib/src/main/java/com/diffplug/spotless/StepHarness.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.assertj.core.api.Assertions;
2727

2828
/** An api for testing a {@code FormatterStep} that doesn't depend on the File path. DO NOT ADD FILE SUPPORT TO THIS, use {@link StepHarnessWithFile} if you need that. */
29-
public class StepHarness extends StepHarnessBase<StepHarness> {
29+
public class StepHarness extends StepHarnessBase {
3030
private StepHarness(Formatter formatter) {
3131
super(formatter);
3232
}

testlib/src/main/java/com/diffplug/spotless/StepHarnessBase.java

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,67 +15,25 @@
1515
*/
1616
package com.diffplug.spotless;
1717

18-
import java.util.Locale;
1918
import java.util.Objects;
20-
import java.util.Set;
2119

2220
import org.assertj.core.api.Assertions;
2321

24-
class StepHarnessBase<T extends StepHarnessBase<?>> implements AutoCloseable {
22+
class StepHarnessBase implements AutoCloseable {
2523
private final Formatter formatter;
26-
private Formatter roundTripped;
27-
private boolean supportsRoundTrip = false;
2824

2925
protected StepHarnessBase(Formatter formatter) {
3026
this.formatter = Objects.requireNonNull(formatter);
31-
if (formatter.getSteps().size() == 1) {
32-
// our goal is for everything to be roundtrip serializable
33-
// the steps to get there are
34-
// - make every individual step round-trippable
35-
// - make the other machinery (Formatter, LineEnding, etc) round-trippable
36-
// - done!
37-
//
38-
// Right now, we're still trying to get each and every single step to be round-trippable.
39-
// You can help by add a test below, make sure that the test for that step fails, and then
40-
// make the test pass. `FormatterStepEqualityOnStateSerialization` is a good base class for
41-
// easily converting a step to round-trip serialization while maintaining easy and concise
42-
// equality code.
43-
String onlyStepName = formatter.getSteps().get(0).getName();
44-
if (onlyStepName.startsWith("indentWith")) {
45-
supportsRoundTrip = true;
46-
} else if (onlyStepName.equals("diktat")) {
47-
supportsRoundTrip = true;
48-
} else if (onlyStepName.toLowerCase(Locale.ROOT).contains("eclipse")) {
49-
supportsRoundTrip = true;
50-
} else if (onlyStepName.equals("fence")) {
51-
supportsRoundTrip = true;
52-
} else if (Set.of("black", "buf", "clang", "ktlint", "ktfmt", "scalafmt", "palantir-java-format", "google-java-format",
53-
"removeUnusedImports", "cleanthat", "No line break between type annotation and type", "antlr4Formatter",
54-
"gson", "jacksonJson", "apply-json-patch", "jsonSimple", "sortPom", "jacksonYaml", "gherkinUtils",
55-
"flexmark-java", "freshmark",
56-
"importOrder", "Remove unnecessary semicolons").contains(onlyStepName)) {
57-
supportsRoundTrip = true;
58-
}
59-
}
27+
Formatter roundTripped = SerializableEqualityTester.reserialize(formatter);
28+
Assertions.assertThat(roundTripped).isEqualTo(formatter);
6029
}
6130

6231
protected Formatter formatter() {
63-
if (!supportsRoundTrip) {
64-
return formatter;
65-
} else {
66-
if (roundTripped == null) {
67-
roundTripped = SerializableEqualityTester.reserialize(formatter);
68-
Assertions.assertThat(roundTripped).isEqualTo(formatter);
69-
}
70-
return roundTripped;
71-
}
32+
return formatter;
7233
}
7334

7435
@Override
7536
public void close() {
7637
formatter.close();
77-
if (roundTripped != null) {
78-
roundTripped.close();
79-
}
8038
}
8139
}

testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.assertj.core.api.Assertions;
2727

2828
/** An api for testing a {@code FormatterStep} that depends on the File path. */
29-
public class StepHarnessWithFile extends StepHarnessBase<StepHarnessWithFile> {
29+
public class StepHarnessWithFile extends StepHarnessBase {
3030
private final ResourceHarness harness;
3131

3232
private StepHarnessWithFile(ResourceHarness harness, Formatter formatter) {

0 commit comments

Comments
 (0)