Source Code Cross Referenced for NumberRangeTest.java in  » Library » Apache-common-lang » org » apache » commons » lang » 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 » Library » Apache common lang » org.apache.commons.lang 
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:        package org.apache.commons.lang;
018:
019:        import junit.framework.Test;
020:        import junit.framework.TestCase;
021:        import junit.framework.TestSuite;
022:
023:        /**
024:         * Test cases for the {@link NumberRange} class.
025:         *
026:         * @author <a href="mailto:chrise@esha.com">Christopher Elkins</a>
027:         * @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
028:         * @author Tim O'Brien
029:         * @version $Revision: 437554 $ $Date: 2006-08-27 23:21:41 -0700 (Sun, 27 Aug 2006) $
030:         */
031:
032:        public final class NumberRangeTest extends TestCase {
033:
034:            private NumberRange tenToTwenty;
035:            private NumberRange fifteenToTwentyFive;
036:            private NumberRange fiveToNine;
037:            private Number five;
038:            private Number nine;
039:            private Number ten;
040:            private Number fifteen;
041:            private Number twenty;
042:            private Number twentyFive;
043:
044:            public NumberRangeTest(String name) {
045:                super (name);
046:            }
047:
048:            public void setUp() {
049:                five = new Integer(5);
050:                nine = new Double(9.0);
051:                ten = new Integer(10);
052:                fifteen = new Integer(15);
053:                twenty = new Integer(20);
054:                twentyFive = new Integer(25);
055:
056:                tenToTwenty = new NumberRange(ten, twenty);
057:                fifteenToTwentyFive = new NumberRange(fifteen, twentyFive);
058:                fiveToNine = new NumberRange(five, nine);
059:            }
060:
061:            public static Test suite() {
062:                TestSuite suite = new TestSuite(NumberRangeTest.class);
063:                suite.setName("NumberRange Tests");
064:                return suite;
065:            }
066:
067:            public void testMaxMin() {
068:                boolean expected = true;
069:                boolean result = tenToTwenty.getMaximum().equals(twenty);
070:                assertEquals(expected, result);
071:
072:                expected = true;
073:                result = tenToTwenty.getMinimum().equals(ten);
074:                assertEquals(expected, result);
075:            }
076:
077:            public void testEquals() {
078:                boolean expected = false;
079:                boolean result = tenToTwenty.equals(new NumberRange(five, ten));
080:                assertEquals(expected, result);
081:
082:                expected = true;
083:                result = tenToTwenty.equals(new NumberRange(ten, twenty));
084:                assertEquals(expected, result);
085:
086:                expected = false;
087:                result = tenToTwenty.equals(new NumberRange(ten, fifteen));
088:                assertEquals(expected, result);
089:
090:                expected = false;
091:                result = tenToTwenty.equals(new NumberRange(fifteen, twenty));
092:                assertEquals(expected, result);
093:            }
094:
095:            public void testEqualsWithOtherObject() {
096:                assertEquals("A NumberRange should not equals a String object",
097:                        false, fiveToNine.equals("TEST"));
098:            }
099:
100:            public void testEqualsWithSameReference() {
101:                assertEquals("A NumberRange should equal itself", true,
102:                        fiveToNine.equals(fiveToNine));
103:            }
104:
105:            public void testEqualsNull() {
106:                assertEquals("A NumberRange should not equal null", false,
107:                        fiveToNine.equals(null));
108:            }
109:
110:            public void testHashCode() {
111:                NumberRange nr = new NumberRange(new Integer(5),
112:                        new Double(9.0));
113:                assertEquals(
114:                        "The hashCode of 5-9 should equals the hashcode of another NumberRange of the same min/max",
115:                        fiveToNine.hashCode(), nr.hashCode());
116:                assertTrue(
117:                        "The hashCode of 10-20 should not equal the hashCode of 5-9",
118:                        fiveToNine.hashCode() != tenToTwenty.hashCode());
119:            }
120:
121:            public void testIncludesNumber() {
122:                boolean expected = false;
123:                boolean result = tenToTwenty.includesNumber(five);
124:                assertEquals(expected, result);
125:
126:                expected = true;
127:                result = tenToTwenty.includesNumber(ten);
128:                assertEquals(expected, result);
129:
130:                expected = true;
131:                result = tenToTwenty.includesNumber(fifteen);
132:                assertEquals(expected, result);
133:
134:                expected = true;
135:                result = tenToTwenty.includesNumber(twenty);
136:                assertEquals(expected, result);
137:
138:                expected = false;
139:                result = tenToTwenty.includesNumber(twentyFive);
140:                assertEquals(expected, result);
141:            }
142:
143:            public void testIncludesNumberNull() {
144:                boolean result = tenToTwenty.includesNumber(null);
145:                assertEquals(
146:                        "Includes number should return false for null values",
147:                        false, result);
148:            }
149:
150:            public void testIncludesRange() {
151:                boolean expected = false;
152:                boolean result = tenToTwenty.includesRange(new NumberRange(
153:                        five, ten));
154:                assertEquals(expected, result);
155:
156:                expected = false;
157:                result = tenToTwenty.includesRange(new NumberRange(five,
158:                        fifteen));
159:                assertEquals(expected, result);
160:
161:                expected = true;
162:                result = tenToTwenty
163:                        .includesRange(new NumberRange(ten, fifteen));
164:                assertEquals(expected, result);
165:
166:                expected = true;
167:                result = tenToTwenty
168:                        .includesRange(new NumberRange(ten, twenty));
169:                assertEquals(expected, result);
170:
171:                expected = true;
172:                result = tenToTwenty.includesRange(new NumberRange(fifteen,
173:                        twenty));
174:                assertEquals(expected, result);
175:
176:                expected = false;
177:                result = tenToTwenty.includesRange(new NumberRange(fifteen,
178:                        twentyFive));
179:                assertEquals(expected, result);
180:
181:                expected = false;
182:                result = tenToTwenty.includesRange(new NumberRange(twenty,
183:                        twentyFive));
184:                assertEquals(expected, result);
185:            }
186:
187:            public void testIncludesRangeNull() {
188:                boolean result = tenToTwenty.includesRange(null);
189:                assertEquals(
190:                        "Includes range should return false for null values",
191:                        false, result);
192:            }
193:
194:            public void testConstructor() {
195:                NumberRange nr = new NumberRange(new Double(2.0));
196:                assertEquals("Unexpected min on NumberRange", 2.0, nr
197:                        .getMinimum().doubleValue(), Double.MIN_VALUE);
198:                assertEquals("Unexpected max on NumberRange", 2.0, nr
199:                        .getMaximum().doubleValue(), Double.MIN_VALUE);
200:            }
201:
202:            public void testConstructorNullParameters() {
203:                try {
204:                    NumberRange nr = new NumberRange(null);
205:                    fail("NumberRange(null) did not throw an exception.");
206:                } catch (Exception e) {
207:                    assertTrue("NumberRange(null)",
208:                            e instanceof  NullPointerException);
209:                }
210:
211:                try {
212:                    NumberRange nr = new NumberRange(five, null);
213:                    fail("NumberRange(five, null) did not throw an exception.");
214:                } catch (Exception e) {
215:                    assertTrue("NumberRange(five, null)",
216:                            e instanceof  NullPointerException);
217:                }
218:
219:                try {
220:                    NumberRange nr = new NumberRange(null, five);
221:                    fail("NumberRange(null, five) did not throw an exception.");
222:                } catch (Exception e) {
223:                    assertTrue("NumberRange(null, five)",
224:                            e instanceof  NullPointerException);
225:                }
226:            }
227:
228:            public void testConstructorWithMaxLessThanMin() {
229:                NumberRange nr = new NumberRange(new Double(2.0), new Double(
230:                        1.0));
231:                assertEquals("Unexpected min on NumberRange", 2.0, nr
232:                        .getMinimum().doubleValue(), Double.MIN_VALUE);
233:                assertEquals("Unexpected max on NumberRange", 2.0, nr
234:                        .getMaximum().doubleValue(), Double.MIN_VALUE);
235:            }
236:
237:            public void testOverlap() {
238:                assertEquals("5-9 should not overlap 10-20", false, fiveToNine
239:                        .overlaps(tenToTwenty));
240:                assertEquals("10-20 should overlap 15-25", true, tenToTwenty
241:                        .overlaps(fifteenToTwentyFive));
242:            }
243:
244:            public void testOverlapNull() {
245:                assertEquals("5-9 should not overlap null", false, fiveToNine
246:                        .overlaps(null));
247:            }
248:
249:            public void testToString() {
250:                String expected = "10-20";
251:                String result = tenToTwenty.toString();
252:                assertEquals(expected, result);
253:            }
254:
255:            public void testToStringWithNegatives() {
256:                String expected = "(-20)-(-10)";
257:                NumberRange nr = new NumberRange(new Integer(-20), new Integer(
258:                        -10));
259:                String result = nr.toString();
260:                assertEquals(expected, result);
261:
262:                expected = "(-20)-10";
263:                nr = new NumberRange(new Integer(-20), new Integer(10));
264:                result = nr.toString();
265:                assertEquals(expected, result);
266:            }
267:
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.