Source Code Cross Referenced for JFileChooserTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Anton Avtamonov
019:         * @version $Revision$
020:         */package javax.swing;
021:
022:        import java.awt.event.ActionEvent;
023:        import java.awt.event.ActionListener;
024:        import java.awt.event.KeyEvent;
025:        import java.io.File;
026:        import java.io.IOException;
027:        import javax.swing.filechooser.FileFilter;
028:        import javax.swing.filechooser.FileSystemView;
029:        import javax.swing.filechooser.FileView;
030:        import javax.swing.plaf.FileChooserUI;
031:        import javax.swing.plaf.basic.BasicFileChooserUI;
032:
033:        public class JFileChooserTest extends SwingTestCase {
034:            private JFileChooser chooser;
035:
036:            public JFileChooserTest(final String name) {
037:                super (name);
038:                setIgnoreNotImplemented(true);
039:            }
040:
041:            @Override
042:            protected void setUp() throws Exception {
043:                super .setUp();
044:                timeoutDelay = 5 * DEFAULT_TIMEOUT_DELAY;
045:                chooser = new JFileChooser();
046:                propertyChangeController = new PropertyChangeController();
047:                chooser.addPropertyChangeListener(propertyChangeController);
048:            }
049:
050:            @Override
051:            protected void tearDown() throws Exception {
052:                chooser = null;
053:                super .tearDown();
054:            }
055:
056:            public void testJFileChooser() throws Exception {
057:                assertNotNull(chooser.getCurrentDirectory());
058:                assertEquals(FileSystemView.getFileSystemView()
059:                        .getDefaultDirectory(), chooser.getCurrentDirectory());
060:                File testDir = new File("testDir");
061:                testDir.deleteOnExit();
062:                testDir.mkdir();
063:                chooser = new JFileChooser(testDir);
064:                assertEqualsIgnoreCase(testDir.getAbsolutePath(), chooser
065:                        .getCurrentDirectory().getAbsolutePath());
066:                chooser = new JFileChooser(testDir.getAbsolutePath());
067:                assertEqualsIgnoreCase(testDir.getAbsolutePath(), chooser
068:                        .getCurrentDirectory().getAbsolutePath());
069:                testDir.delete();
070:                testDir = new File("anotherTestDir");
071:                chooser = new JFileChooser(testDir);
072:                assertEquals(FileSystemView.getFileSystemView()
073:                        .getDefaultDirectory(), chooser.getCurrentDirectory());
074:                chooser = new JFileChooser(testDir.getAbsolutePath());
075:                assertEquals(FileSystemView.getFileSystemView()
076:                        .getDefaultDirectory(), chooser.getCurrentDirectory());
077:                chooser = new JFileChooser((String) null);
078:                assertEquals(FileSystemView.getFileSystemView()
079:                        .getDefaultDirectory(), chooser.getCurrentDirectory());
080:                final File defaultDir = new File("testDir");
081:                defaultDir.deleteOnExit();
082:                defaultDir.mkdir();
083:                try {
084:                    FileSystemView view = new FileSystemView() {
085:                        @Override
086:                        public File createNewFolder(final File containingDir)
087:                                throws IOException {
088:                            return containingDir;
089:                        }
090:
091:                        @Override
092:                        public File getDefaultDirectory() {
093:                            return defaultDir;
094:                        }
095:                    };
096:                    chooser = new JFileChooser(view);
097:                    assertEquals(view, chooser.getFileSystemView());
098:                    assertEqualsIgnoreCase(defaultDir.getAbsolutePath(),
099:                            chooser.getCurrentDirectory().getAbsolutePath());
100:                } finally {
101:                    defaultDir.delete();
102:                }
103:            }
104:
105:            public void testJFileChooser_FSV() throws Exception {
106:                File testDir = new File("testDir");
107:                testDir.deleteOnExit();
108:                testDir.mkdir();
109:                chooser = new JFileChooser();
110:                assertEquals(FileSystemView.getFileSystemView(), chooser
111:                        .getFileSystemView());
112:                chooser = new JFileChooser(testDir);
113:                assertEquals(FileSystemView.getFileSystemView(), chooser
114:                        .getFileSystemView());
115:                chooser = new JFileChooser((File) null);
116:                assertEquals(FileSystemView.getFileSystemView(), chooser
117:                        .getFileSystemView());
118:                chooser = new JFileChooser(testDir.getAbsolutePath());
119:                assertEquals(FileSystemView.getFileSystemView(), chooser
120:                        .getFileSystemView());
121:                chooser = new JFileChooser((String) null);
122:                assertEquals(FileSystemView.getFileSystemView(), chooser
123:                        .getFileSystemView());
124:                chooser = new JFileChooser(FileSystemView.getFileSystemView());
125:                assertEquals(FileSystemView.getFileSystemView(), chooser
126:                        .getFileSystemView());
127:                chooser = new JFileChooser((FileSystemView) null);
128:                assertEquals(FileSystemView.getFileSystemView(), chooser
129:                        .getFileSystemView());
130:                chooser = new JFileChooser(testDir, FileSystemView
131:                        .getFileSystemView());
132:                assertEquals(FileSystemView.getFileSystemView(), chooser
133:                        .getFileSystemView());
134:                chooser = new JFileChooser(testDir, null);
135:                assertEquals(FileSystemView.getFileSystemView(), chooser
136:                        .getFileSystemView());
137:                chooser = new JFileChooser((File) null, FileSystemView
138:                        .getFileSystemView());
139:                assertEquals(FileSystemView.getFileSystemView(), chooser
140:                        .getFileSystemView());
141:                chooser = new JFileChooser((File) null, null);
142:                assertEquals(FileSystemView.getFileSystemView(), chooser
143:                        .getFileSystemView());
144:                chooser = new JFileChooser(testDir.getAbsolutePath(),
145:                        FileSystemView.getFileSystemView());
146:                assertEquals(FileSystemView.getFileSystemView(), chooser
147:                        .getFileSystemView());
148:                chooser = new JFileChooser(testDir.getAbsolutePath(), null);
149:                assertEquals(FileSystemView.getFileSystemView(), chooser
150:                        .getFileSystemView());
151:                chooser = new JFileChooser((String) null, FileSystemView
152:                        .getFileSystemView());
153:                assertEquals(FileSystemView.getFileSystemView(), chooser
154:                        .getFileSystemView());
155:                chooser = new JFileChooser((String) null, null);
156:                assertEquals(FileSystemView.getFileSystemView(), chooser
157:                        .getFileSystemView());
158:                testDir.delete();
159:            }
160:
161:            //TODO
162:            public void testSetup() throws Exception {
163:                chooser = new JFileChooser();
164:                assertEquals(FileSystemView.getFileSystemView(), chooser
165:                        .getFileSystemView());
166:                chooser.setup(FileSystemView.getFileSystemView());
167:                assertEquals(FileSystemView.getFileSystemView(), chooser
168:                        .getFileSystemView());
169:                chooser.setup(null);
170:                assertEquals(FileSystemView.getFileSystemView(), chooser
171:                        .getFileSystemView());
172:
173:                final File defaultDir = new File("testDir");
174:                defaultDir.deleteOnExit();
175:                try {
176:                    defaultDir.mkdir();
177:                    FileSystemView view = new FileSystemView() {
178:                        @Override
179:                        public File createNewFolder(final File containingDir)
180:                                throws IOException {
181:                            return containingDir;
182:                        }
183:
184:                        @Override
185:                        public File getDefaultDirectory() {
186:                            return defaultDir;
187:                        }
188:                    };
189:                    chooser.setup(view);
190:                    assertEquals(view, chooser.getFileSystemView());
191:                    assertEquals(FileSystemView.getFileSystemView()
192:                            .getDefaultDirectory(), chooser
193:                            .getCurrentDirectory());
194:                    chooser.setup(FileSystemView.getFileSystemView());
195:                    assertEquals(FileSystemView.getFileSystemView(), chooser
196:                            .getFileSystemView());
197:                    chooser.setup(view);
198:                    assertEquals(view, chooser.getFileSystemView());
199:                    chooser.setup(null);
200:                    assertEquals(FileSystemView.getFileSystemView(), chooser
201:                            .getFileSystemView());
202:                } catch (Throwable t) {
203:                    defaultDir.delete();
204:                    fail("Detected problem " + t.getMessage());
205:                }
206:            }
207:
208:            public void testGetSetDragEnabled() throws Exception {
209:                assertFalse(chooser.getDragEnabled());
210:                chooser.setDragEnabled(true);
211:                assertTrue(chooser.getDragEnabled());
212:                assertFalse(propertyChangeController.isChanged());
213:            }
214:
215:            public void testGetSetSelectedFile() throws Exception {
216:                assertNull(chooser.getSelectedFile());
217:                File selectedFile = new File("testFile");
218:                chooser.setSelectedFile(selectedFile);
219:                assertEquals(selectedFile, chooser.getSelectedFile());
220:                assertEquals(0, chooser.getSelectedFiles().length);
221:                assertTrue(propertyChangeController
222:                        .isChanged("SelectedFileChangedProperty"));
223:                selectedFile = new File("testDir");
224:                selectedFile.deleteOnExit();
225:                selectedFile.mkdir();
226:                chooser.setSelectedFile(selectedFile);
227:                assertEquals(selectedFile, chooser.getSelectedFile());
228:            }
229:
230:            public void testGetSetSelectedFiles() throws Exception {
231:                assertEquals(0, chooser.getSelectedFiles().length);
232:                chooser.setSelectedFile(new File("c"));
233:                assertEquals(0, chooser.getSelectedFiles().length);
234:                propertyChangeController.reset();
235:                File selectedFile = new File("a");
236:                File[] files = new File[] { selectedFile, new File("b") };
237:                chooser.setSelectedFiles(files);
238:                assertNotSame(files, chooser.getSelectedFiles());
239:                assertEquals(files.length, chooser.getSelectedFiles().length);
240:                assertEquals(selectedFile, chooser.getSelectedFile());
241:                assertTrue(propertyChangeController
242:                        .isChanged("SelectedFilesChangedProperty"));
243:                assertTrue(propertyChangeController
244:                        .isChanged("SelectedFileChangedProperty"));
245:                propertyChangeController.reset();
246:                files = new File[] { new File("b"), selectedFile };
247:                chooser.setSelectedFiles(files);
248:                assertNotSame(files, chooser.getSelectedFiles());
249:                assertEquals(files.length, chooser.getSelectedFiles().length);
250:                assertEquals(new File("b"), chooser.getSelectedFile());
251:                assertTrue(propertyChangeController
252:                        .isChanged("SelectedFilesChangedProperty"));
253:                assertTrue(propertyChangeController
254:                        .isChanged("SelectedFileChangedProperty"));
255:                propertyChangeController.reset();
256:                chooser.setSelectedFiles(new File[] { new File("b"),
257:                        selectedFile });
258:                assertTrue(propertyChangeController
259:                        .isChanged("SelectedFilesChangedProperty"));
260:                assertFalse(propertyChangeController
261:                        .isChanged("SelectedFileChangedProperty"));
262:            }
263:
264:            public void testGetSetCurrentDirectory() throws Exception {
265:                assertEquals(FileSystemView.getFileSystemView()
266:                        .getDefaultDirectory(), chooser.getCurrentDirectory());
267:                File dir = new File("testDir");
268:                dir.deleteOnExit();
269:                dir.mkdir();
270:                File innerDir = new File(dir, "innerDir");
271:                innerDir.deleteOnExit();
272:                innerDir.mkdir();
273:                File file = new File(innerDir, "innerFile");
274:                file.deleteOnExit();
275:                file.createNewFile();
276:                try {
277:                    chooser.setCurrentDirectory(dir);
278:                    assertEqualsIgnoreCase(dir.getAbsolutePath(), chooser
279:                            .getCurrentDirectory().getAbsolutePath());
280:                    chooser.setCurrentDirectory(file);
281:                    assertEqualsIgnoreCase(innerDir.getAbsolutePath(), chooser
282:                            .getCurrentDirectory().getAbsolutePath());
283:                } finally {
284:                    file.delete();
285:                    innerDir.delete();
286:                    dir.delete();
287:                }
288:            }
289:
290:            public void testChangeToParentDirectory() throws Exception {
291:                chooser.changeToParentDirectory();
292:                assertEquals(FileSystemView.getFileSystemView()
293:                        .getDefaultDirectory().getParentFile(), chooser
294:                        .getCurrentDirectory());
295:            }
296:
297:            public void testGetSetControlButtonsAreShown() throws Exception {
298:                assertTrue(chooser.getControlButtonsAreShown());
299:                chooser.setControlButtonsAreShown(false);
300:                assertFalse(chooser.getControlButtonsAreShown());
301:                assertTrue(propertyChangeController
302:                        .isChanged("ControlButtonsAreShownChangedProperty"));
303:            }
304:
305:            public void testgetSetDialogType() throws Exception {
306:                assertEquals(JFileChooser.OPEN_DIALOG, chooser.getDialogType());
307:                chooser.setDialogType(JFileChooser.SAVE_DIALOG);
308:                assertEquals(JFileChooser.SAVE_DIALOG, chooser.getDialogType());
309:                assertTrue(propertyChangeController
310:                        .isChanged("DialogTypeChangedProperty"));
311:                chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
312:                assertEquals(JFileChooser.CUSTOM_DIALOG, chooser
313:                        .getDialogType());
314:                testExceptionalCase(new IllegalArgumentCase() {
315:                    @Override
316:                    public void exceptionalAction() throws Exception {
317:                        chooser.setDialogType(10);
318:                    }
319:                });
320:            }
321:
322:            public void testGetSetDialogTitle() throws Exception {
323:                assertNull(chooser.getDialogTitle());
324:                assertEquals("Open", chooser.getUI().getDialogTitle(chooser));
325:                chooser.setDialogTitle("title");
326:                assertEquals("title", chooser.getDialogTitle());
327:                assertEquals("title", chooser.getUI().getDialogTitle(chooser));
328:                assertTrue(propertyChangeController
329:                        .isChanged("DialogTitleChangedProperty"));
330:            }
331:
332:            public void testGetSetApproveButtonToolTipText() throws Exception {
333:                assertNull(chooser.getApproveButtonToolTipText());
334:                chooser.setApproveButtonToolTipText("text");
335:                assertEquals("text", chooser.getApproveButtonToolTipText());
336:                assertTrue(propertyChangeController
337:                        .isChanged("ApproveButtonToolTipTextChangedProperty"));
338:                chooser.setApproveButtonToolTipText(null);
339:                assertNull(chooser.getApproveButtonToolTipText());
340:            }
341:
342:            public void testGetSetApproveButtonText() throws Exception {
343:                assertNull(chooser.getApproveButtonText());
344:                assertEquals("Open", chooser.getUI().getApproveButtonText(
345:                        chooser));
346:                chooser.setApproveButtonText("text");
347:                assertEquals(JFileChooser.OPEN_DIALOG, chooser.getDialogType());
348:                assertEquals("text", chooser.getApproveButtonText());
349:                assertEquals("text", chooser.getUI().getApproveButtonText(
350:                        chooser));
351:                assertTrue(propertyChangeController
352:                        .isChanged("ApproveButtonTextChangedProperty"));
353:                chooser.setApproveButtonText(null);
354:                assertNull(chooser.getApproveButtonToolTipText());
355:                assertEquals("Open", chooser.getUI().getApproveButtonText(
356:                        chooser));
357:            }
358:
359:            public void testGetSetApproveButtonMnemonic() throws Exception {
360:                assertEquals(0, chooser.getApproveButtonMnemonic());
361:                chooser.setApproveButtonMnemonic('c');
362:                assertEquals(KeyEvent.VK_C, chooser.getApproveButtonMnemonic());
363:                assertTrue(propertyChangeController
364:                        .isChanged("ApproveButtonMnemonicChangedProperty"));
365:                chooser.setApproveButtonMnemonic(KeyEvent.VK_X);
366:                assertEquals(KeyEvent.VK_X, chooser.getApproveButtonMnemonic());
367:            }
368:
369:            public void testGetAddRemoveResetChoosableFileFilters()
370:                    throws Exception {
371:                assertEquals(1, chooser.getChoosableFileFilters().length);
372:                FileFilter fileFilter = new FileFilter() {
373:                    @Override
374:                    public boolean accept(final File file) {
375:                        return false;
376:                    }
377:
378:                    @Override
379:                    public String getDescription() {
380:                        return "additional";
381:                    }
382:                };
383:                chooser.addChoosableFileFilter(fileFilter);
384:                assertEquals(2, chooser.getChoosableFileFilters().length);
385:                assertEquals("additional", chooser.getChoosableFileFilters()[1]
386:                        .getDescription());
387:                assertTrue(propertyChangeController
388:                        .isChanged("ChoosableFileFilterChangedProperty"));
389:                assertTrue(propertyChangeController
390:                        .isChanged("fileFilterChanged"));
391:                propertyChangeController.reset();
392:                chooser.removeChoosableFileFilter(fileFilter);
393:                assertEquals(1, chooser.getChoosableFileFilters().length);
394:                assertTrue(propertyChangeController
395:                        .isChanged("ChoosableFileFilterChangedProperty"));
396:                chooser.addChoosableFileFilter(fileFilter);
397:                assertEquals(2, chooser.getChoosableFileFilters().length);
398:                propertyChangeController.reset();
399:                chooser.resetChoosableFileFilters();
400:                assertEquals(1, chooser.getChoosableFileFilters().length);
401:                assertTrue(propertyChangeController
402:                        .isChanged("ChoosableFileFilterChangedProperty"));
403:                chooser.resetChoosableFileFilters();
404:                assertTrue(propertyChangeController
405:                        .isChanged("ChoosableFileFilterChangedProperty"));
406:            }
407:
408:            public void testGetAcceptAllFileFilter() throws Exception {
409:                FileFilter acceptAllFilter = chooser.getAcceptAllFileFilter();
410:                assertNotNull(acceptAllFilter);
411:                assertEquals(acceptAllFilter, chooser.getUI()
412:                        .getAcceptAllFileFilter(chooser));
413:                chooser.removeChoosableFileFilter(acceptAllFilter);
414:                assertEquals(0, chooser.getChoosableFileFilters().length);
415:                assertTrue(acceptAllFilter == chooser.getAcceptAllFileFilter());
416:                assertEquals(acceptAllFilter, chooser.getUI()
417:                        .getAcceptAllFileFilter(chooser));
418:            }
419:
420:            public void testIsSetAcceptAllFilterUsed() throws Exception {
421:                assertTrue(chooser.isAcceptAllFileFilterUsed());
422:                chooser.setAcceptAllFileFilterUsed(false);
423:                assertFalse(chooser.isAcceptAllFileFilterUsed());
424:                assertEquals(0, chooser.getChoosableFileFilters().length);
425:                assertTrue(propertyChangeController
426:                        .isChanged("acceptAllFileFilterUsedChanged"));
427:                chooser.setAcceptAllFileFilterUsed(true);
428:                assertTrue(chooser.isAcceptAllFileFilterUsed());
429:                assertEquals(1, chooser.getChoosableFileFilters().length);
430:            }
431:
432:            public void testGetSetAccessory() throws Exception {
433:                assertNull(chooser.getAccessory());
434:                JComponent accessory = new JButton();
435:                chooser.setAccessory(accessory);
436:                assertEquals(accessory, chooser.getAccessory());
437:                assertTrue(propertyChangeController
438:                        .isChanged("AccessoryChangedProperty"));
439:            }
440:
441:            public void testGetSetFileSelectionMode_isSelectionEnabled()
442:                    throws Exception {
443:                assertEquals(JFileChooser.FILES_ONLY, chooser
444:                        .getFileSelectionMode());
445:                assertTrue(chooser.isFileSelectionEnabled());
446:                assertFalse(chooser.isDirectorySelectionEnabled());
447:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
448:                assertEquals(JFileChooser.DIRECTORIES_ONLY, chooser
449:                        .getFileSelectionMode());
450:                assertFalse(chooser.isFileSelectionEnabled());
451:                assertTrue(chooser.isDirectorySelectionEnabled());
452:                assertTrue(propertyChangeController
453:                        .isChanged("fileSelectionChanged"));
454:                chooser
455:                        .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
456:                assertEquals(JFileChooser.FILES_AND_DIRECTORIES, chooser
457:                        .getFileSelectionMode());
458:                assertTrue(chooser.isFileSelectionEnabled());
459:                assertTrue(chooser.isDirectorySelectionEnabled());
460:                testExceptionalCase(new IllegalArgumentCase() {
461:                    @Override
462:                    public void exceptionalAction() throws Exception {
463:                        chooser.setFileSelectionMode(10);
464:                    }
465:                });
466:            }
467:
468:            public void testIsSetMultiSelectionEnabled() throws Exception {
469:                assertFalse(chooser.isMultiSelectionEnabled());
470:                chooser.setMultiSelectionEnabled(true);
471:                assertTrue(chooser.isMultiSelectionEnabled());
472:                assertTrue(propertyChangeController
473:                        .isChanged("MultiSelectionEnabledChangedProperty"));
474:            }
475:
476:            public void testIsSetFileHidingEnabled() throws Exception {
477:                assertTrue(chooser.isFileHidingEnabled());
478:                chooser.setFileHidingEnabled(false);
479:                assertFalse(chooser.isFileHidingEnabled());
480:                assertTrue(propertyChangeController
481:                        .isChanged("FileHidingChanged"));
482:            }
483:
484:            public void testGetSetFileFilter() throws Exception {
485:                assertEquals(chooser.getAcceptAllFileFilter(), chooser
486:                        .getFileFilter());
487:                FileFilter fileFilter = new FileFilter() {
488:                    @Override
489:                    public boolean accept(final File file) {
490:                        return false;
491:                    }
492:
493:                    @Override
494:                    public String getDescription() {
495:                        return "description";
496:                    }
497:                };
498:                chooser.setFileFilter(fileFilter);
499:                assertEquals(fileFilter, chooser.getFileFilter());
500:                assertTrue(propertyChangeController
501:                        .isChanged("fileFilterChanged"));
502:            }
503:
504:            public void testGetSetFileView() throws Exception {
505:                assertNull(chooser.getFileView());
506:                assertNotNull(chooser.getUI().getFileView(chooser));
507:                FileView view = new FileView() {
508:                };
509:                chooser.setFileView(view);
510:                assertTrue(propertyChangeController
511:                        .isChanged("fileViewChanged"));
512:                assertEquals(view, chooser.getFileView());
513:                assertNotSame(view, chooser.getUI().getFileView(chooser));
514:            }
515:
516:            public void testGetName_Description_TypeDescription_Icon_Traversable()
517:                    throws Exception {
518:                File f = new File(".");
519:                assertEquals(chooser.getUI().getFileView(chooser).getName(f),
520:                        chooser.getName(f));
521:                assertEquals(chooser.getUI().getFileView(chooser)
522:                        .getDescription(f), chooser.getDescription(f));
523:                assertEquals(chooser.getUI().getFileView(chooser)
524:                        .getTypeDescription(f), chooser.getTypeDescription(f));
525:                assertEquals(chooser.getUI().getFileView(chooser).getIcon(f),
526:                        chooser.getIcon(f));
527:                assertTrue(chooser.isTraversable(f));
528:                final String description = "description";
529:                final Icon icon = new ImageIcon();
530:                final String name = "name";
531:                final String typeDescription = "typeDescription";
532:                FileView view = new FileView() {
533:                    @Override
534:                    public String getDescription(final File f) {
535:                        return description;
536:                    }
537:
538:                    @Override
539:                    public Icon getIcon(final File f) {
540:                        return icon;
541:                    }
542:
543:                    @Override
544:                    public String getName(final File f) {
545:                        return name;
546:                    }
547:
548:                    @Override
549:                    public String getTypeDescription(final File f) {
550:                        return typeDescription;
551:                    }
552:
553:                    @Override
554:                    public Boolean isTraversable(final File f) {
555:                        return Boolean.FALSE;
556:                    }
557:                };
558:                chooser.setFileView(view);
559:                assertEquals(name, chooser.getName(f));
560:                assertEquals(description, chooser.getDescription(f));
561:                assertEquals(typeDescription, chooser.getTypeDescription(f));
562:                assertEquals(icon, chooser.getIcon(f));
563:                assertFalse(chooser.isTraversable(f));
564:            }
565:
566:            public void testAccept() throws Exception {
567:                File f = new File(".");
568:                assertTrue(chooser.accept(f));
569:                chooser.setFileFilter(new FileFilter() {
570:                    @Override
571:                    public boolean accept(final File file) {
572:                        return false;
573:                    }
574:
575:                    @Override
576:                    public String getDescription() {
577:                        return null;
578:                    }
579:                });
580:                assertFalse(chooser.accept(f));
581:                chooser.setFileFilter(null);
582:                assertTrue(chooser.accept(f));
583:            }
584:
585:            public void testGetSetFileSystemView() throws Exception {
586:                assertEquals(FileSystemView.getFileSystemView(), chooser
587:                        .getFileSystemView());
588:                FileSystemView fileSystemView = new FileSystemView() {
589:                    @Override
590:                    public File createNewFolder(final File containingDir)
591:                            throws IOException {
592:                        return null;
593:                    }
594:                };
595:                chooser.setFileSystemView(fileSystemView);
596:                assertEquals(fileSystemView, chooser.getFileSystemView());
597:                assertTrue(propertyChangeController
598:                        .isChanged("FileSystemViewChanged"));
599:            }
600:
601:            public void testApproveSelection() throws Exception {
602:                TestActionListener listener = new TestActionListener();
603:                chooser.addActionListener(listener);
604:                chooser.approveSelection();
605:                assertNotNull(listener.getEvent());
606:                assertEquals(JFileChooser.APPROVE_SELECTION, listener
607:                        .getEvent().getActionCommand());
608:                assertEquals(chooser, listener.getEvent().getSource());
609:            }
610:
611:            public void testCancelSelection() throws Exception {
612:                TestActionListener listener = new TestActionListener();
613:                chooser.addActionListener(listener);
614:                chooser.cancelSelection();
615:                assertNotNull(listener.getEvent());
616:                assertEquals(JFileChooser.CANCEL_SELECTION, listener.getEvent()
617:                        .getActionCommand());
618:                assertEquals(chooser, listener.getEvent().getSource());
619:            }
620:
621:            public void testGetAddRemoveFireActionListeners() throws Exception {
622:                assertEquals(0, chooser.getActionListeners().length);
623:                TestActionListener listener = new TestActionListener();
624:                chooser.addActionListener(listener);
625:                chooser.addActionListener(new TestActionListener());
626:                chooser.fireActionPerformed("command");
627:                assertEquals("command", listener.getEvent().getActionCommand());
628:                assertEquals(2, chooser.getActionListeners().length);
629:                chooser.removeActionListener(listener);
630:                assertEquals(1, chooser.getActionListeners().length);
631:            }
632:
633:            public void testGetUpdateUI() throws Exception {
634:                FileChooserUI ui = chooser.getUI();
635:                assertNotNull(ui);
636:                FileChooserUI customUI = new BasicFileChooserUI(chooser);
637:                chooser.setUI(customUI);
638:                assertEquals(customUI, chooser.getUI());
639:                assertNotSame(ui, chooser.getUI());
640:                chooser.updateUI();
641:                assertNotSame(customUI, chooser.getUI());
642:            }
643:
644:            public void testGetUIClassID() throws Exception {
645:                assertEquals("FileChooserUI", chooser.getUIClassID());
646:            }
647:
648:            public void testgetAccessibleContext() throws Exception {
649:                assertTrue(chooser.getAccessibleContext() instanceof  JFileChooser.AccessibleJFileChooser);
650:            }
651:
652:            public void testGetName() {
653:                JFileChooser fc = new JFileChooser();
654:                assertNull(fc.getName());
655:            }
656:
657:            private class TestActionListener implements  ActionListener {
658:                private ActionEvent event;
659:
660:                public void actionPerformed(final ActionEvent e) {
661:                    event = e;
662:                }
663:
664:                public ActionEvent getEvent() {
665:                    return event;
666:                }
667:            }
668:
669:            private static void assertEqualsIgnoreCase(final String expected,
670:                    final String actual) {
671:                assertTrue(expected.compareToIgnoreCase(actual) == 0);
672:            }
673:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.