public class TestUtils extends Object
| Constructor and Description |
|---|
TestUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends Throwable> |
assertThrows(Class<T> expectedThrowable,
ThrowingRunnable runnable)
Asserts that
runnable throws an exception of type expectedThrowable when
executed. |
static <T extends Throwable> |
assertThrows(String message,
Class<T> expectedThrowable,
ThrowingRunnable runnable)
Asserts that
runnable throws an exception of type expectedThrowable when
executed. |
private static String |
buildPrefix(String message)
Builds a message prefix.
|
private static boolean |
equalsRegardingNull(Object expected,
Object actual)
Returns whether expected and actual are considered equal regarding null.
|
(package private) static String |
format(String message,
Object expected,
Object actual)
Formats a message with given expected and actual value.
|
private static String |
formatClass(Class<?> value)
Formats the given class name.
|
private static String |
formatClassAndValue(Object value,
String valueString)
Formats a class name including value.
|
private static boolean |
isEquals(Object expected,
Object actual)
Returns whether expected and actual are considered equal.
|
static void |
oneSecondRunnable()
Runs/waits for one second.
|
static String |
oneSecondSupplier()
Runs/waits for one second and returns
DATA. |
static javax.json.JsonObject |
readJsonFromResources(String folder,
String filename)
Extracts a JsonObject from a resource.
The resource will be nested in a directory nested under the directory jsonsamples in the resource directory. |
static void |
threeSecondRunnable()
Runs/waits for three seconds.
|
static String |
threeSecondSupplier()
Runs/waits for three seconds and returns
DATA. |
static void |
twoSecondRunnable()
Runs/waits for two seconds.
|
static String |
twoSecondSupplier()
Runs/waits for two seconds and returns
DATA. |
public static final String DATA
public static javax.json.JsonObject readJsonFromResources(String folder, String filename) throws IOException
jsonsamples in the resource directory.folder - name of the directory where the resource is foundfilename - name of the file containing the resourceIOException - if the file cannot be found or an error occurs when
opening the streampublic static void oneSecondRunnable()
public static void twoSecondRunnable()
public static void threeSecondRunnable()
public static String oneSecondSupplier()
DATA.DATApublic static String twoSecondSupplier()
DATA.DATApublic static String threeSecondSupplier()
DATA.DATApublic static <T extends Throwable> T assertThrows(Class<T> expectedThrowable, ThrowingRunnable runnable)
runnable throws an exception of type expectedThrowable when
executed. If it does, the exception object is returned. If it does not throw an exception, an
AssertionError is thrown. If it throws the wrong type of exception, an AssertionError is thrown describing the mismatch; the exception that was actually thrown can
be obtained by calling Throwable.getCause().T - throwable typeexpectedThrowable - the expected type of the exceptionrunnable - a function that is expected to throw an exception when executedrunnablepublic static <T extends Throwable> T assertThrows(String message, Class<T> expectedThrowable, ThrowingRunnable runnable)
runnable throws an exception of type expectedThrowable when
executed. If it does, the exception object is returned. If it does not throw an exception, an
AssertionError is thrown. If it throws the wrong type of exception, an AssertionError is thrown describing the mismatch; the exception that was actually thrown can
be obtained by calling Throwable.getCause().T - throwable typemessage - the identifying message for the AssertionError (null
okay)expectedThrowable - the expected type of the exceptionrunnable - a function that is expected to throw an exception when executedrunnableprivate static String buildPrefix(String message)
message - the messageprivate static String formatClass(Class<?> value)
value - the classstatic String format(String message, Object expected, Object actual)
message - the messageexpected - the expected objectactual - the actual objectprivate static String formatClassAndValue(Object value, String valueString)
value - the class/object valuevalueString - the valueprivate static boolean equalsRegardingNull(Object expected, Object actual)
expected - the expected valueactual - the actual valuetrue for equal, false elseCopyright © 2022. All rights reserved.