Source Code Cross Referenced for Compare.java in  » Portal » Open-Portal » com » sun » portal » wireless » tests » 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 » Portal » Open Portal » com.sun.portal.wireless.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.wireless.tests;
002:
003:        import java.io.*;
004:        import java.util.*;
005:        import junit.framework.*;
006:
007:        /**
008:         * Compares test results with expected and unexpected reference output.  Each
009:         * line of the reference file(s) is compared against the test results.  A test
010:         * failure is generated if:
011:         * <ul>
012:         * <li> any line in the expected reference file is not found as a substring
013:         *      of any line in the test results, or </li>
014:         * <li> any line in the unexpected reference file is found as a substring of
015:         *      any line in the test results </li>
016:         * </ul>
017:         */
018:        public class Compare {
019:            public TestCase test = null;
020:            public PrintStream out = null;
021:
022:            /**
023:             * Creates a <code>Compare</code> class with error messages going to
024:             * stdout.
025:             *
026:             * @param test the test case calling this class
027:             */
028:            public Compare(TestCase test) {
029:                this (test, System.out);
030:            }
031:
032:            /**
033:             * Creates a <code>Compare</code> class.
034:             *
035:             * @param test the test case calling this class
036:             * @param out  where error messages will be sent
037:             */
038:            public Compare(TestCase test, PrintStream out) {
039:                this .test = test;
040:                this .out = out;
041:            }
042:
043:            /**
044:             * Checks the given test results against expected and unexpected output.
045:             *
046:             * @param result     the test results
047:             * @param expected   the filename for expected output
048:             * @param unexpected the filename for unexpected output
049:             */
050:            public void check(String result, String expected, String unexpected) {
051:                check(result, expected, true);
052:                check(result, unexpected, false);
053:            }
054:
055:            /**
056:             * Checks the given test results against expected output.
057:             *
058:             * @param result   the test results
059:             * @param filename the filename for expected output
060:             */
061:            public void expected(String result, String filename) {
062:                check(result, filename, true);
063:            }
064:
065:            /**
066:             * Checks the given test results against unexpected output.
067:             *
068:             * @param result   the test results
069:             * @param filename the filename for unexpected output
070:             */
071:            public void unexpected(String result, String filename) {
072:                check(result, filename, false);
073:            }
074:
075:            private void check(String result, String filename, boolean expected) {
076:                // check for null result
077:                if (result == null) {
078:                    out.println("null result");
079:                    return;
080:                }
081:
082:                // open the reference file and tokenize
083:                File file = new File(filename);
084:                String refStr = null;
085:                if (file.exists()) {
086:                    try {
087:                        refStr = TestUtils.getString(new FileInputStream(file));
088:                    } catch (Exception e) {
089:                    }
090:                } else {
091:                    refStr = "";
092:                }
093:                Enumeration reference = new StringTokenizer(refStr, "\n");
094:
095:                // loop through reference strings looking for (un)expected strings
096:                // in the result
097:                boolean failed = false;
098:                StringBuffer failure = new StringBuffer();
099:                while (reference.hasMoreElements()) {
100:                    String next = (String) reference.nextElement();
101:                    next = next.trim();
102:                    boolean found = (result.indexOf(next.trim()) != -1);
103:                    if ((expected && !found) || (!expected && found)) {
104:                        if (failed) {
105:                            failure.append("\n");
106:                        } else {
107:                            failed = true;
108:                        }
109:                        failure.append(next);
110:                    }
111:                }
112:
113:                if (failed) {
114:                    fail(result, failure.toString(), expected);
115:                }
116:            }
117:
118:            private void fail(String result, String failure, boolean expected) {
119:                StringBuffer msg = new StringBuffer();
120:                msg.append("\n");
121:                msg.append("----- result:\n");
122:                msg.append(result);
123:                msg.append("\n");
124:                if (expected) {
125:                    msg.append("----- expected:\n");
126:                } else {
127:                    msg.append("----- unexpected:\n");
128:                }
129:                msg.append(failure);
130:
131:                test.fail(msg.toString());
132:            }
133:
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.