Package limn.testing
Class TestPreferences
java.lang.Object
limn.testing.TestPreferences
- All Implemented Interfaces:
AutoCloseable
The system's preferences as a test puts them in place: a dark appearance, less motion, more
contrast, access keys underlined at all times. What
SystemPreferences.current() answers,
and what its listeners hear, is what a backend would have reported on a desktop set that way,
so an application's own test can check that it follows the system.
Open it in @BeforeEach or a try block, after the HeadlessUi, and close
it before that: closing puts back what SystemPreferences.current() answered when it was
opened, which in a headless test is SystemPreferences.NONE. Each setter reports at once,
so a listener hears a change as it would from the platform, and a value that does not change is
not heard.
try (TestPreferences system = new TestPreferences()) {
system.colorScheme(ColorScheme.DARK);
assertTrue(myTheme.isDark());
}
Everything here runs on the UI thread, as SystemPreferences.report(limn.scene.SystemPreferences) does.
-
Constructor Summary
ConstructorsConstructorDescriptionStarts from whatSystemPreferences.current()answers now, and changes nothing yet. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Puts back what the system reported when this was opened.increaseContrast(boolean increase) reduceMotion(boolean reduce) underlineAccessKeys(boolean underline)
-
Constructor Details
-
TestPreferences
public TestPreferences()Starts from whatSystemPreferences.current()answers now, and changes nothing yet.
-
-
Method Details
-
colorScheme
- Parameters:
scheme- the appearance the system reports now; nevernull- Returns:
- this
-
reduceMotion
- Parameters:
reduce- whether the system reports that the user asked for less motion- Returns:
- this
-
increaseContrast
- Parameters:
increase- whether the system reports that the user asked for more contrast- Returns:
- this
-
underlineAccessKeys
- Parameters:
underline- whether the system reports that access keys are underlined at all times- Returns:
- this
-
close
public void close()Puts back what the system reported when this was opened.- Specified by:
closein interfaceAutoCloseable
-