Source Code Cross Referenced for StringToNumberParserTestHarness.java in  » IDE-Eclipse » jface » org » eclipse » core » tests » internal » databinding » conversion » 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 » IDE Eclipse » jface » org.eclipse.core.tests.internal.databinding.conversion 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         ******************************************************************************/package org.eclipse.core.tests.internal.databinding.conversion;
011:
012:        import java.math.BigDecimal;
013:        import java.math.BigInteger;
014:
015:        import org.eclipse.core.internal.databinding.conversion.StringToNumberParser;
016:
017:        import junit.framework.TestCase;
018:
019:        /**
020:         * @since 1.1
021:         */
022:        public abstract class StringToNumberParserTestHarness extends TestCase {
023:
024:            protected abstract Number getValidMax();
025:
026:            protected abstract Number getValidMin();
027:
028:            protected abstract boolean assertValid(Number number);
029:
030:            public void testRanges() throws Exception {
031:                Number min = getValidMin();
032:                Number max = getValidMax();
033:
034:                double minDouble = min.doubleValue();
035:                double maxDouble = max.doubleValue();
036:
037:                //test bytes
038:                assertTrue("valid byte", assertValid(new Byte((byte) 1)));
039:                assertTrue("valid byte min", assertValid(new Byte(
040:                        Byte.MIN_VALUE)));
041:                assertTrue("valid byte max", assertValid(new Byte(
042:                        Byte.MAX_VALUE)));
043:
044:                // test shorts
045:                assertTrue("valid short", assertValid(new Short((short) 1)));
046:                boolean result = assertValid(new Short(Short.MIN_VALUE));
047:                if (minDouble > Short.MIN_VALUE) {
048:                    assertFalse("invalid short min", result);
049:                } else {
050:                    assertTrue("valid short min", result);
051:                }
052:
053:                result = assertValid(new Short(Short.MAX_VALUE));
054:                if (maxDouble < Short.MAX_VALUE) {
055:                    assertFalse("invalid short max", result);
056:                } else {
057:                    assertTrue("valid short max", result);
058:                }
059:
060:                // test integers
061:                assertTrue("valid Integer", assertValid(new Integer(1)));
062:
063:                result = assertValid(new Integer(Integer.MIN_VALUE));
064:                if (minDouble > Integer.MIN_VALUE) {
065:                    assertFalse("invalid Integer min", result);
066:                } else {
067:                    assertTrue("valid integer min", result);
068:                }
069:
070:                result = assertValid(new Integer(Integer.MAX_VALUE));
071:                if (maxDouble < Integer.MAX_VALUE) {
072:                    assertFalse("valid Integer max", result);
073:                } else {
074:                    assertTrue("valid integer max", result);
075:                }
076:
077:                // test longs
078:                assertTrue("valid long", assertValid(new Long(1)));
079:                result = assertValid(new Long(Long.MIN_VALUE));
080:                if (minDouble > Long.MIN_VALUE) {
081:                    assertFalse("invalid long min", result);
082:                } else {
083:                    assertTrue("valid long min", result);
084:                }
085:
086:                result = assertValid(new Long(Long.MAX_VALUE));
087:                if (maxDouble < Long.MAX_VALUE) {
088:                    assertFalse("invalid long max", result);
089:                } else {
090:                    assertTrue("valid long max", result);
091:                }
092:
093:                // test floats
094:                assertTrue("valid float", assertValid(new Float(1)));
095:                result = assertValid(new Float(-Float.MAX_VALUE));
096:                if (minDouble > -Float.MAX_VALUE) {
097:                    assertFalse("invalid float min", result);
098:                } else {
099:                    assertTrue("valid float min", result);
100:                }
101:
102:                result = assertValid(new Float(Float.MAX_VALUE));
103:                if (maxDouble < Float.MAX_VALUE) {
104:                    assertFalse("invalid float max", result);
105:                } else {
106:                    assertTrue("valid float max", result);
107:                }
108:
109:                assertFalse("invalid negative float infinity",
110:                        assertValid(new Float(Float.NEGATIVE_INFINITY)));
111:                assertFalse("invalid positive float infinity",
112:                        assertValid(new Float(Float.POSITIVE_INFINITY)));
113:                assertFalse("invalid float NaN", assertValid(new Float(
114:                        Float.NaN)));
115:
116:                // test doubles
117:                assertTrue("valid double", assertValid(new Double(1)));
118:                result = assertValid(new Double(-Double.MAX_VALUE));
119:                if (minDouble > -Double.MAX_VALUE) {
120:                    assertFalse("invalid double min", result);
121:                } else {
122:                    assertTrue("valid double min", result);
123:                }
124:
125:                result = assertValid(new Double(Double.MAX_VALUE));
126:                if (maxDouble < Double.MAX_VALUE) {
127:                    assertFalse("invalid float max", result);
128:                } else {
129:                    assertTrue("valid float max", result);
130:                }
131:
132:                assertFalse("invalid negative double infinity",
133:                        assertValid(new Double(Double.NEGATIVE_INFINITY)));
134:                assertFalse("invalid positive double infinity",
135:                        assertValid(new Double(Double.POSITIVE_INFINITY)));
136:                assertFalse("invalid double NaN", assertValid(new Double(
137:                        Double.NaN)));
138:
139:                // test BigIntegers
140:                assertTrue("valid BigInteger", assertValid(BigInteger
141:                        .valueOf(1)));
142:                BigDecimal bigDecimalMin = new BigDecimal(min.doubleValue());
143:                bigDecimalMin = bigDecimalMin.subtract(new BigDecimal(1));
144:                assertFalse("invalid BigInteger min", assertValid(bigDecimalMin
145:                        .toBigInteger()));
146:
147:                BigDecimal bigDecimalMax = new BigDecimal(max.doubleValue());
148:                bigDecimalMax = bigDecimalMax.add(new BigDecimal(1));
149:                assertFalse("invalid BigInteger max", assertValid(bigDecimalMax
150:                        .toBigInteger()));
151:
152:                // test BigDecimals
153:                assertTrue("valid BigDecimal", assertValid(new BigDecimal(1)));
154:                assertFalse("invalid BigDecimal min",
155:                        assertValid(bigDecimalMin));
156:                assertFalse("invalid BigDecimal max",
157:                        assertValid(bigDecimalMax));
158:
159:                /**
160:                 * The ICU4J plugin's NumberFormat will return it's own BigDecimal
161:                 * implementation, com.ibm.icu.math.BigDecimal. The issue this causes is
162:                 * that we can't reference this class as it's not part of the
163:                 * replacement plugin. So in order to ensure that we handle Number's
164:                 * that are not part of the JDK stub a number implemenation and ensure
165:                 * that the double representation of this number is used.
166:                 * 
167:                 * @throws Exception
168:                 */
169:                class MyNumber extends Number {
170:                    double value;
171:                    int count;
172:
173:                    MyNumber(double value) {
174:                        this .value = value;
175:                    }
176:
177:                    private static final long serialVersionUID = 1L;
178:
179:                    /*
180:                     * (non-Javadoc)
181:                     * 
182:                     * @see java.lang.Number#doubleValue()
183:                     */
184:                    public double doubleValue() {
185:                        count++;
186:                        return value;
187:                    }
188:
189:                    /*
190:                     * (non-Javadoc)
191:                     * 
192:                     * @see java.lang.Number#floatValue()
193:                     */
194:                    public float floatValue() {
195:                        return 0;
196:                    }
197:
198:                    /*
199:                     * (non-Javadoc)
200:                     * 
201:                     * @see java.lang.Number#intValue()
202:                     */
203:                    public int intValue() {
204:                        return 0;
205:                    }
206:
207:                    /*
208:                     * (non-Javadoc)
209:                     * 
210:                     * @see java.lang.Number#longValue()
211:                     */
212:                    public long longValue() {
213:                        return 0;
214:                    }
215:                }
216:
217:                MyNumber number = new MyNumber(1);
218:                assertEquals(0, number.count);
219:                assertTrue(StringToNumberParser.inIntegerRange(number));
220:                assertTrue("double value retrieved", number.count > 0);
221:            }
222:        }
www__.___j___a__v_a__2__s_.c__om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.