|
1 | 1 | /*
|
2 |
| - * Copyright 2016-2021 DiffPlug |
| 2 | + * Copyright 2016-2023 DiffPlug |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | import java.util.Arrays;
|
22 | 22 |
|
23 | 23 | import com.diffplug.spotless.FormatterStep;
|
24 |
| -import com.diffplug.spotless.LineEnding; |
25 | 24 | import com.diffplug.spotless.ResourceHarness;
|
| 25 | +import com.diffplug.spotless.StepHarnessWithFile; |
26 | 26 | import com.diffplug.spotless.extra.EclipseBasedStepBuilder;
|
27 | 27 |
|
28 | 28 | /**
|
|
43 | 43 | */
|
44 | 44 | public class EclipseResourceHarness extends ResourceHarness {
|
45 | 45 | private final EclipseBasedStepBuilder stepBuilder;
|
46 |
| - private final String fileName; |
47 |
| - private final String input; |
48 |
| - private final String expected; |
49 | 46 |
|
50 | 47 | /**
|
51 | 48 | * Create harness to be used for several versions of the formatter step
|
52 | 49 | * @param builder Eclipse Formatter step builder
|
53 |
| - * @param unformatted Simple unformatted input |
54 |
| - * @param formatted Expected formatted output |
55 | 50 | */
|
56 |
| - public EclipseResourceHarness(EclipseBasedStepBuilder builder, String unformatted, String formatted) { |
57 |
| - this(builder, "someSourceFile", unformatted, formatted); |
| 51 | + public EclipseResourceHarness(EclipseBasedStepBuilder builder) { |
| 52 | + this.stepBuilder = builder; |
58 | 53 | }
|
59 | 54 |
|
60 |
| - /** |
61 |
| - * Create harness to be used for several versions of the formatter step |
62 |
| - * @param builder Eclipse Formatter step builder |
63 |
| - * @param sourceFileName File name of the source file |
64 |
| - * @param unformatted Simple unformatted input |
65 |
| - * @param formatted Expected formatted output |
66 |
| - */ |
67 |
| - public EclipseResourceHarness(EclipseBasedStepBuilder builder, String sourceFileName, String unformatted, String formatted) { |
68 |
| - stepBuilder = builder; |
69 |
| - fileName = sourceFileName; |
70 |
| - input = unformatted; |
71 |
| - expected = formatted; |
72 |
| - } |
73 |
| - |
74 |
| - /** |
75 |
| - * Assert that formatting input results in expected output |
76 |
| - * @param formatterVersion Formatter version |
77 |
| - * @param settingsFiles Formatter settings |
78 |
| - * @return Formatted string |
79 |
| - */ |
80 |
| - protected String assertFormatted(String formatterVersion, File... settingsFiles) throws Exception { |
81 |
| - String output = format(formatterVersion, settingsFiles); |
82 |
| - assertThat(output).isEqualTo(expected); |
83 |
| - return output; |
84 |
| - } |
85 |
| - |
86 |
| - /** |
87 |
| - * Formatting input results and returns output |
88 |
| - * @param formatterVersion Formatter version |
89 |
| - * @param settingsFiles Formatter settings |
90 |
| - * @return Formatted string |
91 |
| - */ |
92 |
| - protected String format(String formatterVersion, File... settingsFiles) throws Exception { |
93 |
| - File inputFile = setFile(fileName).toContent(input); |
| 55 | + protected StepHarnessWithFile harnessFor(String formatterVersion, File... settingsFiles) throws Exception { |
94 | 56 | stepBuilder.setVersion(formatterVersion);
|
95 | 57 | stepBuilder.setPreferences(Arrays.asList(settingsFiles));
|
96 | 58 | FormatterStep step = stepBuilder.build();
|
97 |
| - return LineEnding.toUnix(step.format(input, inputFile)); |
| 59 | + return StepHarnessWithFile.forStep(this, step); |
98 | 60 | }
|
99 | 61 | }
|
0 commit comments