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


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package org.apache.harmony.luni.tests.java.util;
019:
020:        import java.util.NoSuchElementException;
021:        import java.util.StringTokenizer;
022:
023:        public class StringTokenizerTest extends junit.framework.TestCase {
024:
025:            /**
026:             * @tests java.util.StringTokenizer#StringTokenizer(java.lang.String)
027:             */
028:            public void test_ConstructorLjava_lang_String() {
029:                // Test for method java.util.StringTokenizer(java.lang.String)
030:                assertTrue("Used in tests", true);
031:            }
032:
033:            /**
034:             * @tests java.util.StringTokenizer#StringTokenizer(java.lang.String,
035:             *        java.lang.String)
036:             */
037:            public void test_ConstructorLjava_lang_StringLjava_lang_String() {
038:                // Test for method java.util.StringTokenizer(java.lang.String,
039:                // java.lang.String)
040:                StringTokenizer st = new StringTokenizer(
041:                        "This:is:a:test:String", ":");
042:                assertTrue("Created incorrect tokenizer", st.countTokens() == 5
043:                        && (st.nextElement().equals("This")));
044:            }
045:
046:            /**
047:             * @tests java.util.StringTokenizer#StringTokenizer(java.lang.String,
048:             *        java.lang.String, boolean)
049:             */
050:            public void test_ConstructorLjava_lang_StringLjava_lang_StringZ() {
051:                // Test for method java.util.StringTokenizer(java.lang.String,
052:                // java.lang.String, boolean)
053:                StringTokenizer st = new StringTokenizer(
054:                        "This:is:a:test:String", ":", true);
055:                st.nextElement();
056:                assertTrue("Created incorrect tokenizer", st.countTokens() == 8
057:                        && (st.nextElement().equals(":")));
058:            }
059:
060:            /**
061:             * @tests java.util.StringTokenizer#countTokens()
062:             */
063:            public void test_countTokens() {
064:                // Test for method int java.util.StringTokenizer.countTokens()
065:                StringTokenizer st = new StringTokenizer(
066:                        "This is a test String");
067:
068:                assertEquals("Incorrect token count returned", 5, st
069:                        .countTokens());
070:            }
071:
072:            /**
073:             * @tests java.util.StringTokenizer#hasMoreElements()
074:             */
075:            public void test_hasMoreElements() {
076:                // Test for method boolean java.util.StringTokenizer.hasMoreElements()
077:
078:                StringTokenizer st = new StringTokenizer(
079:                        "This is a test String");
080:                st.nextElement();
081:                assertTrue("hasMoreElements returned incorrect value", st
082:                        .hasMoreElements());
083:                st.nextElement();
084:                st.nextElement();
085:                st.nextElement();
086:                st.nextElement();
087:                assertTrue("hasMoreElements returned incorrect value", !st
088:                        .hasMoreElements());
089:            }
090:
091:            /**
092:             * @tests java.util.StringTokenizer#hasMoreTokens()
093:             */
094:            public void test_hasMoreTokens() {
095:                // Test for method boolean java.util.StringTokenizer.hasMoreTokens()
096:                StringTokenizer st = new StringTokenizer(
097:                        "This is a test String");
098:                for (int counter = 0; counter < 5; counter++) {
099:                    assertTrue(
100:                            "StringTokenizer incorrectly reports it has no more tokens",
101:                            st.hasMoreTokens());
102:                    st.nextToken();
103:                }
104:                assertTrue(
105:                        "StringTokenizer incorrectly reports it has more tokens",
106:                        !st.hasMoreTokens());
107:            }
108:
109:            /**
110:             * @tests java.util.StringTokenizer#nextElement()
111:             */
112:            public void test_nextElement() {
113:                // Test for method java.lang.Object
114:                // java.util.StringTokenizer.nextElement()
115:                StringTokenizer st = new StringTokenizer(
116:                        "This is a test String");
117:                assertEquals("nextElement returned incorrect value", "This",
118:                        ((String) st.nextElement()));
119:                assertEquals("nextElement returned incorrect value", "is",
120:                        ((String) st.nextElement()));
121:                assertEquals("nextElement returned incorrect value", "a",
122:                        ((String) st.nextElement()));
123:                assertEquals("nextElement returned incorrect value", "test",
124:                        ((String) st.nextElement()));
125:                assertEquals("nextElement returned incorrect value", "String",
126:                        ((String) st.nextElement()));
127:                try {
128:                    st.nextElement();
129:                    fail("nextElement failed to throw a NoSuchElementException when it should have been out of elements");
130:                } catch (NoSuchElementException e) {
131:                    return;
132:                }
133:            }
134:
135:            /**
136:             * @tests java.util.StringTokenizer#nextToken()
137:             */
138:            public void test_nextToken() {
139:                // Test for method java.lang.String
140:                // java.util.StringTokenizer.nextToken()
141:                StringTokenizer st = new StringTokenizer(
142:                        "This is a test String");
143:                assertEquals("nextToken returned incorrect value", "This", st
144:                        .nextToken());
145:                assertEquals("nextToken returned incorrect value", "is", st
146:                        .nextToken());
147:                assertEquals("nextToken returned incorrect value", "a", st
148:                        .nextToken());
149:                assertEquals("nextToken returned incorrect value", "test", st
150:                        .nextToken());
151:                assertEquals("nextToken returned incorrect value", "String", st
152:                        .nextToken());
153:                try {
154:                    st.nextToken();
155:                    fail("nextToken failed to throw a NoSuchElementException when it should have been out of elements");
156:                } catch (NoSuchElementException e) {
157:                    return;
158:                }
159:            }
160:
161:            /**
162:             * @tests java.util.StringTokenizer#nextToken(java.lang.String)
163:             */
164:            public void test_nextTokenLjava_lang_String() {
165:                // Test for method java.lang.String
166:                // java.util.StringTokenizer.nextToken(java.lang.String)
167:                StringTokenizer st = new StringTokenizer(
168:                        "This is a test String");
169:                assertEquals(
170:                        "nextToken(String) returned incorrect value with normal token String",
171:                        "This", st.nextToken(" "));
172:                assertEquals(
173:                        "nextToken(String) returned incorrect value with custom token String",
174:                        " is a ", st.nextToken("tr"));
175:                assertEquals(
176:                        "calling nextToken() did not use the new default delimiter list",
177:                        "es", st.nextToken());
178:            }
179:
180:            /**
181:             * Sets up the fixture, for example, open a network connection. This method
182:             * is called before a test is executed.
183:             */
184:            protected void setUp() {
185:            }
186:
187:            /**
188:             * Tears down the fixture, for example, close a network connection. This
189:             * method is called after a test is executed.
190:             */
191:            protected void tearDown() {
192:            }
193:        }
ww___w.__j_a__v___a_2__s_._co_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.