2323import org .apache .avro .generic .GenericRecord ;
2424import org .assertj .core .api .AbstractThrowableAssert ;
2525import org .assertj .core .api .Assertions ;
26+ import org .assertj .core .api .ThrowableAssert ;
2627
28+ /**
29+ * This class is deprecated. Please use {@link
30+ * Assertions#assertThatThrownBy(ThrowableAssert.ThrowingCallable)} directly as shown below:
31+ *
32+ * <pre>
33+ * Assertions.assertThatThrownBy(() -> throwingCallable)
34+ * .isInstanceOf(ExpectedException.class)
35+ * .hasMessage(expectedErrorMsg)
36+ * </pre>
37+ *
38+ * @deprecated Use {@link Assertions#assertThatThrownBy(ThrowableAssert.ThrowingCallable)} directly
39+ * as it provides a more fluent way of asserting on exceptions.
40+ */
41+ @ Deprecated
2742public class AssertHelpers {
2843
2944 private AssertHelpers () {}
@@ -35,7 +50,10 @@ private AssertHelpers() {}
3550 * @param expected An Exception class that the Runnable should throw
3651 * @param containedInMessage A String that should be contained by the thrown exception's message
3752 * @param callable A Callable that is expected to throw the exception
53+ * @deprecated Use {@link Assertions#assertThatThrownBy(ThrowableAssert.ThrowingCallable)}
54+ * directly as it provides a more fluent way of asserting on exceptions.
3855 */
56+ @ Deprecated
3957 public static void assertThrows (
4058 String message ,
4159 Class <? extends Exception > expected ,
@@ -55,7 +73,10 @@ public static void assertThrows(
5573 * @param expected An Exception class that the Runnable should throw
5674 * @param containedInMessage A String that should be contained by the thrown exception's message
5775 * @param runnable A Runnable that is expected to throw the runtime exception
76+ * @deprecated Use {@link Assertions#assertThatThrownBy(ThrowableAssert.ThrowingCallable)}
77+ * directly as it provides a more fluent way of asserting on exceptions.
5878 */
79+ @ Deprecated
5980 public static void assertThrows (
6081 String message ,
6182 Class <? extends Exception > expected ,
@@ -74,7 +95,10 @@ public static void assertThrows(
7495 * @param message A String message to describe this assertion
7596 * @param expected An Exception class that the Runnable should throw
7697 * @param callable A Callable that is expected to throw the exception
98+ * @deprecated Use {@link Assertions#assertThatThrownBy(ThrowableAssert.ThrowingCallable)}
99+ * directly as it provides a more fluent way of asserting on exceptions.
77100 */
101+ @ Deprecated
78102 public static void assertThrows (
79103 String message , Class <? extends Exception > expected , Callable callable ) {
80104 assertThrows (message , expected , null , callable );
@@ -86,7 +110,10 @@ public static void assertThrows(
86110 * @param message A String message to describe this assertion
87111 * @param expected An Exception class that the Runnable should throw
88112 * @param runnable A Runnable that is expected to throw the runtime exception
113+ * @deprecated Use {@link Assertions#assertThatThrownBy(ThrowableAssert.ThrowingCallable)}
114+ * directly as it provides a more fluent way of asserting on exceptions.
89115 */
116+ @ Deprecated
90117 public static void assertThrows (
91118 String message , Class <? extends Exception > expected , Runnable runnable ) {
92119 assertThrows (message , expected , null , runnable );
@@ -100,7 +127,10 @@ public static void assertThrows(
100127 * @param containedInMessage A String that should be contained by the cause of the thrown
101128 * exception's message
102129 * @param runnable A Runnable that is expected to throw the runtime exception
130+ * @deprecated Use {@link Assertions#assertThatThrownBy(ThrowableAssert.ThrowingCallable)}
131+ * directly as it provides a more fluent way of asserting on exceptions.
103132 */
133+ @ Deprecated
104134 public static void assertThrowsCause (
105135 String message ,
106136 Class <? extends Exception > expected ,
@@ -124,7 +154,10 @@ public static void assertThrowsCause(
124154 * @param causeContainedInMessage A String that should be contained by the cause of the thrown
125155 * exception's message, will be skipped if null.
126156 * @param runnable A Runnable that is expected to throw the runtime exception
157+ * @deprecated Use {@link Assertions#assertThatThrownBy(ThrowableAssert.ThrowingCallable)}
158+ * directly as it provides a more fluent way of asserting on exceptions.
127159 */
160+ @ Deprecated
128161 public static void assertThrowsWithCause (
129162 String message ,
130163 Class <? extends Exception > expected ,
@@ -150,13 +183,22 @@ public static void assertThrowsWithCause(
150183 *
151184 * @param record The record to read from
152185 * @param field The name of the field
186+ * @deprecated Use {@link Assertions#assertThatThrownBy(ThrowableAssert.ThrowingCallable)}
187+ * directly as it provides a more fluent way of asserting on exceptions.
153188 */
189+ @ Deprecated
154190 public static void assertEmptyAvroField (GenericRecord record , String field ) {
155191 AssertHelpers .assertThrows (
156192 "Not a valid schema field: " + field , AvroRuntimeException .class , () -> record .get (field ));
157193 }
158194
159- /** Same as {@link AssertHelpers#assertThrowsCause}, but this method compares root cause. */
195+ /**
196+ * Same as {@link AssertHelpers#assertThrowsCause}, but this method compares root cause.
197+ *
198+ * @deprecated Use {@link Assertions#assertThatThrownBy(ThrowableAssert.ThrowingCallable)}
199+ * directly as it provides a more fluent way of asserting on exceptions.
200+ */
201+ @ Deprecated
160202 public static void assertThrowsRootCause (
161203 String message ,
162204 Class <? extends Exception > expected ,
0 commit comments