Skip to content

Commit f089c7e

Browse files
committed
Fix up more javadoc warnings under jdk21
1 parent 5dc0112 commit f089c7e

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

hamcrest/src/main/java/org/hamcrest/Matchers.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@ public static <T> Matcher<Optional<T>> optionalWithValue(Matcher<? super T> matc
22342234
}
22352235

22362236
/**
2237-
* Matcher for {@link Throwable} that expects that the Runnable throws an exception
2237+
* Matcher for {@link Runnable} that expects an exception to be thrown
22382238
*
22392239
* @param <T> type of the Runnable
22402240
* @return The matcher.
@@ -2297,23 +2297,21 @@ public static <T extends Runnable, U extends Throwable> Matcher<T> throwsExcepti
22972297
* Matcher for {@link Throwable} that expects that the Runnable throws an exception with a message equal to the provided <code>message</code>
22982298
*
22992299
* @param <T> type of the Runnable
2300-
* @param <U> type of the Throwable
23012300
* @param message the String against which examined exception messages are compared
23022301
* @return The matcher.
23032302
*/
2304-
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsExceptionWithMessage(String message) {
2303+
public static <T extends Runnable> Matcher<T> throwsExceptionWithMessage(String message) {
23052304
return ThrowsException.throwsExceptionWithMessage(message);
23062305
}
23072306

23082307
/**
23092308
* Matcher for {@link Throwable} that expects that the Runnable throws an exception with a message matching the provided <code>messageMatcher</code>
23102309
*
23112310
* @param <T> type of the Runnable
2312-
* @param <U> type of the Throwable
23132311
* @param messageMatcher matcher to validate exception's message
23142312
* @return The matcher.
23152313
*/
2316-
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsExceptionWithMessage(Matcher<String> messageMatcher) {
2314+
public static <T extends Runnable> Matcher<T> throwsExceptionWithMessage(Matcher<String> messageMatcher) {
23172315
return ThrowsException.throwsExceptionWithMessage(messageMatcher);
23182316
}
23192317
}

hamcrest/src/main/java/org/hamcrest/exception/ThrowsException.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,100 @@ public class ThrowsException<T extends Runnable> extends TypeSafeDiagnosingMatch
1717
private final IsInstanceOf classMatcher;
1818
private final Matcher<? super String> messageMatcher;
1919

20+
/**
21+
* Constructor, best called from one of the static {@link #throwsException()} methods.
22+
* @param classMatcher the matcher for the type of the exception
23+
* @param messageMatcher the matcher for the exception message
24+
*/
2025
public ThrowsException(IsInstanceOf classMatcher, Matcher<? super String> messageMatcher) {
2126
this.classMatcher = classMatcher;
2227
this.messageMatcher = messageMatcher;
2328
}
2429

30+
/**
31+
* Matcher for {@link Runnable} that expects an exception to be thrown
32+
*
33+
* @param <T> type of the Runnable
34+
* @return The matcher.
35+
*/
2536
public static <T extends Runnable> Matcher<T> throwsException() {
2637
return throwsException(Throwable.class);
2738
}
2839

40+
/**
41+
* Matcher for {@link Throwable} that expects that the Runnable throws an exception equal
42+
* to the provided <code>throwable</code>
43+
*
44+
* @param <U> type of the Runnable
45+
* @param <T> type of the Throwable
46+
* @param throwable the Throwable class against which examined exceptions are compared
47+
* @return The matcher.
48+
*/
2949
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsException(U throwable) {
3050
return throwsException(throwable.getClass(), throwable.getMessage());
3151
}
3252

53+
/**
54+
* Matcher for {@link Throwable} that expects that the Runnable throws an exception of the
55+
* provided <code>throwableClass</code> class
56+
*
57+
* @param <U> type of the Runnable
58+
* @param <T> type of the Throwable
59+
* @param throwableClass the Throwable class against which examined exceptions are compared
60+
* @return The matcher.
61+
*/
3362
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsException(Class<U> throwableClass) {
3463
return new ThrowsException<>(new IsInstanceOf(throwableClass), anything("<anything>"));
3564
}
3665

66+
/**
67+
* Matcher for {@link Throwable} that expects that the Runnable throws an exception of the
68+
* provided <code>throwableClass</code> class and has a message equal to the provided
69+
* <code>message</code>
70+
*
71+
* @param <T> type of the Runnable
72+
* @param <U> type of the Throwable
73+
* @param throwableClass the Throwable class against which examined exceptions are compared
74+
* @param exactMessage the String against which examined exception messages are compared
75+
* @return The matcher.
76+
*/
3777
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsException(Class<U> throwableClass, String exactMessage) {
3878
return throwsException(throwableClass, equalTo(exactMessage));
3979
}
4080

81+
/**
82+
* Matcher for {@link Throwable} that expects that the Runnable throws an exception of the provided
83+
* <code>throwableClass</code> class and has a message matching the provided
84+
* <code>messageMatcher</code>
85+
*
86+
* @param <T> type of the Runnable
87+
* @param <U> type of the Throwable
88+
* @param throwableClass the Throwable class against which examined exceptions are compared
89+
* @param messageMatcher matcher to validate exception's message
90+
* @return The matcher.
91+
*/
4192
public static <T extends Runnable, U extends Throwable> Matcher<T> throwsException(Class<U> throwableClass, Matcher<String> messageMatcher) {
4293
return new ThrowsException<>(new IsInstanceOf(throwableClass), messageMatcher);
4394
}
4495

96+
/**
97+
* Matcher for {@link Throwable} that expects that the Runnable throws an exception with a message equal to the provided <code>message</code>
98+
*
99+
* @param <T> type of the Runnable
100+
* @param exactMessage the String against which examined exception messages are compared
101+
* @return The matcher.
102+
*/
45103
public static <T extends Runnable> Matcher<T> throwsExceptionWithMessage(String exactMessage) {
46104
return throwsException(Throwable.class, equalTo(exactMessage));
47105
}
48106

107+
/**
108+
* Matcher for {@link Throwable} that expects that the Runnable throws an exception with a message matching the provided <code>messageMatcher</code>
109+
*
110+
* @param <T> type of the Runnable
111+
* @param messageMatcher matcher to validate exception's message
112+
* @return The matcher.
113+
*/
49114
public static <T extends Runnable> Matcher<T> throwsExceptionWithMessage(Matcher<String> messageMatcher) {
50115
return throwsException(Throwable.class, messageMatcher);
51116
}

0 commit comments

Comments
 (0)