Source Code Cross Referenced for FileChooserHandlerTest.java in  » Testing » UISpec4J » org » uispec4j » interception » 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 » Testing » UISpec4J » org.uispec4j.interception 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.uispec4j.interception;
002:
003:        import org.uispec4j.Trigger;
004:        import org.uispec4j.utils.ArrayUtils;
005:        import org.uispec4j.utils.Utils;
006:
007:        import javax.swing.*;
008:        import java.awt.*;
009:        import java.io.File;
010:
011:        public class FileChooserHandlerTest extends InterceptionTestCase {
012:            private JFileChooser chooser = new JFileChooser();
013:            private Trigger SHOW_OPEN_DIALOG_TRIGGER = new Trigger() {
014:                public void run() throws Exception {
015:                    JFrame frame = new JFrame();
016:                    chooser.showOpenDialog(frame);
017:                }
018:            };
019:            private Trigger SHOW_SAVE_DIALOG_TRIGGER = new Trigger() {
020:                public void run() throws Exception {
021:                    JFrame frame = new JFrame();
022:                    chooser.showSaveDialog(frame);
023:                }
024:            };
025:            private Trigger SHOW_CUSTOM_DIALOG_TRIGGER = new Trigger() {
026:                public void run() throws Exception {
027:                    JFrame frame = new JFrame();
028:                    chooser.showDialog(frame, "OK");
029:                }
030:            };
031:            private File javaHome = new File(System.getProperty("java.home"));
032:            private File userHome = new File(System.getProperty("user.home"));
033:
034:            protected void setUp() throws Exception {
035:                super .setUp();
036:                chooser
037:                        .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
038:            }
039:
040:            public void testSelectionOfASingleFile() throws Exception {
041:                WindowInterceptor.init(SHOW_OPEN_DIALOG_TRIGGER).process(
042:                        FileChooserHandler.init().select(javaHome)).run();
043:                assertEquals(javaHome, chooser.getSelectedFile());
044:            }
045:
046:            public void testSelectionOfSeveralFiles() throws Exception {
047:                File[] files = { javaHome, userHome };
048:                WindowInterceptor.init(SHOW_OPEN_DIALOG_TRIGGER).process(
049:                        FileChooserHandler.init().select(files)).run();
050:                ArrayUtils.assertEquals(files, chooser.getSelectedFiles());
051:            }
052:
053:            public void testSelectionOfASingleStringifiedFile()
054:                    throws Exception {
055:                WindowInterceptor.init(SHOW_OPEN_DIALOG_TRIGGER).process(
056:                        FileChooserHandler.init().select(
057:                                javaHome.getAbsolutePath())).run();
058:                assertEquals(javaHome, chooser.getSelectedFile());
059:            }
060:
061:            public void testSelectionOfSeveralStringifiedFile()
062:                    throws Exception {
063:                String[] files = { javaHome.getAbsolutePath(),
064:                        userHome.getAbsolutePath() };
065:                WindowInterceptor.init(SHOW_OPEN_DIALOG_TRIGGER).process(
066:                        FileChooserHandler.init().select(files)).run();
067:                ArrayUtils.assertEquals(new File[] { javaHome, userHome },
068:                        chooser.getSelectedFiles());
069:            }
070:
071:            public void testCancelSelection() throws Exception {
072:                WindowInterceptor.init(SHOW_OPEN_DIALOG_TRIGGER).process(
073:                        FileChooserHandler.init().cancelSelection()).run();
074:                assertEquals(0, chooser.getSelectedFiles().length);
075:            }
076:
077:            public void testAssertCurrentDirEquals() throws Exception {
078:                chooser.setCurrentDirectory(javaHome);
079:                WindowInterceptor.init(SHOW_OPEN_DIALOG_TRIGGER).process(
080:                        FileChooserHandler.init().assertCurrentDirEquals(
081:                                javaHome).select(javaHome)).run();
082:            }
083:
084:            public void testAssertCurrentDirEqualsError() throws Exception {
085:                chooser.setCurrentDirectory(javaHome);
086:                checkError(SHOW_OPEN_DIALOG_TRIGGER, FileChooserHandler.init()
087:                        .assertCurrentDirEquals(userHome), javaHome,
088:                        "Unexpected current directory - expected:<" + userHome
089:                                + "> but was:<" + javaHome + ">");
090:            }
091:
092:            public void testAssertIsOpenSaveDialog() throws Exception {
093:                checkOk(SHOW_OPEN_DIALOG_TRIGGER, FileChooserHandler.init()
094:                        .assertIsOpenDialog());
095:                checkError(SHOW_OPEN_DIALOG_TRIGGER, FileChooserHandler.init()
096:                        .assertIsSaveDialog(), javaHome,
097:                        "Chooser is in 'open' mode");
098:
099:                checkOk(SHOW_SAVE_DIALOG_TRIGGER, FileChooserHandler.init()
100:                        .assertIsSaveDialog());
101:                checkError(SHOW_SAVE_DIALOG_TRIGGER, FileChooserHandler.init()
102:                        .assertIsOpenDialog(), javaHome,
103:                        "Chooser is in 'save' mode");
104:
105:                checkError(SHOW_CUSTOM_DIALOG_TRIGGER, FileChooserHandler
106:                        .init().assertIsSaveDialog(), javaHome,
107:                        "Chooser is in 'custom' mode");
108:                checkError(SHOW_CUSTOM_DIALOG_TRIGGER, FileChooserHandler
109:                        .init().assertIsOpenDialog(), javaHome,
110:                        "Chooser is in 'custom' mode");
111:            }
112:
113:            public void testAssertTitleEquals() throws Exception {
114:                chooser.setDialogTitle("title");
115:                checkOk(SHOW_OPEN_DIALOG_TRIGGER, FileChooserHandler.init()
116:                        .titleEquals("title"));
117:                checkError(SHOW_OPEN_DIALOG_TRIGGER, FileChooserHandler.init()
118:                        .titleEquals("error"), javaHome,
119:                        "Unexpected title - expected:<error> but was:<title>");
120:            }
121:
122:            public void testAssertApplyButtonTextEquals() throws Exception {
123:                chooser.setApproveButtonText("text");
124:                checkOk(SHOW_OPEN_DIALOG_TRIGGER, FileChooserHandler.init()
125:                        .assertApplyButtonTextEquals("text"));
126:                checkError(SHOW_OPEN_DIALOG_TRIGGER, FileChooserHandler.init()
127:                        .assertApplyButtonTextEquals("other"), javaHome,
128:                        "Unexpected apply button text - expected:<other> but was:<text>");
129:            }
130:
131:            public void testAssertAcceptsFilesAndDirectories() throws Exception {
132:                final int[] modes = { JFileChooser.FILES_ONLY,
133:                        JFileChooser.FILES_AND_DIRECTORIES,
134:                        JFileChooser.DIRECTORIES_ONLY };
135:                final String[] messages = {
136:                        "The file chooser accepts files only.",
137:                        "The file chooser accepts both files and directories.",
138:                        "The file chooser accepts directories only." };
139:                for (int i = 0; i < modes.length; i++) {
140:                    final FileChooserHandler[] interceptors = {
141:                            FileChooserHandler.init().assertAcceptsFilesOnly(),
142:                            FileChooserHandler.init()
143:                                    .assertAcceptsFilesAndDirectories(),
144:                            FileChooserHandler.init()
145:                                    .assertAcceptsDirectoriesOnly() };
146:                    chooser.setFileSelectionMode(modes[i]);
147:                    for (int j = 0; j < modes.length; j++) {
148:                        if (i == j) {
149:                            checkOk(SHOW_OPEN_DIALOG_TRIGGER, interceptors[j]);
150:                        } else {
151:                            checkError(SHOW_OPEN_DIALOG_TRIGGER,
152:                                    interceptors[j], javaHome, messages[i]);
153:                        }
154:                    }
155:                }
156:            }
157:
158:            public void testAssertMultiSelectionEnabled() throws Exception {
159:                checkMultiSelectionEnabled(true, "Multi selection is enabled.");
160:                checkMultiSelectionEnabled(false,
161:                        "Multi selection is not enabled.");
162:            }
163:
164:            public void testShownDialogIsNotAFileChooserButAJFrame()
165:                    throws Exception {
166:                checkUnexpectedWindowShown(new JFrame("title"), "title");
167:            }
168:
169:            public void testShownDialogIsNotAFileChooserButAModalDialog()
170:                    throws Exception {
171:                checkUnexpectedWindowShown(createModalDialog("aDialog"),
172:                        "aDialog");
173:            }
174:
175:            private void checkUnexpectedWindowShown(final Window window,
176:                    String title) {
177:                checkAssertionFailedError(WindowInterceptor.init(new Trigger() {
178:                    public void run() throws Exception {
179:                        window.setVisible(true);
180:                    }
181:                }).process(FileChooserHandler.init().select(javaHome)),
182:                        "The shown window is not a file chooser - window content:"
183:                                + Utils.LINE_SEPARATOR + "<window title=\""
184:                                + title + "\"/>");
185:            }
186:
187:            private void checkOk(Trigger trigger, FileChooserHandler handler) {
188:                WindowInterceptor.init(trigger).process(
189:                        handler.select(javaHome)).run();
190:            }
191:
192:            private void checkError(Trigger trigger,
193:                    FileChooserHandler handler, File selectedFile,
194:                    String errorMessage) {
195:                checkAssertionFailedError(WindowInterceptor.init(trigger)
196:                        .process(handler.select(selectedFile)), errorMessage);
197:            }
198:
199:            private void checkMultiSelectionEnabled(boolean enabled,
200:                    String message) {
201:                chooser.setMultiSelectionEnabled(enabled);
202:                checkOk(SHOW_OPEN_DIALOG_TRIGGER, FileChooserHandler.init()
203:                        .assertMultiSelectionEnabled(enabled));
204:                checkError(SHOW_OPEN_DIALOG_TRIGGER, FileChooserHandler.init()
205:                        .assertMultiSelectionEnabled(!enabled), javaHome,
206:                        message);
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.