*/
package com.intellij;
+import com.intellij.idea.Bombed;
import com.intellij.idea.RecordExecution;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing;
}
@Nullable
- private static Test getTest(@NotNull final Class testCaseClass) {
+ private static Test getTest(@NotNull final Class<?> testCaseClass) {
try {
if ((testCaseClass.getModifiers() & Modifier.PUBLIC) == 0) {
return null;
}
+ Bombed classBomb = testCaseClass.getAnnotation(Bombed.class);
+ if (classBomb != null && PlatformTestUtil.bombExplodes(classBomb)) {
+ return new ExplodedBomb(testCaseClass.getName(), classBomb);
+ }
Method suiteMethod = safeFindMethod(testCaseClass, "suite");
if (suiteMethod != null && !isPerformanceTestsRun()) {
@Override
public void addTest(Test test) {
if (!(test instanceof TestCase)) {
- testsCount[0]++;
- super.addTest(test);
+ doAddTest(test);
}
else {
String name = ((TestCase)test).getName();
return;
Method method = findTestMethod((TestCase)test);
- if (method == null || !TestCaseLoader.isBombed(method)) {
- testsCount[0]++;
- super.addTest(test);
+ if (method == null) {
+ doAddTest(test);
+ }
+ else {
+ Bombed methodBomb = method.getAnnotation(Bombed.class);
+ if (methodBomb == null) {
+ doAddTest(test);
+ }
+ else if (PlatformTestUtil.bombExplodes(methodBomb)) {
+ doAddTest(new ExplodedBomb(method.getDeclaringClass().getName() + "." + method.getName(), methodBomb));
+ }
}
}
}
+ private void doAddTest(Test test) {
+ testsCount[0]++;
+ super.addTest(test);
+ }
+
@Nullable
private Method findTestMethod(final TestCase testCase) {
return safeFindMethod(testCase.getClass(), testCase.getName());
private static void log(String message) {
TeamCityLogger.info(message);
}
+
+ @SuppressWarnings({"JUnitTestCaseWithNoTests", "JUnitTestClassNamingConvention", "JUnitTestCaseWithNonTrivialConstructors"})
+ private static class ExplodedBomb extends TestCase {
+ private final Bombed myBombed;
+
+ public ExplodedBomb(String testName, Bombed bombed) {
+ super(testName);
+ myBombed = bombed;
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ String description = myBombed.description().isEmpty() ? "" : " (" + myBombed.description() + ")";
+ fail("Bomb created by " + myBombed.user() + description + " now explodes!");
+ }
+ }
}
import java.io.IOException;
import java.io.InputStreamReader;
+import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URL;
return !myTestClassesFilter.matches(className, moduleName) || isBombed(testCaseClass);
}
- public static boolean isBombed(final Method method) {
- final Bombed bombedAnnotation = method.getAnnotation(Bombed.class);
+ public static boolean isBombed(final AnnotatedElement element) {
+ final Bombed bombedAnnotation = element.getAnnotation(Bombed.class);
if (bombedAnnotation == null) return false;
- if (PlatformTestUtil.isRotten(bombedAnnotation)) {
- String message = "Disarm the stale bomb for '" + method + "' in class '" + method.getDeclaringClass() + "'";
- System.err.println(message);
- }
- return !PlatformTestUtil.bombExplodes(bombedAnnotation);
- }
-
- public static boolean isBombed(final Class<?> testCaseClass) {
- final Bombed bombedAnnotation = testCaseClass.getAnnotation(Bombed.class);
- if (bombedAnnotation == null) return false;
- if (PlatformTestUtil.isRotten(bombedAnnotation)) {
- String message = "Disarm the stale bomb for '" + testCaseClass + "'";
- System.err.println(message);
- }
return !PlatformTestUtil.bombExplodes(bombedAnnotation);
}