Skip to content

Commit 676d7d6

Browse files
committed
8283621: Write a regression test for CCC4400728
Backport-of: 632825c6d2933c8f1e63569199413ecaa74b6740
1 parent 46dad76 commit 676d7d6

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.io.File;
25+
import java.util.concurrent.atomic.AtomicReference;
26+
import javax.swing.JFileChooser;
27+
import javax.swing.SwingUtilities;
28+
29+
/*
30+
* @test
31+
* @bug 4400728
32+
* @summary This testcase tests CCC4400728 request, checks whether JFileChooser
33+
* constructor set correct default directory or not, it is typically
34+
* the "Documents" folder on Windows, and the user's home directory
35+
* on Unix.
36+
* @run main JFileChooserDefaultDirectoryTest
37+
*/
38+
public class JFileChooserDefaultDirectoryTest {
39+
40+
public static void main(String[] args) throws Exception {
41+
final AtomicReference<String> actual = new AtomicReference<>("");
42+
SwingUtilities.invokeAndWait(() -> {
43+
JFileChooser jFileChooser = new JFileChooser();
44+
actual.set(jFileChooser.getFileSystemView()
45+
.getDefaultDirectory()
46+
.getName());
47+
});
48+
String actualDefaultDirectory = actual.get();
49+
final boolean isWindows = System.getProperty("os.name")
50+
.startsWith("Windows");
51+
if (isWindows) {
52+
if (actualDefaultDirectory.equals("Documents")) {
53+
System.out.println("Test Passed");
54+
} else {
55+
throw new RuntimeException(
56+
"Test Failed, JFileChooser constructor sets incorrect" +
57+
" default directory, actual = " +
58+
actualDefaultDirectory +
59+
" expected should be 'Documents'");
60+
}
61+
} else {
62+
final String userHome = System.getProperty("user.home");
63+
System.out.println("UserHome dir = " + userHome);
64+
String expectedDefaultDirectory = new File(userHome).getName();
65+
if (expectedDefaultDirectory.equals(actualDefaultDirectory)) {
66+
System.out.println("Test Passed");
67+
} else {
68+
throw new RuntimeException(
69+
"Test Failed, JFileChooser constructor sets incorrect" +
70+
" default directory, actual = " +
71+
actualDefaultDirectory + " expected = " +
72+
expectedDefaultDirectory);
73+
}
74+
}
75+
}
76+
77+
}

0 commit comments

Comments
 (0)