RFR: 8320303: Allow PassFailJFrame to accept single window creator

Alexey Ivanov aivanov at openjdk.org
Fri Nov 17 20:08:41 UTC 2023


Enhance `PassFailJFrame` for single-window test UI which is the most common case so that there's no need to return `List.of`.

With this change, the lambda or method reference passed to `Builder.testUI` will return Window instead of `List<Window>` (or `List<? extends Window>`.

This change adds new functional interface `WindowCreator` which returns a single Window; the existing interface is renamed to `WindowListCreator`.

It's backwards compatible change; the [FileChooserSymLinkTest.java](https://github.com/openjdk/jdk/blob/7f47c51aced9c724dbc9b0d8cbd88c49435da460/test/jdk/javax/swing/JFileChooser/FileChooserSymLinkTest.java) test which uses `Builder.testUI` works without change.

It was my main concern that it will be impossible to have two interfaces where one creates a `Windows` and another — `List<Windows>`. The Java compiler automatically selects the correct method based on the return type of the lambda expression, so that both cases are supported. The requirement to return a `List` where only one window is needed bothered me, and I finally solved it.

In addition to that, I added description to all the overloads of the `Builder.testUI` method and updated the sample in the class documentation.

Since the `PassFailJFrame` class isn't supposed to be extended, I marked it `final` to prevent anyone from doing it.

-------------

Commit messages:
 - 8320303: Allow PassFailJFrame to accept single window creator

Changes: https://git.openjdk.org/jdk/pull/16717/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16717&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8320303
  Stats: 152 lines in 1 file changed: 125 ins; 6 del; 21 mod
  Patch: https://git.openjdk.org/jdk/pull/16717.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/16717/head:pull/16717

PR: https://git.openjdk.org/jdk/pull/16717


More information about the client-libs-dev mailing list