Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Target({ ElementType.TYPE, ElementType.METHOD })
- @Retention(RetentionPolicy.RUNTIME)
- public @interface IgnoreException {
- Class<? extends Throwable>[] value();
- }
- public class IgnoreExceptionExtension implements TestExecutionExceptionHandler {
- @Override
- public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable {
- IgnoreException annotation = context.getRequiredTestMethod().getAnnotation(IgnoreException.class);
- if (annotation != null) {
- Optional<?> o = Arrays.stream(annotation.value())
- .filter(c -> c.isAssignableFrom(throwable.getClass()))
- .findFirst();
- if (!o.isPresent()) {
- throw throwable;
- }
- }
- }
- }
- class FooTest {
- @Test
- @IgnoreException({IllegalArgumentException.class, IllegalStateException.class})
- void doTheRoar() {
- //...
- }
- }
Add Comment
Please, Sign In to add comment