Source Code Cross Referenced for PatternSyntaxExceptionTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » tests » java » util » regex » 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 » Apache Harmony Java SE » org package » org.apache.harmony.tests.java.util.regex 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Licensed to the Apache Software Foundation (ASF) under one or more
002:         * contributor license agreements.  See the NOTICE file distributed with
003:         * this work for additional information regarding copyright ownership.
004:         * The ASF licenses this file to You under the Apache License, Version 2.0
005:         * (the "License"); you may not use this file except in compliance with
006:         * the License.  You may obtain a copy of the License at
007:         * 
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.apache.harmony.tests.java.util.regex;
018:
019:        import java.io.ObjectStreamClass;
020:        import java.io.Serializable;
021:        import java.util.regex.Pattern;
022:        import java.util.regex.PatternSyntaxException;
023:
024:        import junit.framework.TestCase;
025:
026:        import org.apache.harmony.testframework.serialization.SerializationTest;
027:        import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
028:
029:        /**
030:         * TODO Type description
031:         */
032:        @SuppressWarnings("nls")
033:        public class PatternSyntaxExceptionTest extends TestCase {
034:            public void testCase() {
035:                String regex = "(";
036:                try {
037:                    Pattern.compile(regex);
038:                    fail("PatternSyntaxException expected");
039:                } catch (PatternSyntaxException e) {
040:                    // TOFIX: Commented out assertEquals tests...
041:                    // TOFIX: should we match exception strings?
042:                    // assertEquals("Unclosed group", e.getDescription());
043:                    assertEquals(1, e.getIndex());
044:                    // assertEquals("Unclosed group near index 1\n(\n ^",
045:                    // e.getMessage());
046:                    assertEquals(regex, e.getPattern());
047:                }
048:            }
049:
050:            public void testCase2() {
051:                String regex = "[4-";
052:                try {
053:                    Pattern.compile(regex);
054:                    fail("PatternSyntaxException expected");
055:                } catch (PatternSyntaxException e) {
056:                    // TOFIX: Commented out assertEquals tests...
057:                    // TOFIX: should we match exception strings?
058:                    // assertEquals("Illegal character range", e.getDescription());
059:                    assertEquals(3, e.getIndex());
060:                    // assertEquals("Illegal character range near index 3\n[4-\n ^",
061:                    // e.getMessage());
062:                    assertEquals(regex, e.getPattern());
063:                }
064:            }
065:
066:            /**
067:             * @tests serialization/deserialization compatibility.
068:             */
069:            public void testSerializationSelf() throws Exception {
070:                PatternSyntaxException object = new PatternSyntaxException(
071:                        "TESTDESC", "TESTREGEX", 3);
072:                SerializationTest.verifySelf(object,
073:                        PATTERNSYNTAXEXCEPTION_COMPARATOR);
074:            }
075:
076:            /**
077:             * @tests serialization/deserialization compatibility with RI.
078:             */
079:            public void testSerializationCompatibility() throws Exception {
080:                PatternSyntaxException object = new PatternSyntaxException(
081:                        "TESTDESC", "TESTREGEX", 3);
082:                SerializationTest.verifyGolden(this , object,
083:                        PATTERNSYNTAXEXCEPTION_COMPARATOR);
084:            }
085:
086:            // Regression test for HARMONY-3787
087:            public void test_objectStreamField() {
088:                ObjectStreamClass objectStreamClass = ObjectStreamClass
089:                        .lookup(PatternSyntaxException.class);
090:                assertNotNull(objectStreamClass.getField("desc"));
091:            }
092:
093:            // comparator for BatchUpdateException field updateCounts
094:            private static final SerializableAssert PATTERNSYNTAXEXCEPTION_COMPARATOR = new SerializableAssert() {
095:                public void assertDeserialized(Serializable initial,
096:                        Serializable deserialized) {
097:
098:                    // do common checks for all throwable objects
099:                    SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(
100:                            initial, deserialized);
101:
102:                    PatternSyntaxException initPatternSyntaxException = (PatternSyntaxException) initial;
103:                    PatternSyntaxException dserPatternSyntaxException = (PatternSyntaxException) deserialized;
104:
105:                    // verify fields
106:                    assertEquals(initPatternSyntaxException.getDescription(),
107:                            dserPatternSyntaxException.getDescription());
108:                    assertEquals(initPatternSyntaxException.getPattern(),
109:                            dserPatternSyntaxException.getPattern());
110:                    assertEquals(initPatternSyntaxException.getIndex(),
111:                            dserPatternSyntaxException.getIndex());
112:                }
113:            };
114:        }
w_w__w__.j_a___v_a2___s__.__c_om__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.