Skip to content

Commit 1d128dc

Browse files
committed
8316025: Use testUI() method of PassFailJFrame.Builder in FileChooserSymLinkTest.java
Backport-of: 7f47c51aced9c724dbc9b0d8cbd88c49435da460
1 parent 3c124e3 commit 1d128dc

File tree

1 file changed

+63
-70
lines changed

1 file changed

+63
-70
lines changed

test/jdk/javax/swing/JFileChooser/FileChooserSymLinkTest.java

+63-70
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222
*/
2323

2424
import java.awt.BorderLayout;
25+
import java.awt.Window;
2526
import java.awt.event.ActionEvent;
2627
import java.awt.event.ActionListener;
2728
import java.beans.PropertyChangeEvent;
2829
import java.beans.PropertyChangeListener;
2930
import java.io.File;
30-
import java.lang.reflect.InvocationTargetException;
3131
import java.util.Arrays;
32+
import java.util.List;
3233

3334
import javax.swing.JCheckBox;
3435
import javax.swing.JFileChooser;
3536
import javax.swing.JFrame;
3637
import javax.swing.JPanel;
37-
import javax.swing.JTextArea;
3838
import javax.swing.JScrollPane;
39-
import javax.swing.SwingUtilities;
39+
import javax.swing.JTextArea;
4040
import javax.swing.WindowConstants;
4141

