|
3 | 3 | import org.hamcrest.collection.ArrayMatching; |
4 | 4 | import org.hamcrest.core.IsIterableContaining; |
5 | 5 | import org.hamcrest.core.StringRegularExpression; |
| 6 | +import org.hamcrest.exception.ThrowsException; |
| 7 | +import org.hamcrest.exception.ThrowsExceptionEqualTo; |
| 8 | +import org.hamcrest.exception.ThrowsExceptionWithMessage; |
6 | 9 | import org.hamcrest.optional.OptionalEmpty; |
7 | 10 | import org.hamcrest.optional.OptionalWithValue; |
8 | 11 | import org.hamcrest.text.IsEqualCompressingWhiteSpace; |
@@ -2228,4 +2231,86 @@ public static <T> Matcher<Optional<T>> optionalWithValue(T value) { |
2228 | 2231 | public static <T> Matcher<Optional<T>> optionalWithValue(Matcher<? super T> matcher) { |
2229 | 2232 | return OptionalWithValue.optionalWithValue(matcher); |
2230 | 2233 | } |
| 2234 | + |
| 2235 | + /** |
| 2236 | + * Matcher for {@link Throwable} that expects that the Runnable throws an exception |
| 2237 | + * |
| 2238 | + * @param <T> type of the Runnable |
| 2239 | + * @return The matcher. |
| 2240 | + */ |
| 2241 | + public static <T extends Runnable> ThrowsException<T> throwsException() { |
| 2242 | + return ThrowsException.throwsException(); |
| 2243 | + } |
| 2244 | + |
| 2245 | + /** |
| 2246 | + * Matcher for {@link Throwable} that expects that the Runnable throws an exception equal to the provided <code>throwable</code> |
| 2247 | + * |
| 2248 | + * @param <T> type of the Runnable |
| 2249 | + * @param <U> type of the Throwable |
| 2250 | + * @param throwable the Throwable instance against which examined exceptions are compared |
| 2251 | + * @return The matcher. |
| 2252 | + */ |
| 2253 | + public static <T extends Runnable, U extends Throwable> ThrowsException<T> throwsException(U throwable) { |
| 2254 | + return ThrowsException.throwsException(throwable); |
| 2255 | + } |
| 2256 | + |
| 2257 | + /** |
| 2258 | + * Matcher for {@link Throwable} that expects that the Runnable throws an exception of the provided <code>throwableClass</code> class |
| 2259 | + * |
| 2260 | + * @param <U> type of the Runnable |
| 2261 | + * @param <T> type of the Throwable |
| 2262 | + * @param throwableClass the Throwable class against which examined exceptions are compared |
| 2263 | + * @return The matcher. |
| 2264 | + */ |
| 2265 | + public static <T extends Runnable, U extends Throwable> ThrowsException<T> throwsException(Class<U> throwableClass) { |
| 2266 | + return ThrowsException.throwsException(throwableClass); |
| 2267 | + } |
| 2268 | + |
| 2269 | + /** |
| 2270 | + * Matcher for {@link Throwable} that expects that the Runnable throws an exception with a message equal to the provided <code>message</code> class |
| 2271 | + * |
| 2272 | + * @param <T> type of the Runnable |
| 2273 | + * @param message the String against which examined exception messages are compared |
| 2274 | + * @return The matcher. |
| 2275 | + */ |
| 2276 | + public static <T extends Runnable> ThrowsException<T> throwsException(String message) { |
| 2277 | + return ThrowsException.throwsException(message); |
| 2278 | + } |
| 2279 | + |
| 2280 | + /** |
| 2281 | + * Matcher for {@link Throwable} that expects that the Runnable throws an exception matching provided <code>matcher</code> |
| 2282 | + * |
| 2283 | + * @param <T> type of the Runnable |
| 2284 | + * @param matcher matcher to validate the exception |
| 2285 | + * @return The matcher. |
| 2286 | + */ |
| 2287 | + public static <T extends Runnable> ThrowsException<T> throwsException(Matcher<? super Throwable> matcher) { |
| 2288 | + return ThrowsException.throwsException(matcher); |
| 2289 | + } |
| 2290 | + |
| 2291 | + /** |
| 2292 | + * Matcher for {@link Throwable} that expects that the Runnable throws an exception of the provided <code>throwableClass</code> class and has a message equal to the provided <code>message</code> |
| 2293 | + * |
| 2294 | + * @param <T> type of the Runnable |
| 2295 | + * @param <U> type of the Throwable |
| 2296 | + * @param throwableClass the Throwable class against which examined exceptions are compared |
| 2297 | + * @param message the String against which examined exception messages are compared |
| 2298 | + * @return The matcher. |
| 2299 | + */ |
| 2300 | + public static <T extends Runnable, U extends Throwable> ThrowsException<T> throwsException(Class<U> throwableClass, String message) { |
| 2301 | + return ThrowsException.throwsException(throwableClass, message); |
| 2302 | + } |
| 2303 | + |
| 2304 | + /** |
| 2305 | + * Matcher for {@link Throwable} that expects that the Runnable throws an exception of the provided <code>throwableClass</code> class and matches the provided <code>matcher</code> |
| 2306 | + * |
| 2307 | + * @param <U> type of the Runnable |
| 2308 | + * @param <T> type of the Throwable |
| 2309 | + * @param throwableClass the Throwable class against which examined exceptions are compared |
| 2310 | + * @param matcher matcher to validate the exception |
| 2311 | + * @return The matcher. |
| 2312 | + */ |
| 2313 | + public static <T extends Runnable, U extends Throwable> ThrowsException<T> throwsException(Class<U> throwableClass, Matcher<? super Throwable> matcher) { |
| 2314 | + return ThrowsException.throwsException(throwableClass, matcher); |
| 2315 | + } |
2231 | 2316 | } |
0 commit comments