/** * This method throws the expected exception wrapped into the {@link Test} * annotation. * * @param test * with the expected exception */ public static void provoke(final Test test) { Class<? extends Throwable> expected = test.expected(); if ((expected != Test.None.class) && (expected != null)) { ExceptionThrower.provoke(expected); } }
/** * Be careful - you can provoke any Exception with the method without the * need to declare it with a throws statement. For example * * <pre> * provoke(IOException.class) * </pre> * * would throw an IOException. * <p> * WARNING: If the desired exception can't be instantiated an * InstantiationException or IllegalAccessException may be thrown. * </p> * <p> * WARNING(2): This method is not synchronized. * </p> * * @param type * e.g. IOException.class */ public static void provoke(final Class<? extends Throwable> type) { Throwable t; try { t = create(type); } catch (ReflectiveOperationException ex) { LOG.debug("Cannot create {}:", type, ex); t = ex; } Thrower.provoke(t); }