4242
/*
@@ -51,87 +51,80 @@
5151
* @run main/manual FileChooserSymLinkTest
5252
*/
5353
public class FileChooserSymLinkTest {
54+
private static final String INSTRUCTIONS = """
55+
<html><body>
56+
Instructions to Test:
57+
<ol>
58+
<li>Open an elevated <i>Command Prompt</i>.
59+
<li>Paste the following commands:
60+
<pre><code>cd /d C:\\
61+
mkdir FileChooserTest
62+
cd FileChooserTest
63+
mkdir target
64+
mklink /d link target</code></pre>
65+
66+
<li>Navigate to <code>C:\\FileChooserTest</code> in
67+
the <code>JFileChooser</code>.
68+
<li>Perform testing in single- and multi-selection modes:
69+
<ul style="margin-bottom: 0px">
70+
<li><strong>Single-selection:</strong>
71+
<ol>
72+
<li>Ensure <b>Enable multi-selection</b> is cleared
73+
(the default state).
74+
<li>Click <code>link</code> directory,
75+
the absolute path of the symbolic
76+
link should be displayed.<br>
77+
If it's <code>null</code>, click <b>Fail</b>.
78+
<li>Click <code>target</code> directory,
79+
its absolute path should be displayed.
80+
</ol>
81+
<li><strong>Multi-selection:</strong>
82+
<ol>
83+
<li>Select <b>Enable multi-selection</b>.
84+
<li>Click <code>link</code>,
85+
<li>Press <kbd>Ctrl</kbd> and
86+
then click <code>target</code>.
87+
<li>Both should be selected and
88+
their absolute paths should be displayed.
89+
<li>If <code>link</code> can't be selected or
90+
if its absolute path is <code>null</code>,
91+
click <b>Fail</b>.
92+
</ol>
93+
</ul>
94+
<p>If <code>link</code> can be selected in both
95+
single- and multi-selection modes, click <b>Pass</b>.</p>
96+
<li>When done with testing, paste the following commands to
97+
remove the <code>FileChooserTest</code> directory:
98+
<pre><code>cd \\
99+
rmdir /s /q C:\\FileChooserTest</code></pre>
100+
101+
or use File Explorer to clean it up.
102+
</ol>
103+
""";
104+
54105
static JFrame frame;
55106
static JFileChooser jfc;
56107
static JPanel panel;
57108
static JTextArea pathList;
58109
static JCheckBox multiSelection;
59-
static PassFailJFrame passFailJFrame;
60110

61111
public static void main(String[] args) throws Exception {
62-
SwingUtilities.invokeAndWait(new Runnable() {
63-
public void run() {
64-
try {
65-
initialize();
66-
} catch (InterruptedException | InvocationTargetException e) {
67-
throw new RuntimeException(e);
68-
}
69-
}
70-
});
71-
passFailJFrame.awaitAndCheck();
112+
PassFailJFrame.builder()
113+
.instructions(INSTRUCTIONS)
114+
.rows(35)
115+
.columns(50)
116+
.testUI(FileChooserSymLinkTest::createTestUI)
117+
.build()
118+
.awaitAndCheck();
72119
}
73120

74-
static void initialize() throws InterruptedException, InvocationTargetException {
75-
//Initialize the components
76-
final String INSTRUCTIONS = """
77-
<html><body>
78-
Instructions to Test:
79-
<ol>
80-
<li>Open an elevated <i>Command Prompt</i>.
81-
<li>Paste the following commands:
82-
<pre><code>cd /d C:\\
83-
mkdir FileChooserTest
84-
cd FileChooserTest
85-
mkdir target
86-
mklink /d link target</code></pre>
87-
88-
<li>Navigate to <code>C:\\FileChooserTest</code> in
89-
the <code>JFileChooser</code>.
90-
<li>Perform testing in single- and multi-selection modes:
91-
<ul style="margin-bottom: 0px">
92-
<li><strong>Single-selection:</strong>
93-
<ol>
94-
<li>Ensure <b>Enable multi-selection</b> is cleared
95-
(the default state).
96-
<li>Click <code>link</code> directory,
97-
the absolute path of the symbolic
98-
link should be displayed.<br>
99-
If it's <code>null</code>, click <b>Fail</b>.
100-
<li>Click <code>target</code> directory,
101-
its absolute path should be displayed.
102-
</ol>
103-
<li><strong>Multi-selection:</strong>
104-
<ol>
105-
<li>Select <b>Enable multi-selection</b>.
106-
<li>Click <code>link</code>,
107-
<li>Press <kbd>Ctrl</kbd> and
108-
then click <code>target</code>.
109-
<li>Both should be selected and
110-
their absolute paths should be displayed.
111-
<li>If <code>link</code> can't be selected or
112-
if its absolute path is <code>null</code>,
113-
click <b>Fail</b>.
114-
</ol>
115-
</ul>
116-
<p>If <code>link</code> can be selected in both
117-
single- and multi-selection modes, click <b>Pass</b>.</p>
118-
<li>When done with testing, paste the following commands to
119-
remove the <code>FileChooserTest</code> directory:
120-
<pre><code>cd \\
121-
rmdir /s /q C:\\FileChooserTest</code></pre>
122-
123-
or use File Explorer to clean it up.
124-
</ol>
125-
""";
121+
private static List<Window> createTestUI() {
126122
frame = new JFrame("JFileChooser Symbolic Link test");
127123
panel = new JPanel(new BorderLayout());
128124
multiSelection = new JCheckBox("Enable Multi-Selection");
129125
pathList = new JTextArea(10, 50);
130126
jfc = new JFileChooser(new File("C:\\"));
131-
passFailJFrame = new PassFailJFrame("Test Instructions", INSTRUCTIONS, 5L, 35, 50);
132127

133-
PassFailJFrame.addTestWindow(frame);
134-
PassFailJFrame.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL);
135128
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
136129
panel.add(multiSelection, BorderLayout.EAST);
137130
panel.add(new JScrollPane(pathList), BorderLayout.WEST);
@@ -166,6 +159,6 @@ public void propertyChange(PropertyChangeEvent evt) {
166159
frame.add(panel, BorderLayout.NORTH);
167160
frame.add(jfc, BorderLayout.CENTER);
168161
frame.pack();
169-
frame.setVisible(true);
162+
return List.of(frame);
170163
}
171164
}

0 commit comments

Comments
 (0)