Guest User

Untitled

a guest
May 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. @Target({ ElementType.TYPE, ElementType.METHOD })
  2. @Retention(RetentionPolicy.RUNTIME)
  3. public @interface IgnoreException {
  4. Class<? extends Throwable>[] value();
  5. }
  6.  
  7. public class IgnoreExceptionExtension implements TestExecutionExceptionHandler {
  8. @Override
  9. public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable {
  10. IgnoreException annotation = context.getRequiredTestMethod().getAnnotation(IgnoreException.class);
  11. if (annotation != null) {
  12. Optional<?> o = Arrays.stream(annotation.value())
  13. .filter(c -> c.isAssignableFrom(throwable.getClass()))
  14. .findFirst();
  15.  
  16. if (!o.isPresent()) {
  17. throw throwable;
  18. }
  19. }
  20. }
  21. }
  22.  
  23. class FooTest {
  24. @Test
  25. @IgnoreException({IllegalArgumentException.class, IllegalStateException.class})
  26. void doTheRoar() {
  27. //...
  28. }
  29. }
Add Comment
Please, Sign In to add comment