Package org.openhab.core.test.java
Class JavaTest
java.lang.Object
org.openhab.core.test.java.JavaTest
- Direct Known Subclasses:
JavaOSGiTest
JavaTest
is an abstract base class for tests which are not necessarily based on OSGi.- Author:
- Simon Kaufmann - Initial contribution
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
protected static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
assertLogMessage
(Class<?> clazz, JavaTest.LogLevel logLevel, String message) Assert that a message was logged for a class with a given log level and messageprotected void
assertNoLogMessage
(Class<?> clazz) Assert that not message was logged for a classprotected static <T> T
giveNull()
Useful for testing @NonNull annotated parametersprotected void
setupInterceptedLogger
(Class<?> clazz, JavaTest.LogLevel minLogLevel) Set up an intercepting logger for a class with a log level thresholdprotected void
stopInterceptedLogger
(Class<?> clazz) Stop the logging interceptionprotected boolean
waitFor
(BooleanSupplier condition) Wait until the condition is fulfilled or the timeout is reached.protected boolean
waitFor
(BooleanSupplier condition, long timeout, long sleepTime) Wait until the condition is fulfilled or the timeout is reached.protected void
waitForAssert
(Runnable assertion) Wait until the assertion is fulfilled or the timeout is reached.protected void
waitForAssert
(Runnable assertion, long timeout, long sleepTime) Wait until the assertion is fulfilled or the timeout is reached.protected void
waitForAssert
(Runnable assertion, @Nullable Runnable beforeLastCall, long timeout, long sleepTime) Wait until the assertion is fulfilled or the timeout is reached.protected void
waitForAssert
(Runnable assertion, @Nullable Runnable beforeLastCall, @Nullable Runnable afterLastCall, long timeout, long sleepTime) Wait until the assertion is fulfilled or the timeout is reached.protected <T> T
waitForAssert
(Supplier<T> assertion) Wait until the assertion is fulfilled or the timeout is reached.protected <T> T
waitForAssert
(Supplier<T> assertion, long timeout, long sleepTime) Wait until the assertion is fulfilled or the timeout is reached.
-
Field Details
-
DFL_TIMEOUT
protected static final int DFL_TIMEOUT- See Also:
-
DFL_SLEEP_TIME
protected static final int DFL_SLEEP_TIME- See Also:
-
-
Constructor Details
-
JavaTest
public JavaTest()
-
-
Method Details
-
setupInterceptedLogger
Set up an intercepting logger for a class with a log level threshold- Parameters:
clazz
- TheClass
to intercept the logs forminLogLevel
- The minimum log level that should be recorded
-
stopInterceptedLogger
Stop the logging interception- Parameters:
clazz
- TheClass
to stop intercepting logs for
-
assertNoLogMessage
Assert that not message was logged for a class- Parameters:
clazz
- TheClass
to check
-
assertLogMessage
Assert that a message was logged for a class with a given log level and message- Parameters:
clazz
- TheClass
to checklogLevel
- The expected log levelmessage
- The expected message
-
waitFor
Wait until the condition is fulfilled or the timeout is reached.This method uses the default timing parameters.
- Parameters:
condition
- the condition to check- Returns:
- true on success, false on timeout
-
waitFor
Wait until the condition is fulfilled or the timeout is reached.- Parameters:
condition
- the condition to checktimeout
- timeoutsleepTime
- interval for checking the condition- Returns:
- true on success, false on timeout
-
waitForAssert
Wait until the assertion is fulfilled or the timeout is reached.This method uses the default timing parameters.
- Parameters:
assertion
- closure that must not have an argument
-
waitForAssert
Wait until the assertion is fulfilled or the timeout is reached.- Parameters:
assertion
- the logic to executetimeout
- timeoutsleepTime
- interval for checking the condition
-
waitForAssert
Wait until the assertion is fulfilled or the timeout is reached.This method uses the default timing parameters.
- Parameters:
assertion
- the logic to execute- Returns:
- the return value of the supplied assertion object's function on success
-
waitForAssert
Wait until the assertion is fulfilled or the timeout is reached.- Parameters:
assertion
- the logic to executetimeout
- timeoutsleepTime
- interval for checking the condition- Returns:
- the return value of the supplied assertion object's function on success
-
waitForAssert
protected void waitForAssert(Runnable assertion, @Nullable Runnable beforeLastCall, long timeout, long sleepTime) Wait until the assertion is fulfilled or the timeout is reached.- Parameters:
assertion
- the logic to executebeforeLastCall
- logic to execute in front of the last call to ${code assertion}sleepTime
- interval for checking the condition
-
waitForAssert
protected void waitForAssert(Runnable assertion, @Nullable Runnable beforeLastCall, @Nullable Runnable afterLastCall, long timeout, long sleepTime) Wait until the assertion is fulfilled or the timeout is reached.- Parameters:
assertion
- the logic to executebeforeLastCall
- logic to execute in front of the last call to ${code assertion}afterLastCall
- logic to execute after the last call to ${code assertion}sleepTime
- interval for checking the condition
-
giveNull
protected static <T> T giveNull()Useful for testing @NonNull annotated parametersThis method can be used if you want to check the behavior of a method if you supply null to a non-null marked argument. If you use null directly the compiler will raise an error. Using this method allows you to work around that compiler check by using a null value that is marked as non-null.
- Returns:
- null for testing purpose
-