Package limn.testing

Class TestPreferences

java.lang.Object
limn.testing.TestPreferences
All Implemented Interfaces:
AutoCloseable

public final class TestPreferences extends Object implements 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 Details

  • Method Details

    • colorScheme

      public TestPreferences colorScheme(SystemPreferences.ColorScheme scheme)
      Parameters:
      scheme - the appearance the system reports now; never null
      Returns:
      this
    • reduceMotion

      public TestPreferences reduceMotion(boolean reduce)
      Parameters:
      reduce - whether the system reports that the user asked for less motion
      Returns:
      this
    • increaseContrast

      public TestPreferences increaseContrast(boolean increase)
      Parameters:
      increase - whether the system reports that the user asked for more contrast
      Returns:
      this
    • underlineAccessKeys

      public TestPreferences underlineAccessKeys(boolean underline)
      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:
      close in interface AutoCloseable