boolean shouldIntercept(Method testMethod) { if (testMethod == null) return false; Test annotation = testMethod.getAnnotation(Test.class); return annotation != null && asList(annotation.expectedExceptions()).isEmpty(); }
result.setDescription( findInherited(test.description(), cls, Test.class, "description", DEFAULT_STRING)); result.setExpectedExceptions(test.expectedExceptions()); result.setExpectedExceptionsMessageRegExp(test.expectedExceptionsMessageRegExp()); result.setSuiteName(test.suiteName());
result.setDescription( findInherited(test.description(), cls, Test.class, "description", DEFAULT_STRING)); result.setExpectedExceptions(test.expectedExceptions()); result.setExpectedExceptionsMessageRegExp(test.expectedExceptionsMessageRegExp()); result.setSuiteName(test.suiteName());
private static boolean isExpectedException(@Nonnull IInvokedMethod invokedMethod, @Nonnull Throwable thrownByTest) { Method testMethod = invokedMethod.getTestMethod().getConstructorOrMethod().getMethod(); Class<?>[] expectedExceptions = testMethod.getAnnotation(Test.class).expectedExceptions(); Class<? extends Throwable> thrownExceptionType = thrownByTest.getClass(); for (Class<?> expectedException : expectedExceptions) { if (expectedException.isAssignableFrom(thrownExceptionType)) { return true; } } return false; }
public String[] getPackagesToIgnore(AnnotatedElement element) { List<String> ignoredPackages = new LinkedList<String>(); if (element instanceof Class<?>) { Class<?> klazz = (Class<?>) element; for (Method method : klazz.getMethods()) { Test annotation = method.getAnnotation(Test.class); if (annotation != null) { Class<?>[] ignores = annotation.expectedExceptions(); if (ignores != null) { for (Class<?> ignorePackage : ignores) { ignoredPackages.add(ignorePackage.getName()); } } } } Class<?> superclass = klazz.getSuperclass(); if (superclass != null && !superclass.equals(Object.class)) { String[] packagesToIgnore = getPackagesToIgnore(superclass); ignoredPackages.addAll(Arrays.asList(packagesToIgnore)); } } return ignoredPackages.toArray(new String[ignoredPackages.size()]); } }