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


001:        package org.uispec4j;
002:
003:        import junit.framework.Assert;
004:        import org.uispec4j.assertion.Assertion;
005:
006:        import javax.swing.Icon;
007:        import javax.swing.JLabel;
008:        import javax.swing.text.JTextComponent;
009:        import java.awt.Component;
010:
011:        /**
012:         * Wrapper for JTextComponent/JLabel components.
013:         */
014:        public class TextBox extends AbstractUIComponent {
015:            public static final String TYPE_NAME = "textBox";
016:            public static final Class[] SWING_CLASSES = { JTextComponent.class,
017:                    JLabel.class };
018:
019:            private Handler handler;
020:
021:            public TextBox(JTextComponent textComponent) {
022:                this .handler = TextBoxHandlerForHtmlTextComponent
023:                        .init(textComponent);
024:                if (handler == null) {
025:                    this .handler = new TextBoxHandlerForRawTextComponent(
026:                            textComponent);
027:                }
028:            }
029:
030:            public TextBox(JLabel label) {
031:                this .handler = new TextBoxHandlerForLabel(label);
032:            }
033:
034:            public String getDescriptionTypeName() {
035:                return TYPE_NAME;
036:            }
037:
038:            public Component getAwtComponent() {
039:                return handler.getAwtComponent();
040:            }
041:
042:            /**
043:             * Simulates pressing a key while the focus is in the text box.<br>
044:             * Warning: the default cursor position is 0.
045:             */
046:            public void pressKey(Key key) {
047:                handler.pressKey(key);
048:            }
049:
050:            /**
051:             * Replaces the text box contents and simulates pressing the Enter key.
052:             */
053:            public void setText(String text) {
054:                handler.setText(text);
055:            }
056:
057:            /**
058:             * Inserts text at the given position without pressing Enter.
059:             */
060:            public void insertText(String text, int position) {
061:                handler.insertText(text, position);
062:            }
063:
064:            public String getText() {
065:                return handler.getText();
066:            }
067:
068:            public Assertion textIsEmpty() {
069:                return handler.textIsEmpty();
070:            }
071:
072:            /**
073:             * Checks the displayed text in cases where HTML text is used. This is
074:             * different from {@link #textIsEmpty()} in that whitespaces, carriage return
075:             * and other formatting adjustments are ignored.
076:             */
077:            public Assertion htmlEquals(String html) {
078:                return handler.htmlEquals(html);
079:            }
080:
081:            /**
082:             * Checks that the text box contains a number of substrings, in a given order.
083:             * This method is useful for checking key information in the displayed string,
084:             * without being too dependent on the actual wording.
085:             */
086:            public Assertion textContains(final String[] orderedTexts) {
087:                return new Assertion() {
088:                    public void check() {
089:                        String actual = handler.getText();
090:                        int index = 0;
091:                        for (int i = 0; i < orderedTexts.length; i++) {
092:                            String text = orderedTexts[i];
093:                            index = actual.indexOf(text, index);
094:                            if (index < 0) {
095:                                if (actual.indexOf(text) < 0) {
096:                                    Assert
097:                                            .fail("The component text does not contain '"
098:                                                    + text
099:                                                    + "' "
100:                                                    + "- actual content is:"
101:                                                    + actual);
102:                                } else {
103:                                    Assert
104:                                            .fail("The component text does not contain '"
105:                                                    + text
106:                                                    + "' at the expected position "
107:                                                    + "- actual content is:"
108:                                                    + actual);
109:                                }
110:                            } else {
111:                                index += text.length();
112:                            }
113:                        }
114:                    }
115:                };
116:            }
117:
118:            public Assertion textEquals(String text) {
119:                return handler.textEquals(text);
120:            }
121:
122:            public Assertion textContains(String text) {
123:                return handler.textContains(text);
124:            }
125:
126:            public Assertion textDoesNotContain(String text) {
127:                return handler.textDoesNotContain(text);
128:            }
129:
130:            public Assertion isEditable() {
131:                return handler.isEditable();
132:            }
133:
134:            /**
135:             * Checks the icon displayed by the component. Please note that equals()
136:             * not being defined for Icon implementations, you will have to provide a pointer
137:             * to the actual Icon instance that is used in the production code. This make
138:             * this method mostly suited to unit testing.
139:             */
140:            public Assertion iconEquals(Icon icon) {
141:                return handler.iconEquals(icon);
142:            }
143:
144:            /**
145:             * Simulates a click on an hyperlink given a part of the link text.
146:             * An exception will be thrown if zero or more than one hyperlinks are
147:             * found with this text.
148:             */
149:            public void clickOnHyperlink(String link) {
150:                handler.clickOnHyperlink(link);
151:            }
152:
153:            /**
154:             * @see #clickOnHyperlink(String)
155:             */
156:            public Trigger triggerClickOnHyperlink(final String name) {
157:                return new Trigger() {
158:                    public void run() throws Exception {
159:                        clickOnHyperlink(name);
160:                    }
161:                };
162:            }
163:
164:            interface Handler {
165:                Component getAwtComponent();
166:
167:                void setText(String text);
168:
169:                void insertText(String text, int position);
170:
171:                String getText();
172:
173:                Assertion textIsEmpty();
174:
175:                Assertion textEquals(String text);
176:
177:                Assertion textContains(String text);
178:
179:                Assertion textDoesNotContain(String text);
180:
181:                Assertion isEditable();
182:
183:                void clickOnHyperlink(String link);
184:
185:                void pressKey(Key key);
186:
187:                Assertion iconEquals(Icon icon);
188:
189:                Assertion htmlEquals(String html);
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.