public class ThrowableUtils extends Object
Constructor and Description |
---|
ThrowableUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
assertExceptionContainsMessage(Throwable t,
String msg)
Throws an assertion error if the specified throwable or throwable causes do not contain the specified message string.
|
static void |
assertFieldNotNull(Object fieldValue,
String fieldName)
Throws an
IllegalArgumentException if the specified field is |
static void |
assertFieldPositive(int fieldValue,
String fieldName)
Throws an
IllegalArgumentException if the specified field is |
static void |
assertNotNull(Object o,
String msg,
Object... args)
Throws an
IllegalArgumentException if the specified object is |
static void |
assertSameThread(long threadId,
String msg,
Object... args)
Throws an exception if the specified thread ID is not the same as the current thread.
|
static <T extends Throwable> |
getCause(Class<T> c,
Throwable t)
Same as
Throwable.getCause() but searches the throwable chain for an exception of the specified type. |
static void |
illegalArg(String msg,
Object... args)
Shortcut for calling
|
static void |
throwException(String name,
String message,
Class<?>... throwables)
Given a list of available throwable types, attempts to create and throw the exception based on name.
|
public ThrowableUtils()
public static void assertNotNull(Object o, String msg, Object... args) throws IllegalArgumentException
IllegalArgumentException
if the specified object is o
- The object to check.msg
- The message of the IllegalArgumentException.args
- Optional MessageFormat
-style arguments.IllegalArgumentException
- Constructed exception.public static void assertFieldNotNull(Object fieldValue, String fieldName) throws IllegalArgumentException
IllegalArgumentException
if the specified field is fieldValue
- The object to check.fieldName
- The name of the field.IllegalArgumentException
- Constructed exception.public static void assertFieldPositive(int fieldValue, String fieldName) throws IllegalArgumentException
IllegalArgumentException
if the specified field is fieldValue
- The object to check.fieldName
- The name of the field.IllegalArgumentException
- Constructed exception.public static void illegalArg(String msg, Object... args) throws IllegalArgumentException
new IllegalArgumentException(MessageFormat.format (msg, args));
msg
- The message of the IllegalArgumentException.args
- Optional MessageFormat
-style arguments.IllegalArgumentException
- Constructed exception.public static void assertSameThread(long threadId, String msg, Object... args) throws IllegalStateException
threadId
- The ID of the thread to compare against.msg
- The message of the IllegalStateException.args
- Optional MessageFormat
-style arguments.IllegalStateException
- Constructed exception.public static void assertExceptionContainsMessage(Throwable t, String msg) throws AssertionError
t
- The throwable to check.msg
- The message text to check for.AssertionError
- Assertion failed.public static <T extends Throwable> T getCause(Class<T> c, Throwable t)
Throwable.getCause()
but searches the throwable chain for an exception of the specified type.T
- The throwable type to search for.c
- The throwable type to search for.t
- The throwable to search.public static void throwException(String name, String message, Class<?>... throwables) throws Throwable
name
- The exception name. Can be a simple name or fully-qualified.message
- The exception message passed to the exception constructor.throwables
- The list of available throwable classes to choose from.Throwable
- The thrown exception if it was possible to create.Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.