public class CommonTestUtils extends Object
Constructor and Description |
---|
CommonTestUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
assertThrows(String msg,
Class<? extends Exception> expected,
Callable<?> code)
Checks whether an exception with a message occurs when running a piece of code.
|
static void |
blockForeverNonInterruptibly()
Permanently blocks the current thread.
|
static boolean |
containsCause(Throwable throwable,
Class<? extends Throwable> cause)
Checks whether the given throwable contains the given cause as a cause.
|
static <T extends Serializable> |
createCopySerializable(T original)
Creates a copy of an object via Java Serialization.
|
static String |
createTempFile(String contents)
Creates a temporary file that contains the given string.
|
static void |
setEnv(Map<String,String> newenv) |
static void |
setEnv(Map<String,String> newenv,
boolean clearExisting) |
static void |
waitUtil(java.util.function.Supplier<Boolean> condition,
java.time.Duration timeout,
java.time.Duration pause,
String errorMsg)
Wait util the given condition is met or timeout.
|
static void |
waitUtil(java.util.function.Supplier<Boolean> condition,
java.time.Duration timeout,
String errorMsg)
Wait util the given condition is met or timeout.
|
public static <T extends Serializable> T createCopySerializable(T original) throws IOException
original
- The original object.IOException
public static String createTempFile(String contents) throws IOException
The temp file is automatically deleted on JVM exit.
contents
- The contents to be written to the file.IOException
public static void blockForeverNonInterruptibly()
Thread.interrupt()
.public static boolean containsCause(Throwable throwable, Class<? extends Throwable> cause)
throwable
- Throwable to check for the causecause
- Cause to look forpublic static void assertThrows(String msg, Class<? extends Exception> expected, Callable<?> code)
public static void waitUtil(java.util.function.Supplier<Boolean> condition, java.time.Duration timeout, java.time.Duration pause, String errorMsg) throws TimeoutException, InterruptedException
condition
- the condition to wait for.timeout
- the maximum time to wait for the condition to become true.pause
- delay between condition checks.errorMsg
- the error message to include in the TimeoutException
if the
condition was not met before timeout.TimeoutException
- if the condition is not met before timeout.InterruptedException
- if the thread is interrupted.public static void waitUtil(java.util.function.Supplier<Boolean> condition, java.time.Duration timeout, String errorMsg) throws TimeoutException, InterruptedException
condition
- the condition to wait for.timeout
- the maximum time to wait for the condition to become true.errorMsg
- the error message to include in the TimeoutException
if the
condition was not met before timeout.TimeoutException
- if the condition is not met before timeout.InterruptedException
- if the thread is interrupted.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.