88import java .util .function .Predicate ;
99
1010/**
11- * A test utility class for recording and executing assertions about the presence (or absence) of exceptions
11+ * The ExceptionTracker interface provides a set of methods to record, track, and assert exceptions
12+ * in a testing context. By defining rules to expect or ignore certain exceptions, it helps in
13+ * systematically verifying the correct exception handling behavior of code under test.
1214 *
1315 * @param <T> The class used to represent thrown exceptions
1416 */
1517public interface ExceptionTracker <T > {
1618
1719 /**
18- * Create an exception tracker
20+ * Factory method to create an instance of the exception tracker. This method encapsulates
21+ * the construction of a concrete implementation of the ExceptionTracker interface.
1922 *
20- * @param messageExtractor The function used to extract the String message or description from T
21- * @param throwableExtractor The function used to extract the Throwable from T
22- * @param resetRunnable A Runnable that will be called at the end of {@link #checkExceptions()}
23- * @param exceptions A map that will be populated with T as the key and the count of occurrences of T as a value
24- * @param ignorePredicate A predicate that will exclude T's from consideration
25- * @param exceptionRenderer A function to render T as a String (used when dumping exceptions)
23+ * @param messageExtractor Function to extract the String message or description from T
24+ * @param throwableExtractor Function to extract the Throwable from T
25+ * @param resetRunnable Runnable that will be called at the end of {@link #checkExceptions()}
26+ * @param exceptions Map to populate with T as the key and count of occurrences as value
27+ * @param ignorePredicate Predicate to exclude T's from consideration
28+ * @param exceptionRenderer Function to render T as a String (used when dumping exceptions)
29+ * @return An instance of ExceptionTracker
2630 */
2731 static <T > ExceptionTracker <T > create (@ NotNull final Function <T , String > messageExtractor ,
2832 @ NotNull final Function <T , Throwable > throwableExtractor ,
@@ -40,50 +44,54 @@ static <T> ExceptionTracker<T> create(@NotNull final Function<T, String> message
4044 }
4145
4246 /**
43- * Require than an exception containing the specified string is thrown during the test
47+ * Specifies that an exception containing the specified string must be thrown during the test.
48+ * Failing to do so will cause the test to fail.
4449 *
4550 * @param message The string to require
4651 */
4752 void expectException (String message );
4853
4954 /**
50- * Require that an exception matching the specified predicate is thrown
55+ * Specifies that an exception matching the specified predicate must be thrown.
56+ * Failing to match the exception will cause the test to fail.
5157 *
52- * @param predicate The predicate used to match exceptions
53- * @param description The description of the exceptions being required
58+ * @param predicate Predicate to match exceptions
59+ * @param description Description of the exceptions being required
5460 */
5561 void expectException (Predicate <T > predicate , String description );
5662
5763 /**
58- * Ignore exceptions containing the specified string
64+ * Ignores exceptions containing the specified string. Matching exceptions will not cause
65+ * the test to fail.
5966 *
6067 * @param message The string to ignore
6168 */
6269 void ignoreException (String message );
6370
6471 /**
65- * Ignore exceptions matching the specified predicate
72+ * Ignores exceptions matching the specified predicate. Matching exceptions will not cause
73+ * the test to fail.
6674 *
67- * @param predicate The predicate to match the exception
68- * @param description The description of the exceptions being ignored
75+ * @param predicate Predicate to match the exception
76+ * @param description Description of the exceptions being ignored
6977 */
7078 void ignoreException (Predicate <T > predicate , String description );
7179
7280 /**
73- * Determine if the tracker contains an exception matching the predicate
81+ * Determines if the tracker contains an exception matching the predicate.
7482 *
75- * @param predicate The predicate to match the exception
83+ * @param predicate Predicate to match the exception
84+ * @return true if an exception matching the predicate is found; false otherwise
7685 */
7786 boolean hasException (Predicate <T > predicate );
7887
7988 /**
80- * Call this in @After to ensure
89+ * Call this method in a teardown ( @After) phase of the test to:
8190 * <ul>
82- * <li>No non-ignored exceptions were thrown</li>
83- * <li>There is an exception matching each of the expected predicates</li>
91+ * <li>Verify no non-ignored exceptions were thrown</li>
92+ * <li>Assert there is an exception matching each of the expected predicates</li>
8493 * </ul>
85- * <p>
86- * Implementations should throw an exception and print a summary of the assertion(s) violated
94+ * Implementations should throw an exception and print a summary if the assertion(s) are violated.
8795 */
8896 void checkExceptions ();
8997}
0 commit comments