Source Code Cross Referenced for ExtendedTestCase.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » content » 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 » 6.0 JDK Modules » j2me » com.sun.midp.content 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package com.sun.midp.content;
028:
029:        import com.sun.midp.i3test.TestCase;
030:        import com.sun.midp.security.SecurityToken;
031:        import com.sun.midp.midlet.MIDletStateHandler;
032:        import com.sun.midp.midlet.MIDletSuite;
033:
034:        /**
035:         * Extension to the basic TestCase class to add ContentHandler
036:         * specific assert methods.
037:         */
038:        public abstract class ExtendedTestCase extends TestCase {
039:
040:            /** Classname of the MIDlet. */
041:            String classname = "com.sun.midp.i3test.Framework";
042:
043:            /**
044:             * Initialize the registry for this application.
045:             * @return the registry for the Framework class
046:             */
047:            RegistryImpl getRegistry() {
048:                try {
049:                    SecurityToken token = getSecurityToken();
050:                    MIDletStateHandler mstate = MIDletStateHandler
051:                            .getMidletStateHandler();
052:                    MIDletSuite msuite = mstate.getMIDletSuite();
053:                    msuite.setTempProperty(token, "MIDlet-1", "CHAPI Tests,,"
054:                            + classname);
055:
056:                    return RegistryImpl.getRegistryImpl(classname, token);
057:                } catch (SecurityException sx) {
058:                    fail("SecurityException: can't setTempProperty");
059:                } catch (Throwable t) {
060:                    assertNull("i3test can't get registry for class "
061:                            + classname, t);
062:                    t.printStackTrace();
063:                }
064:                return null;
065:            }
066:
067:            /**
068:             * Override assertEquals to allow null pointers.
069:             * @param message message
070:             * @param expected the expected object
071:             * @param actual the actual object.
072:             */
073:            public void assertEquals(String message, Object expected,
074:                    Object actual) {
075:                if (expected == actual) {
076:                    // The identity and the null == null
077:                    return;
078:                }
079:                if (expected != null) {
080:                    assertTrue(message, expected.equals(actual));
081:                } else {
082:                    assertTrue(message, actual.equals(expected));
083:                }
084:            }
085:
086:            /**
087:             * Assert that all of the fields of the two InvocationImpls match
088:             * exactly.
089:             * @param msg the message to print for assert failures
090:             * @param expected the InvocationImpl containing the expected values
091:             * @param actual the InvocationImpl containing the actual values
092:             */
093:            public void assertEquals(String msg, InvocationImpl expected,
094:                    InvocationImpl actual) {
095:                if (expected == actual) {
096:                    return;
097:                }
098:                assertNotNull(msg + " expected: ", actual);
099:                if (actual == null) {
100:                    return;
101:                }
102:
103:                assertEquals("verify getID", expected.getID(), actual.getID());
104:                assertEquals("verify getType", expected.getType(), actual
105:                        .getType());
106:                assertEquals("verify getURL", expected.getURL(), actual
107:                        .getURL());
108:                assertTrue("verify responseRequired", expected
109:                        .getResponseRequired() == actual.getResponseRequired());
110:                assertEquals("verify action", expected.getAction(), actual
111:                        .getAction());
112:                assertEquals("verify classname", expected.classname,
113:                        actual.classname);
114:                assertEquals("verify invokingSuiteId",
115:                        expected.invokingSuiteId, actual.invokingSuiteId);
116:                assertEquals("verify invokingClassname",
117:                        expected.invokingClassname, actual.invokingClassname);
118:                assertEquals("verify tid", expected.tid, actual.tid);
119:                assertEquals("verify invokingAuthority",
120:                        expected.invokingAuthority, actual.invokingAuthority);
121:                assertEquals("verify invokingID", expected.invokingID,
122:                        actual.invokingID);
123:                assertEquals("verify previousTid", expected.previousTid,
124:                        actual.previousTid);
125:                assertEquals("verify arguments", expected.getArgs(), actual
126:                        .getArgs());
127:                String[] args = expected.getArgs();
128:                int argsLen = args != null ? args.length : 0;
129:                assertEquals("verify argsLen", argsLen, actual.argsLen);
130:                assertEquals("verify data", expected.data, actual.data);
131:            }
132:
133:            /**
134:             * Compare two arrays of strings, must be the same length
135:             * and contents to match.
136:             * @param msg the message to print for assert failures
137:             * @param s1 an array of strings
138:             * @param s2 another array of strings
139:             */
140:            public void assertEquals(String msg, String[] s1, String[] s2) {
141:                // Identical arrays are equals
142:                if (s1 == s2) {
143:                    return;
144:                }
145:                // If either array is null then they don't match
146:                if (s1 == null) {
147:                    fail("mismatched arg arrays; expected is null");
148:                    return;
149:                }
150:                if (s2 == null) {
151:                    fail("mismatched arg arrays; actual is null");
152:                    return;
153:                }
154:                // If the lengths are unequal then they are not equal
155:                assertEquals("mismatched arg lengths", s1.length, s2.length);
156:
157:                if (s1.length == s2.length) {
158:                    // Compare the strings in each array
159:                    for (int i = 0; i < s1.length; i++) {
160:                        // Two strings, non-null of the same length
161:                        assertEquals("arg " + i, s1[i], s2[i]);
162:                    }
163:                }
164:            }
165:
166:            /**
167:             * Compare two byte arrays; must be same length.
168:             * @param msg the description of the array
169:             * @param expected the expected data array
170:             * @param actual the actual data array
171:             */
172:            public void assertEquals(String msg, byte[] expected, byte[] actual) {
173:                if (expected == actual) {
174:                    return;
175:                }
176:                if (expected == null) {
177:                    fail("expected string array is null");
178:                    return;
179:                }
180:                if (actual == null) {
181:                    fail("actual string array is null");
182:                    return;
183:                }
184:                assertEquals(msg + " length", expected.length, actual.length);
185:                int badbytes = 0;
186:                if (expected.length == actual.length) {
187:                    for (int i = 0; i < expected.length; i++) {
188:                        if (expected[i] != actual[i]) {
189:                            if (0 == badbytes++) {
190:                                fail(msg + " data does not match");
191:                            }
192:                            assertEquals("  " + i + ": ", expected[i],
193:                                    actual[i]);
194:                        }
195:                    }
196:                }
197:            }
198:
199:            /**
200:             * Sleep a bit.
201:             * @param millis millseconds to sleep
202:             */
203:            public static void sleep(long millis) {
204:                try {
205:                    Thread.sleep(millis);
206:                } catch (InterruptedException ie) {
207:                }
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.