Skip to content

Commit 93305eb

Browse files
committed
Also assert test classes in the src/test/resources directory
1 parent b67277f commit 93305eb

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

  • AndroidAnnotations/androidannotations-core/androidannotations-testutils/src/main/java/org/androidannotations/testutils

AndroidAnnotations/androidannotations-core/androidannotations-testutils/src/main/java/org/androidannotations/testutils/ProcessorTestHelper.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Collection;
3232
import java.util.Collections;
3333
import java.util.List;
34+
import java.util.regex.Pattern;
3435

3536
import javax.annotation.processing.Processor;
3637
import javax.tools.Diagnostic;
@@ -166,18 +167,31 @@ public static void assertCompilationErrorOn(File expectedErrorClassFile, String
166167
assertCompilationDiagnostingOn(Kind.ERROR, expectedErrorClassFile, expectedContentInError, result);
167168
}
168169

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+
169174
public static void assertCompilationWarningOn(File expectedErrorClassFile, String expectedContentInError, CompileResult result) throws IOException {
170175
assertCompilationDiagnostingOn(Kind.WARNING, expectedErrorClassFile, expectedContentInError, result);
171176
}
172177

173178
private static void assertCompilationDiagnostingOn(Kind expectedDiagnosticKind, File expectedErrorClassFile, String expectedContentInError, CompileResult result) throws IOException {
174179

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+
176190
for (Diagnostic<? extends JavaFileObject> diagnostic : result.diagnostics) {
177191
if (diagnostic.getKind() == expectedDiagnosticKind) {
178192
JavaFileObject source = diagnostic.getSource();
179193
if (source != null) {
180-
if (expectedErrorPath.endsWith(source.toUri().toString())) {
194+
if (expectedErrorPath.endsWith(source.toUri().toString()) || fileNameOnly && source.toUri().toString().endsWith(expectedErrorPath)) {
181195

182196
CharSequence sourceContent = source.getCharContent(true);
183197
if (diagnostic.getPosition() != Diagnostic.NOPOS) {

0 commit comments

Comments
 (0)