1 package top.infra.core;
2
3 /**
4 * ExpectedException is thrown by user, not by libraries or frameworks.
5 */
6 public class ExpectedException extends RuntimeException {
7
8 /** Constructs a new expected exception with {@code null} as its
9 * detail message. The cause is not initialized, and may subsequently be
10 * initialized by a call to {@link #initCause}.
11 */
12 public ExpectedException() {
13 super();
14 }
15
16 /** Constructs a new expected exception with the specified detail message.
17 * The cause is not initialized, and may subsequently be initialized by a
18 * call to {@link #initCause}.
19 *
20 * @param message the detail message. The detail message is saved for
21 * later retrieval by the {@link #getMessage()} method.
22 */
23 public ExpectedException(final String message) {
24 super(message);
25 }
26
27 /**
28 * Constructs a new expected exception with the specified detail message and
29 * cause. <p>Note that the detail message associated with
30 * {@code cause} is <i>not</i> automatically incorporated in
31 * this expected exception's detail message.
32 *
33 * @param message the detail message (which is saved for later retrieval
34 * by the {@link #getMessage()} method).
35 * @param cause the cause (which is saved for later retrieval by the
36 * {@link #getCause()} method). (A <tt>null</tt> value is
37 * permitted, and indicates that the cause is nonexistent or
38 * unknown.)
39 */
40 public ExpectedException(final String message, final Throwable cause) {
41 super(message, cause);
42 }
43
44 /** Constructs a new expected exception with the specified cause and a
45 * detail message of <tt>(cause==null ? null : cause.toString())</tt>
46 * (which typically contains the class and detail message of
47 * <tt>cause</tt>). This constructor is useful for expected exceptions
48 * that are little more than wrappers for other throwables.
49 *
50 * @param cause the cause (which is saved for later retrieval by the
51 * {@link #getCause()} method). (A <tt>null</tt> value is
52 * permitted, and indicates that the cause is nonexistent or
53 * unknown.)
54 */
55 public ExpectedException(final Throwable cause) {
56 super(cause);
57 }
58
59 /**
60 * Constructs a new expected exception with the specified detail
61 * message, cause, suppression enabled or disabled, and writable
62 * stack trace enabled or disabled.
63 *
64 * @param message the detail message.
65 * @param cause the cause. (A {@code null} value is permitted,
66 * and indicates that the cause is nonexistent or unknown.)
67 * @param enableSuppression whether or not suppression is enabled
68 * or disabled
69 * @param writableStackTrace whether or not the stack trace should
70 * be writable
71 */
72 protected ExpectedException( //
73 final String message, //
74 final Throwable cause, //
75 boolean enableSuppression, //
76 boolean writableStackTrace //
77 ) {
78 super(message, cause, enableSuppression, writableStackTrace);
79 }
80 }