Skip to content

Commit d8b0e20

Browse files
committed
Use StepHarnessWithFile
1 parent bdc857e commit d8b0e20

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,14 @@ public static StepHarness forFormatter(Formatter formatter) {
5757

5858
/** Asserts that the given element is transformed as expected, and that the result is idempotent. */
5959
public StepHarness test(String before, String after) {
60-
return test(before, after, "");
61-
}
62-
63-
public StepHarness test(String before, String after, String fileName) {
64-
String actual = formatter.compute(LineEnding.toUnix(before), new File(fileName));
60+
String actual = formatter.compute(LineEnding.toUnix(before), new File(""));
6561
assertEquals(after, actual, "Step application failed");
66-
return testUnaffected(after, fileName);
62+
return testUnaffected(after);
6763
}
6864

6965
/** Asserts that the given element is idempotent w.r.t the step under test. */
7066
public StepHarness testUnaffected(String idempotentElement) {
71-
return testUnaffected(idempotentElement, "");
72-
}
73-
74-
public StepHarness testUnaffected(String idempotentElement, String fileName) {
75-
String actual = formatter.compute(LineEnding.toUnix(idempotentElement), new File(fileName));
67+
String actual = formatter.compute(LineEnding.toUnix(idempotentElement), new File(""));
7668
assertEquals(idempotentElement, actual, "Step is not idempotent");
7769
return this;
7870
}

testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.time.YearMonth;
2222
import java.time.ZoneOffset;
2323

24+
import com.diffplug.spotless.StepHarnessWithFile;
25+
2426
import org.junit.jupiter.api.Assertions;
2527
import org.junit.jupiter.api.Test;
2628

@@ -266,18 +268,18 @@ void should_preserve_year_for_license_with_address() throws Throwable {
266268
@Test
267269
void should_apply_license_containing_filename_token() throws Exception {
268270
FormatterStep step = LicenseHeaderStep.headerDelimiter(header(HEADER_WITH_$FILE), package_).build();
269-
StepHarness.forStep(step)
270-
.test(getTestResource(FILE_NO_LICENSE), hasHeaderFileName(HEADER_WITH_$FILE, "Test.java"), "Test.java");
271+
StepHarnessWithFile.forStep(this, step)
272+
.test(new File("Test.java"), getTestResource(FILE_NO_LICENSE), hasHeaderFileName(HEADER_WITH_$FILE, "Test.java"));
271273
}
272274

273275
@Test
274276
void should_apply_license_containing_YEAR_filename_token() throws Exception {
275277
FormatterStep step = LicenseHeaderStep.headerDelimiter(header(HEADER_WITH_$YEAR_$FILE), package_).build();
276-
StepHarness.forStep(step)
278+
StepHarnessWithFile.forStep(this, step)
277279
.test(
280+
new File("Test.java"),
278281
getTestResource(FILE_NO_LICENSE),
279-
hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java"),
280-
"Test.java"
282+
hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java")
281283
);
282284
}
283285
}

0 commit comments

Comments
 (0)