|
18 | 18 | import static org.junit.jupiter.api.Assertions.*; |
19 | 19 |
|
20 | 20 | import java.io.File; |
| 21 | +import java.io.IOException; |
21 | 22 | import java.nio.charset.StandardCharsets; |
22 | 23 | import java.util.Collections; |
23 | 24 | import java.util.Objects; |
24 | 25 |
|
25 | | -import org.assertj.core.api.AbstractStringAssert; |
26 | | -import org.assertj.core.api.Assertions; |
| 26 | +import com.diffplug.selfie.StringSelfie; |
27 | 27 |
|
28 | 28 | /** An api for testing a {@code FormatterStep} that depends on the File path. */ |
29 | 29 | public class StepHarnessWithFile extends StepHarnessBase { |
@@ -85,30 +85,17 @@ public StepHarnessWithFile testResourceUnaffected(String resourceIdempotent) { |
85 | 85 | return testUnaffected(file, contentBefore); |
86 | 86 | } |
87 | 87 |
|
88 | | - public AbstractStringAssert<?> testResourceExceptionMsg(String resourceBefore) { |
89 | | - return testResourceExceptionMsg(resourceBefore, resourceBefore); |
| 88 | + public StringSelfie expectLintsOfResource(String resource) { |
| 89 | + return expectLintsOfResource(resource, resource); |
90 | 90 | } |
91 | 91 |
|
92 | | - public AbstractStringAssert<?> testResourceExceptionMsg(String filename, String resourceBefore) { |
93 | | - String contentBefore = ResourceHarness.getTestResource(resourceBefore); |
94 | | - File file = harness.setFile(filename).toContent(contentBefore); |
95 | | - return testExceptionMsg(file, contentBefore); |
96 | | - } |
97 | | - |
98 | | - public AbstractStringAssert<?> testExceptionMsg(File file, String before) { |
| 92 | + public StringSelfie expectLintsOfResource(String filename, String resource) { |
99 | 93 | try { |
100 | | - formatter().compute(LineEnding.toUnix(before), file); |
101 | | - throw new SecurityException("Expected exception"); |
102 | | - } catch (Throwable e) { |
103 | | - if (e instanceof SecurityException) { |
104 | | - throw new AssertionError(e.getMessage()); |
105 | | - } else { |
106 | | - Throwable rootCause = e; |
107 | | - while (rootCause.getCause() != null) { |
108 | | - rootCause = rootCause.getCause(); |
109 | | - } |
110 | | - return Assertions.assertThat(rootCause.getMessage()); |
111 | | - } |
| 94 | + File file = harness.setFile(filename).toResource(resource); |
| 95 | + LintState state = LintState.of(formatter(), file); |
| 96 | + return StepHarness.expectLintsOf(state, formatter()); |
| 97 | + } catch (IOException e) { |
| 98 | + throw new AssertionError(e); |
112 | 99 | } |
113 | 100 | } |
114 | 101 | } |
0 commit comments