Skip to content

Commit

Permalink
8316025: Use testUI() method of PassFailJFrame.Builder in FileChooser…
Browse files Browse the repository at this point in the history
…SymLinkTest.java

Reviewed-by: azvegint
  • Loading branch information
aivanov-jdk committed Nov 1, 2023
1 parent 36de19d commit 7f47c51
Showing 1 changed file with 63 additions and 70 deletions.
133 changes: 63 additions & 70 deletions test/jdk/javax/swing/JFileChooser/FileChooserSymLinkTest.java
Expand Up @@ -22,21 +22,21 @@
*/

import java.awt.BorderLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;

import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;

/*
Expand All @@ -51,87 +51,80 @@
* @run main/manual FileChooserSymLinkTest
*/
public class FileChooserSymLinkTest {
private static final String INSTRUCTIONS = """
<html><body>
Instructions to Test:
<ol>
<li>Open an elevated <i>Command Prompt</i>.
<li>Paste the following commands:
<pre><code>cd /d C:\\
mkdir FileChooserTest
cd FileChooserTest
mkdir target
mklink /d link target</code></pre>
<li>Navigate to <code>C:\\FileChooserTest</code> in
the <code>JFileChooser</code>.
<li>Perform testing in single- and multi-selection modes:
<ul style="margin-bottom: 0px">
<li><strong>Single-selection:</strong>
<ol>
<li>Ensure <b>Enable multi-selection</b> is cleared
(the default state).
<li>Click <code>link</code> directory,
the absolute path of the symbolic
link should be displayed.<br>
If it's <code>null</code>, click <b>Fail</b>.
<li>Click <code>target</code> directory,
its absolute path should be displayed.
</ol>
<li><strong>Multi-selection:</strong>
<ol>
<li>Select <b>Enable multi-selection</b>.
<li>Click <code>link</code>,
<li>Press <kbd>Ctrl</kbd> and
then click <code>target</code>.
<li>Both should be selected and
their absolute paths should be displayed.
<li>If <code>link</code> can't be selected or
if its absolute path is <code>null</code>,
click <b>Fail</b>.
</ol>
</ul>
<p>If <code>link</code> can be selected in both
single- and multi-selection modes, click <b>Pass</b>.</p>
<li>When done with testing, paste the following commands to
remove the <code>FileChooserTest</code> directory:
<pre><code>cd \\
rmdir /s /q C:\\FileChooserTest</code></pre>
or use File Explorer to clean it up.
</ol>
""";

static JFrame frame;
static JFileChooser jfc;
static JPanel panel;
static JTextArea pathList;
static JCheckBox multiSelection;
static PassFailJFrame passFailJFrame;

public static void main(String[] args) throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
try {
initialize();
} catch (InterruptedException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
});
passFailJFrame.awaitAndCheck();
PassFailJFrame.builder()
.instructions(INSTRUCTIONS)
.rows(35)
.columns(50)
.testUI(FileChooserSymLinkTest::createTestUI)
.build()
.awaitAndCheck();
}

static void initialize() throws InterruptedException, InvocationTargetException {
//Initialize the components
final String INSTRUCTIONS = """
<html><body>
Instructions to Test:
<ol>
<li>Open an elevated <i>Command Prompt</i>.
<li>Paste the following commands:
<pre><code>cd /d C:\\
mkdir FileChooserTest
cd FileChooserTest
mkdir target
mklink /d link target</code></pre>
<li>Navigate to <code>C:\\FileChooserTest</code> in
the <code>JFileChooser</code>.
<li>Perform testing in single- and multi-selection modes:
<ul style="margin-bottom: 0px">
<li><strong>Single-selection:</strong>
<ol>
<li>Ensure <b>Enable multi-selection</b> is cleared
(the default state).
<li>Click <code>link</code> directory,
the absolute path of the symbolic
link should be displayed.<br>
If it's <code>null</code>, click <b>Fail</b>.
<li>Click <code>target</code> directory,
its absolute path should be displayed.
</ol>
<li><strong>Multi-selection:</strong>
<ol>
<li>Select <b>Enable multi-selection</b>.
<li>Click <code>link</code>,
<li>Press <kbd>Ctrl</kbd> and
then click <code>target</code>.
<li>Both should be selected and
their absolute paths should be displayed.
<li>If <code>link</code> can't be selected or
if its absolute path is <code>null</code>,
click <b>Fail</b>.
</ol>
</ul>
<p>If <code>link</code> can be selected in both
single- and multi-selection modes, click <b>Pass</b>.</p>
<li>When done with testing, paste the following commands to
remove the <code>FileChooserTest</code> directory:
<pre><code>cd \\
rmdir /s /q C:\\FileChooserTest</code></pre>
or use File Explorer to clean it up.
</ol>
""";
private static List<Window> createTestUI() {
frame = new JFrame("JFileChooser Symbolic Link test");
panel = new JPanel(new BorderLayout());
multiSelection = new JCheckBox("Enable Multi-Selection");
pathList = new JTextArea(10, 50);
jfc = new JFileChooser(new File("C:\\"));
passFailJFrame = new PassFailJFrame("Test Instructions", INSTRUCTIONS, 5L, 35, 50);

PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
panel.add(multiSelection, BorderLayout.EAST);
panel.add(new JScrollPane(pathList), BorderLayout.WEST);
Expand Down Expand Up @@ -166,6 +159,6 @@ public void propertyChange(PropertyChangeEvent evt) {
frame.add(panel, BorderLayout.NORTH);
frame.add(jfc, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
return List.of(frame);
}
}

3 comments on commit 7f47c51

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aivanov-jdk
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u

@openjdk
Copy link

@openjdk openjdk bot commented on 7f47c51 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aivanov-jdk the backport was successfully created on the branch aivanov-jdk-backport-7f47c51a in my personal fork of openjdk/jdk21u. To create a pull request with this backport targeting openjdk/jdk21u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 7f47c51a from the openjdk/jdk repository.

The commit being backported was authored by Alexey Ivanov on 1 Nov 2023 and was reviewed by Alexander Zvegintsev.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u:

$ git fetch https://github.com/openjdk-bots/jdk21u.git aivanov-jdk-backport-7f47c51a:aivanov-jdk-backport-7f47c51a
$ git checkout aivanov-jdk-backport-7f47c51a
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u.git aivanov-jdk-backport-7f47c51a

Please sign in to comment.