Source Code Cross Referenced for CelsiusConverterTest.java in  » Testing » abbot-1.0.1 » example » 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 » abbot 1.0.1 » example 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package example;
002:
003:        import java.awt.Component;
004:
005:        import javax.swing.JButton;
006:        import javax.swing.JFrame;
007:        import javax.swing.JLabel;
008:        import javax.swing.JMenuItem;
009:        import javax.swing.JTextField;
010:
011:        import junit.extensions.abbot.ComponentTestFixture;
012:        import junit.extensions.abbot.TestHelper;
013:        import abbot.finder.matchers.ClassMatcher;
014:        import abbot.finder.matchers.JMenuItemMatcher;
015:        import abbot.tester.JButtonTester;
016:        import abbot.tester.JTextComponentTester;
017:
018:        /**
019:         * Demonstrates testing a simple Swing UI ({@link CelsiusConverter}) with
020:         * Abbot. 
021:         *   
022:         * @author Satadip Dutta (original)
023:         * @author Tom Roche (ported to new-style Abbot, added more tests)
024:         * @version $Id: CelsiusConverterTest.java 1597 2005-05-06 23:27:16Z tlroche $
025:         */
026:        public class CelsiusConverterTest extends ComponentTestFixture {
027:
028:            // for precision testing
029:            final static int DEFAULT_PRECISION = 0;
030:            final static int PRECISION2 = 2;
031:            final static int PRECISION3 = 3;
032:
033:            private CelsiusConverter cc;
034:            private JTextField tempCelsius;
035:            private JButton convertButton;
036:            private JLabel outputLabel;
037:
038:            private JTextComponentTester tt;
039:            private JButtonTester bt;
040:
041:            /** For older versions of JUnit. */
042:            public CelsiusConverterTest(String name) {
043:                super (name);
044:            }
045:
046:            protected void setUp() throws Exception {
047:                cc = new CelsiusConverter();
048:                JFrame frame = new JFrame();
049:                cc.enframe(frame);
050:                // Display at the current frame's desired size (avoids packing)
051:                showWindow(frame, null, false);
052:
053:                // only one JTextField in our UI, so we can just class-match
054:                tempCelsius = (JTextField) getFinder().find(
055:                        new ClassMatcher(JTextField.class));
056:                // ditto for the JButton
057:                convertButton = (JButton) getFinder().find(
058:                        new ClassMatcher(JButton.class));
059:                // But there's 2 JLabel's in our UI, so we need to add more
060:                // information
061:                outputLabel = (JLabel) getFinder().find(
062:                        new ClassMatcher(JLabel.class) {
063:                            public boolean matches(Component c) {
064:                                String text = CelsiusConverter
065:                                        .lookupString("output.label.text");
066:                                return super .matches(c)
067:                                        && ((JLabel) c).getText().equals(text);
068:                            }
069:                        });
070:
071:                tt = new JTextComponentTester();
072:                bt = new JButtonTester();
073:            }
074:
075:            public void testNegativeNumber() throws Exception {
076:
077:                tt.actionEnterText(tempCelsius, "-45"); //$NON-NLS-1$
078:                bt.actionClick(convertButton);
079:                assertEquals(CelsiusConverter.fahrenheitOutput(-49,
080:                        DEFAULT_PRECISION), outputLabel.getText());
081:            }
082:
083:            public void testBadInput() throws Exception {
084:                // get default text
085:                String originalText = outputLabel.getText();
086:                // nothing should change if the input is not parseable as a double
087:                tt.actionEnterText(tempCelsius, " HELLO "); //$NON-NLS-1$
088:                bt.actionClick(convertButton);
089:                assertTrue("Output changed for bad input", outputLabel
090:                        .getText().equals(originalText)); //$NON-NLS-1$
091:            }
092:
093:            public void testChangePrecision() throws Exception {
094:                JMenuItem item2 = (JMenuItem) getFinder().find(
095:                        new JMenuItemMatcher(String.valueOf(PRECISION2))); //$NON-NLS-1$
096:
097:                // the output should update to reflect a higher precision after making
098:                // a change, even with no new input
099:
100:                // initial precision is 0
101:                tt.actionEnterText(tempCelsius, "25.23"); //$NON-NLS-1$
102:                bt.actionClick(convertButton);
103:
104:                // now update precision and make sure output fields update too
105:                tt.actionSelectMenuItem(item2);
106:
107:                assertEquals(
108:                        "Failed to reflect change in precision", //$NON-NLS-1$
109:                        CelsiusConverter.fahrenheitOutput(77.41, PRECISION2),
110:                        outputLabel.getText());
111:            }
112:
113:            public void testHighPrecision() throws Exception {
114:                JMenuItem item3 = (JMenuItem) getFinder().find(
115:                        new JMenuItemMatcher(String.valueOf(PRECISION3))); //$NON-NLS-1$
116:                tt.actionSelectMenuItem(item3);
117:                tt.actionEnterText(tempCelsius, "-45.543"); //$NON-NLS-1$
118:                bt.actionClick(convertButton);
119:
120:                assertEquals(
121:                        "Failed to show answer with proper precision", //$NON-NLS-1$
122:                        CelsiusConverter.fahrenheitOutput(-49.977, PRECISION3),
123:                        outputLabel.getText());
124:            }
125:
126:            public static void main(String[] args) {
127:                /*
128:                junit.textui.TestRunner.main(new String[] {
129:                    CelsiusConverterTest.class.getName()
130:                });
131:                 */
132:                TestHelper.runTests(args, CelsiusConverterTest.class);
133:            }
134:
135:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.