|
31 | 31 | import java.util.Collection; |
32 | 32 | import java.util.Collections; |
33 | 33 | import java.util.List; |
| 34 | +import java.util.regex.Pattern; |
34 | 35 |
|
35 | 36 | import javax.annotation.processing.Processor; |
36 | 37 | import javax.tools.Diagnostic; |
@@ -166,18 +167,31 @@ public static void assertCompilationErrorOn(File expectedErrorClassFile, String |
166 | 167 | assertCompilationDiagnostingOn(Kind.ERROR, expectedErrorClassFile, expectedContentInError, result); |
167 | 168 | } |
168 | 169 |
|
| 170 | + public static void assertCompilationErrorOn(String expectedClassName, String expectedContentInError, CompileResult result) throws IOException { |
| 171 | + assertCompilationDiagnostingOn(Kind.ERROR, new File(expectedClassName + ".java"), expectedContentInError, result); |
| 172 | + } |
| 173 | + |
169 | 174 | public static void assertCompilationWarningOn(File expectedErrorClassFile, String expectedContentInError, CompileResult result) throws IOException { |
170 | 175 | assertCompilationDiagnostingOn(Kind.WARNING, expectedErrorClassFile, expectedContentInError, result); |
171 | 176 | } |
172 | 177 |
|
173 | 178 | private static void assertCompilationDiagnostingOn(Kind expectedDiagnosticKind, File expectedErrorClassFile, String expectedContentInError, CompileResult result) throws IOException { |
174 | 179 |
|
175 | | - String expectedErrorPath = expectedErrorClassFile.toURI().toString(); |
| 180 | + String expectedErrorPath; |
| 181 | + boolean fileNameOnly = expectedErrorClassFile.getPath().split(Pattern.quote(File.separator)).length == 1; |
| 182 | + |
| 183 | + if (fileNameOnly) { |
| 184 | + // this is just the filename |
| 185 | + expectedErrorPath = expectedErrorClassFile.getPath(); |
| 186 | + } else { |
| 187 | + expectedErrorPath = expectedErrorClassFile.toURI().toString(); |
| 188 | + } |
| 189 | + |
176 | 190 | for (Diagnostic<? extends JavaFileObject> diagnostic : result.diagnostics) { |
177 | 191 | if (diagnostic.getKind() == expectedDiagnosticKind) { |
178 | 192 | JavaFileObject source = diagnostic.getSource(); |
179 | 193 | if (source != null) { |
180 | | - if (expectedErrorPath.endsWith(source.toUri().toString())) { |
| 194 | + if (expectedErrorPath.endsWith(source.toUri().toString()) || fileNameOnly && source.toUri().toString().endsWith(expectedErrorPath)) { |
181 | 195 |
|
182 | 196 | CharSequence sourceContent = source.getCharContent(true); |
183 | 197 | if (diagnostic.getPosition() != Diagnostic.NOPOS) { |
|
0 commit comments