@@ -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