01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Anton Avtamonov
19: * @version $Revision$
20: */package javax.swing;
21:
22: import java.io.File;
23: import javax.swing.filechooser.FileFilter;
24:
25: public class JFileChooserRTest extends BasicSwingTestCase {
26: private JFileChooser chooser;
27:
28: public JFileChooserRTest(final String name) {
29: super (name);
30: }
31:
32: @Override
33: protected void setUp() throws Exception {
34: chooser = new JFileChooser();
35: }
36:
37: @Override
38: protected void tearDown() throws Exception {
39: chooser = null;
40: }
41:
42: public void testAddChoosableFileFilter() throws Exception {
43: FileFilter ff = new FileFilter() {
44: @Override
45: public boolean accept(File file) {
46: return false;
47: }
48:
49: @Override
50: public String getDescription() {
51: return "any";
52: }
53: };
54: assertEquals(1, chooser.getChoosableFileFilters().length);
55: chooser.addChoosableFileFilter(ff);
56: assertEquals(2, chooser.getChoosableFileFilters().length);
57: chooser.addChoosableFileFilter(ff);
58: assertEquals(2, chooser.getChoosableFileFilters().length);
59: chooser
60: .addChoosableFileFilter(chooser
61: .getAcceptAllFileFilter());
62: assertEquals(2, chooser.getChoosableFileFilters().length);
63: assertSame(chooser.getAcceptAllFileFilter(), chooser
64: .getChoosableFileFilters()[0]);
65: assertSame(ff, chooser.getChoosableFileFilters()[1]);
66: }
67:
68: public void testGetSetSelectedFile() throws Exception {
69: propertyChangeController = new PropertyChangeController();
70: chooser.addPropertyChangeListener(propertyChangeController);
71: assertNull(chooser.getSelectedFile());
72: File selectedFile = new File(new File(".").getCanonicalPath()
73: + File.separator + "testFile");
74: selectedFile.deleteOnExit();
75: chooser.setSelectedFile(selectedFile);
76: assertEquals(selectedFile, chooser.getSelectedFile());
77: assertEquals(0, chooser.getSelectedFiles().length);
78: assertEquals(selectedFile.getAbsoluteFile().getParentFile()
79: .getCanonicalFile(), chooser.getCurrentDirectory()
80: .getCanonicalFile());
81: selectedFile.mkdir();
82: chooser.setSelectedFile(selectedFile);
83: assertEquals(selectedFile, chooser.getSelectedFile());
84: assertTrue(propertyChangeController
85: .isChanged("SelectedFileChangedProperty"));
86: }
87: }
|