Source Code Cross Referenced for SetOfIntegerSyntaxTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » print » attribute » 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 » javax package » javax.print.attribute 
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:         * @author Elena V. Sayapina 
019:         * @version $Revision: 1.3 $ 
020:         */package javax.print.attribute;
021:
022:        import javax.print.attribute.SetOfIntegerSyntax;
023:        import javax.print.attribute.standard.Copies;
024:        import javax.print.attribute.standard.NumberUpSupported;
025:        import javax.print.attribute.standard.PageRanges;
026:
027:        import junit.framework.TestCase;
028:
029:        public class SetOfIntegerSyntaxTest extends TestCase {
030:
031:            static {
032:                System.out.println("SetOfIntegerSyntax testing...");
033:            }
034:
035:            public static void main(String[] args) {
036:                junit.textui.TestRunner.run(SetOfIntegerSyntaxTest.class);
037:            }
038:
039:            SetOfIntegerSyntax set1, set2;
040:            int[][] arr1, arr2;
041:
042:            /*
043:             * setOfIntegerSyntax(String str) constructor testing. 
044:             */
045:            public final void testSetOfIntegerSyntax() {
046:                set1 = new setOfIntegerSyntax(
047:                        " 16-37, 100:30, 17-50, 1000-1848, 1-2, 2147");
048:                set1 = new setOfIntegerSyntax("0");
049:                set1 = new setOfIntegerSyntax(
050:                        "100       :       30,                  4");
051:                set1 = new setOfIntegerSyntax("000-1848");
052:                set1 = new setOfIntegerSyntax("");
053:
054:                try {
055:                    set1 = new setOfIntegerSyntax("17-50 1000-160");
056:                    fail("IllegalArgumentException wasn't trown when expected");
057:                } catch (IllegalArgumentException e) {
058:                }
059:
060:                try {
061:                    set1 = new setOfIntegerSyntax("-16:12");
062:                    fail("IllegalArgumentException wasn't trown when expected");
063:                } catch (IllegalArgumentException e) {
064:                }
065:
066:                try {
067:                    set1 = new setOfIntegerSyntax("a");
068:                    fail("IllegalArgumentException wasn't trown when expected");
069:                } catch (IllegalArgumentException e) {
070:                }
071:
072:                try {
073:                    //fails in "some" environment
074:                    set1 = new setOfIntegerSyntax("19836475376");
075:                    fail("IllegalArgumentException wasn't trown when expected");
076:                } catch (IllegalArgumentException e) {
077:                }
078:
079:                set1 = new setOfIntegerSyntax(
080:                        " 16-37, 100:30, 17:50, 1000-1848, 1-2, 214748364, 3");
081:                //System.out.println(set1.toString());
082:                arr1 = set1.getMembers();
083:                arr2 = new int[][] { { 1, 3 }, { 16, 50 }, { 1000, 1848 },
084:                        { 214748364, 214748364 } };
085:                if (arr1.length == arr2.length) {
086:                    for (int i = 0; i < arr1.length; i++) {
087:                        if ((arr1[i][0] != arr2[i][0])
088:                                || (arr1[i][1] != arr2[i][1])) {
089:                            fail("Wrong cannonical array");
090:                        }
091:                    }
092:                } else {
093:                    fail("Wrong cannonical array");
094:                }
095:
096:                set1 = new setOfIntegerSyntax(" ");
097:                arr1 = set1.getMembers();
098:                String str = null;
099:                set2 = new setOfIntegerSyntax(str);
100:                arr2 = set2.getMembers();
101:                if (arr1.length != arr2.length || arr1.length != 0) {
102:                    fail("IllegalArgumentException wasn't trown when expected");
103:                }
104:                set1 = new setOfIntegerSyntax("15-2");
105:                assertEquals(0, set1.getMembers().length);
106:
107:                try {
108:                    set1 = new setOfIntegerSyntax("1-2-3");
109:                    fail("IllegalArgumentException wasn't trown when expected");
110:                } catch (IllegalArgumentException e) {
111:                }
112:
113:            }
114:
115:            /*
116:             * setOfIntegerSyntax(int member) constructor testing. 
117:             */
118:            public final void testSetOfIntegerSyntax1() {
119:                try {
120:                    set1 = new setOfIntegerSyntax(-1);
121:                    fail("IllegalArgumentException wasn't trown when expected");
122:                } catch (IllegalArgumentException e) {
123:                }
124:
125:                try {
126:                    set1 = new setOfIntegerSyntax(0);
127:                    set2 = new setOfIntegerSyntax(1000);
128:                    assertEquals(0, set1.getMembers()[0][0]);
129:                    assertEquals(1000, set2.getMembers()[0][0]);
130:                } catch (IllegalArgumentException e) {
131:                    fail("Unexpected exception " + e);
132:                }
133:            }
134:
135:            /*
136:             * setOfIntegerSyntax(int[][] members) constructor testing. 
137:             * Tests that .
138:             */
139:            public final void testSetOfIntegerSyntax2() {
140:                try {
141:                    int[] arr = null;
142:                    arr1 = new int[][] { { 9 }, arr };
143:                    set1 = new setOfIntegerSyntax(arr1);
144:                    fail("NullPointerException wasn't trown when expected");
145:                } catch (NullPointerException e) {
146:                }
147:                try {
148:                    arr1 = new int[][] { { 9 }, { 4, 5, 6 } };
149:                    set1 = new setOfIntegerSyntax(arr1);
150:                    fail("IllegalArgumentException wasn't trown when expected");
151:                } catch (IllegalArgumentException e) {
152:                }
153:                try {
154:                    arr1 = new int[][] { { -9 }, { 4 } };
155:                    set1 = new setOfIntegerSyntax(arr1);
156:                    fail("IllegalArgumentException wasn't trown when expected");
157:                } catch (IllegalArgumentException e) {
158:                }
159:
160:                arr1 = new int[][] { { 1, 5 }, { 10 }, { 7, 7 }, { 5, 6 },
161:                        { 8, 9 }, { 15, 14 } };
162:                set1 = new setOfIntegerSyntax(arr1);
163:                //System.out.println(set1.toString());
164:                assertEquals(1, set1.getMembers()[0][0]);
165:                assertEquals(10, set1.getMembers()[0][1]);
166:
167:                arr1 = new int[][] { { 15, 14 } };
168:                set1 = new setOfIntegerSyntax(arr1);
169:                assertEquals(0, set1.getMembers().length);
170:
171:            }
172:
173:            /*
174:             * setOfIntegerSyntax(int lowerBound, int upperBound) constructor testing. 
175:             */
176:            public final void testSetOfIntegerSyntax3() {
177:                try {
178:                    set1 = new setOfIntegerSyntax(10, 10);
179:                    assertEquals(10, set1.getMembers()[0][0]);
180:                    assertEquals(10, set1.getMembers()[0][1]);
181:                    set2 = new setOfIntegerSyntax(10, 1);
182:                    assertEquals(0, set2.getMembers().length);
183:                } catch (IllegalArgumentException e) {
184:                    fail("Unexpected exception occurred " + e);
185:                }
186:                try {
187:                    arr1 = new int[][] { { -9 }, { 4 } };
188:                    set1 = new setOfIntegerSyntax(arr1);
189:                    fail("IllegalArgumentException wasn't trown when expected");
190:                } catch (IllegalArgumentException e) {
191:                }
192:            }
193:
194:            /*
195:             * setOfIntegerSyntax(String string) constructor testing. 
196:             */
197:            public final void testSetOfIntegerSyntax4() {
198:                String str = null;
199:                set1 = new setOfIntegerSyntax(str);
200:                assertTrue(0 == set1.getMembers().length);
201:            }
202:
203:            /*
204:             * contains(int x) method testing. 
205:             */
206:            public final void testContains() {
207:                set1 = new setOfIntegerSyntax("0:8");
208:                assertTrue(set1.contains(0));
209:                assertTrue(set1.contains(8));
210:                assertFalse(set1.contains(9));
211:                assertFalse(set1.contains(-1));
212:            }
213:
214:            /*
215:             * contains(IntegerSyntax attribute) method testing. 
216:             */
217:            public final void testContains1() {
218:                IntegerSyntax att1 = new Copies(10);
219:                IntegerSyntax att2 = new Copies(1);
220:                set1 = new setOfIntegerSyntax("10, 5-8");
221:                assertTrue(set1.contains(att1));
222:                assertFalse(set1.contains(att2));
223:            }
224:
225:            /*
226:             * equals(Object object) method testing. 
227:             */
228:            public final void testEquals() {
229:                arr1 = new int[][] { { 0, 1 }, { 5 } };
230:                set1 = new setOfIntegerSyntax(arr1);
231:                set2 = new setOfIntegerSyntax("0, 1, 5");
232:                assertTrue(set1.equals(set2));
233:
234:                set1 = new PageRanges("2, 3-2");
235:                set2 = new PageRanges(2);
236:                assertTrue(set1.equals(set2));
237:
238:                set1 = new NumberUpSupported(2, 10);
239:                set2 = new NumberUpSupported(2);
240:                assertFalse(set1.equals(set2));
241:
242:                set1 = new setOfIntegerSyntax("100-1000");
243:                set2 = null;
244:                assertFalse(set1.equals(set2));
245:            }
246:
247:            /*
248:             * getMembers() method testing. 
249:             */
250:            public final void testGetMembers() {
251:                set1 = new setOfIntegerSyntax("10, 5-8");
252:                arr1 = set1.getMembers();
253:                assertEquals(5, arr1[0][0]);
254:                assertEquals(8, arr1[0][1]);
255:                assertEquals(10, arr1[1][0]);
256:                assertEquals(10, arr1[1][1]);
257:            }
258:
259:            /*
260:             * hashCode() method testing. 
261:             * Tests that hash code is the sum of the lower and upper bounds of 
262:             * the ranges in the canonical array form, or 0 for an empty set.
263:             */
264:            public final void testHashCode() {
265:                set1 = new setOfIntegerSyntax("0, 1, 5, 10-15");
266:                assertEquals(36, set1.hashCode());
267:                set1 = new setOfIntegerSyntax(" ");
268:                assertEquals(0, set1.hashCode());
269:                set1 = new setOfIntegerSyntax("5");
270:                assertEquals(10, set1.hashCode());
271:            }
272:
273:            /*
274:             * next() method testing.
275:             */
276:            public final void testNext() {
277:                set1 = new setOfIntegerSyntax(" 5-8, 10, 25, 100-130, 250");
278:                assertEquals(10, set1.next(8));
279:                assertEquals(5, set1.next(1));
280:                assertEquals(-1, set1.next(250));
281:            }
282:
283:            /*
284:             * Auxiliary class
285:             */
286:            public class setOfIntegerSyntax extends SetOfIntegerSyntax {
287:
288:                public setOfIntegerSyntax(int lowerBound, int upperBound) {
289:                    super (lowerBound, upperBound);
290:                }
291:
292:                public setOfIntegerSyntax(String str) {
293:                    super (str);
294:                }
295:
296:                public setOfIntegerSyntax(int i) {
297:                    super (i);
298:                }
299:
300:                public setOfIntegerSyntax(int[][] arr) {
301:                    super(arr);
302:                }
303:            }
304:
305:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.