Package limn.testing
Class HeadlessUi
java.lang.Object
limn.testing.HeadlessUi
- All Implemented Interfaces:
AutoCloseable
A
UiRuntime bound to the calling thread for the life of a test, so that the thread
confinement every widget asserts holds on the JUnit thread, and the worker pool and queue
behind Ui exist to be drained.
Open it in @BeforeEach, close it in @AfterEach. Twenty-five test classes
wrote the four lines this constructor is and the two lines close() is, most of them
beside a base class that already had them; this is the pair once, with the clock as the one
thing a test chooses.
-
Constructor Summary
ConstructorsConstructorDescriptionA runtime on the wall clock.HeadlessUi(LongSupplier nanos) A runtime on a clock the test controls. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Uninstalls the runtime and stops the workers.voidpumpUntil(BooleanSupplier done) pumpUntil(BooleanSupplier, long)with a five-second limit.voidpumpUntil(BooleanSupplier done, long timeoutNanos) Spins the UI queue, the way a backend's loop does, until the condition holds.runtime()workers()
-
Constructor Details
-
HeadlessUi
public HeadlessUi()A runtime on the wall clock. -
HeadlessUi
A runtime on a clock the test controls.- Parameters:
nanos- what the runtime reads as now
-
-
Method Details
-
runtime
- Returns:
- the runtime installed as
Ui's
-
workers
- Returns:
- the worker pool behind
Ui.async(java.util.function.Supplier<T>)
-
pumpUntil
Spins the UI queue, the way a backend's loop does, until the condition holds.- Parameters:
done- what to wait fortimeoutNanos- how long to keep spinning- Throws:
AssertionError- if the condition does not hold in time
-
pumpUntil
pumpUntil(BooleanSupplier, long)with a five-second limit. -
close
public void close()Uninstalls the runtime and stops the workers.- Specified by:
closein interfaceAutoCloseable
-