Source Code Cross Referenced for ReflectionComparatorPrimitivesTest.java in  » Testing » unitils » org » unitils » reflectionassert » 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 » Testing » unitils » org.unitils.reflectionassert 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007,  Unitils.org
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * 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:        package org.unitils.reflectionassert;
017:
018:        import junit.framework.TestCase;
019:        import org.unitils.reflectionassert.ReflectionComparator.Difference;
020:
021:        /**
022:         * Test class for {@link ReflectionComparator}. Contains tests with primitive types.
023:         * 
024:         * @author Tim Ducheyne
025:         * @author Filip Neven
026:         */
027:        public class ReflectionComparatorPrimitivesTest extends TestCase {
028:
029:            /* Test object */
030:            private Primitives primitivesA;
031:
032:            /* Same as A but different instance */
033:            private Primitives primitivesB;
034:
035:            /* Same as A and B but different int value for intValue2 */
036:            private Primitives primitiveDifferentValue;
037:
038:            /* Same as A and B but with 0 value for intValue2 */
039:            private Primitives primitives0Value;
040:
041:            /* Test object with inner object */
042:            private Primitives primitivesInnerA;
043:
044:            /* Same as innerA but different instance */
045:            private Primitives primitivesInnerB;
046:
047:            /* Same as innerA and innerB but different int value for inner intValue2 */
048:            private Primitives primitivesInnerDifferentValue;
049:
050:            /* Class under test */
051:            private ReflectionComparator reflectionComparator;
052:
053:            /**
054:             * Initializes the test fixture.
055:             */
056:            protected void setUp() throws Exception {
057:                super .setUp();
058:
059:                primitivesA = new Primitives(1, 2, null);
060:                primitivesB = new Primitives(1, 2, null);
061:                primitiveDifferentValue = new Primitives(1, 9999, null);
062:                primitives0Value = new Primitives(1, 0, null);
063:
064:                primitivesInnerA = new Primitives(0, 0, primitivesA);
065:                primitivesInnerB = new Primitives(0, 0, primitivesB);
066:                primitivesInnerDifferentValue = new Primitives(0, 0,
067:                        primitiveDifferentValue);
068:
069:                reflectionComparator = ReflectionComparatorChainFactory.STRICT_COMPARATOR;
070:            }
071:
072:            /**
073:             * Test for two equal primitives.
074:             */
075:            public void testGetDifference_equals() {
076:                Difference result = reflectionComparator.getDifference(
077:                        primitivesA, primitivesB);
078:                assertNull(result);
079:            }
080:
081:            /**
082:             * Test for two equal autoboxing. An autoboxed primitive should be considered equals to the object version.
083:             */
084:            public void testGetDifference_equalsAutoboxing() {
085:                Difference result = reflectionComparator.getDifference(5L,
086:                        new Long(5));
087:                assertNull(result);
088:            }
089:
090:            /**
091:             * Test for two equal primitives as an inner field of an object.
092:             */
093:            public void testGetDifference_equalsInner() {
094:                Difference result = reflectionComparator.getDifference(
095:                        primitivesInnerA, primitivesInnerB);
096:                assertNull(result);
097:            }
098:
099:            /**
100:             * Test for two equal primitives but of different type (int vs long).
101:             */
102:            public void testGetDifference_differentTypes() {
103:                Difference result = reflectionComparator.getDifference(5L, 5);
104:                assertNull(result);
105:            }
106:
107:            /**
108:             * Test for two primitives that contain different values.
109:             */
110:            public void testGetDifference_notEqualsDifferentValues() {
111:                Difference result = reflectionComparator.getDifference(
112:                        primitivesA, primitiveDifferentValue);
113:
114:                assertNotNull(result);
115:                assertEquals("intValue2", result.getFieldStack().get(0));
116:                assertEquals(2, result.getLeftValue());
117:                assertEquals(9999, result.getRightValue());
118:            }
119:
120:            /**
121:             * Test for two primitives with right value 0.
122:             */
123:            public void testGetDifference_notEqualsRight0() {
124:                Difference result = reflectionComparator.getDifference(
125:                        primitivesA, primitives0Value);
126:
127:                assertNotNull(result);
128:                assertEquals("intValue2", result.getFieldStack().get(0));
129:                assertEquals(2, result.getLeftValue());
130:                assertEquals(0, result.getRightValue());
131:            }
132:
133:            /**
134:             * Test for two primitives with left value 0.
135:             */
136:            public void testGetDifference_notEqualsLeft0() {
137:                Difference result = reflectionComparator.getDifference(
138:                        primitives0Value, primitivesA);
139:
140:                assertNotNull(result);
141:                assertEquals("intValue2", result.getFieldStack().get(0));
142:                assertEquals(0, result.getLeftValue());
143:                assertEquals(2, result.getRightValue());
144:            }
145:
146:            /**
147:             * Test for objects with inner primitives that contain different values.
148:             */
149:            public void testGetDifference_notEqualsInnerDifferentValues() {
150:                Difference result = reflectionComparator.getDifference(
151:                        primitivesInnerA, primitivesInnerDifferentValue);
152:
153:                assertNotNull(result);
154:                assertEquals("inner", result.getFieldStack().get(0));
155:                assertEquals("intValue2", result.getFieldStack().get(1));
156:                assertEquals(2, result.getLeftValue());
157:                assertEquals(9999, result.getRightValue());
158:            }
159:
160:            /**
161:             * Tests for equality of two NaN values
162:             */
163:            public void testNaN() {
164:                Difference result = reflectionComparator.getDifference(
165:                        Double.NaN, Float.NaN);
166:                assertNull(result);
167:            }
168:
169:            /**
170:             * Tests for equality of a NaN with a 0 value
171:             */
172:            public void testNaN_notEqual() {
173:                Difference result = reflectionComparator.getDifference(
174:                        Double.NaN, 0);
175:                assertTrue(result.getFieldStack().isEmpty());
176:                assertEquals(Double.NaN, result.getLeftValue());
177:                assertEquals(0, result.getRightValue());
178:            }
179:
180:            /**
181:             * Tests for equality of two NEGATIVE_INFINITY values
182:             */
183:            public void testInfinity() {
184:                Difference result = reflectionComparator.getDifference(
185:                        Double.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
186:                assertNull(result);
187:            }
188:
189:            /**
190:             * Tests for equality of a NEGATIVE_INFINITY with a POSITIVE_INFINITY value
191:             */
192:            public void testInfinity_notEqual() {
193:                Difference result = reflectionComparator.getDifference(
194:                        Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
195:                assertTrue(result.getFieldStack().isEmpty());
196:                assertEquals(Double.NEGATIVE_INFINITY, result.getLeftValue());
197:                assertEquals(Double.POSITIVE_INFINITY, result.getRightValue());
198:            }
199:
200:            /**
201:             * Test class with failing equals.
202:             */
203:            @SuppressWarnings("unused")
204:            private static class Primitives {
205:
206:                /* A fist int value */
207:                private int intValue1;
208:
209:                /* A second int value */
210:                private int intValue2;
211:
212:                /* An inner object */
213:                private Primitives inner;
214:
215:                /**
216:                 * Creates and initializes the element.
217:                 * 
218:                 * @param intValue1 the first int value
219:                 * @param intValue2 the second int value
220:                 * @param inner the inner collection
221:                 */
222:                public Primitives(int intValue1, int intValue2, Primitives inner) {
223:                    this .intValue1 = intValue1;
224:                    this .intValue2 = intValue2;
225:                    this .inner = inner;
226:                }
227:
228:                /**
229:                 * Always returns false
230:                 * 
231:                 * @param o the object to compare to
232:                 */
233:                @Override
234:                public boolean equals(Object o) {
235:                    return false;
236:                }
237:            }
238:
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.