Source Code Cross Referenced for ReflectionComparatorPrimitivesArrayTest.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 org.unitils.reflectionassert.ReflectionComparator.Difference;
019:
020:        import junit.framework.TestCase;
021:
022:        /**
023:         * Test class for {@link ReflectionComparator}.
024:         * Contains tests with primitive array types.
025:         *
026:         * @author Tim Ducheyne
027:         * @author Filip Neven
028:         */
029:        public class ReflectionComparatorPrimitivesArrayTest extends TestCase {
030:
031:            /* Test array */
032:            private int[] arrayA;
033:
034:            /* Same as A but different instance */
035:            private int[] arrayB;
036:
037:            /* Same as A but different order of values*/
038:            private int[] arrayDifferentOrder;
039:
040:            /* Same as A and B but different int value for element 2 */
041:            private int[] arrayDifferentValue;
042:
043:            /* Same as A and B but no 3rd element */
044:            private int[] arrayDifferentSize;
045:
046:            /* Same as A and B but of type long */
047:            private long[] arrayDifferentType;
048:
049:            /* Test element with inner array for element 2 */
050:            private Element arrayInnerA;
051:
052:            /* Same as innerA but different instance */
053:            private Element arrayInnerB;
054:
055:            /* Same as innerA and innerB but different int value for inner element 2 */
056:            private Element arrayInnerDifferentValue;
057:
058:            /* Same as innerA and innerB but no 3rd inner element */
059:            private Element arrayInnerDifferentSize;
060:
061:            /* Class under test */
062:            private ReflectionComparator reflectionComparator;
063:
064:            /* Class under test lenient order version */
065:            private ReflectionComparator reflectionComparatorLenientOrder;
066:
067:            /**
068:             * Initializes the test fixture.
069:             */
070:            protected void setUp() throws Exception {
071:                super .setUp();
072:
073:                arrayA = new int[] { 1, 2, 3 };
074:                arrayB = new int[] { 1, 2, 3 };
075:                arrayDifferentOrder = new int[] { 3, 1, 2 };
076:                arrayDifferentValue = new int[] { 1, 9999, 3 };
077:                arrayDifferentSize = new int[] { 1, 2 };
078:                arrayDifferentType = new long[] { 1, 2, 3 };
079:
080:                arrayInnerA = new Element(arrayA);
081:                arrayInnerB = new Element(arrayB);
082:                arrayInnerDifferentValue = new Element(arrayDifferentValue);
083:                arrayInnerDifferentSize = new Element(arrayDifferentSize);
084:
085:                reflectionComparator = ReflectionComparatorChainFactory.STRICT_COMPARATOR;
086:                reflectionComparatorLenientOrder = ReflectionComparatorChainFactory.LENIENTORDER_COMPARATOR;
087:            }
088:
089:            /**
090:             * Test for two equal arrays.
091:             */
092:            public void testGetDifference_equals() {
093:                Difference result = reflectionComparator.getDifference(arrayA,
094:                        arrayB);
095:                assertNull(result);
096:            }
097:
098:            /**
099:             * Test for two equal arrays as an inner field of an object.
100:             */
101:            public void testGetDifference_equalsInner() {
102:                Difference result = reflectionComparator.getDifference(
103:                        arrayInnerA, arrayInnerB);
104:                assertNull(result);
105:            }
106:
107:            /**
108:             * Test for two equal arrays with different order and no lenient order.
109:             */
110:            public void testGetDifference_notEqualsDifferentOrder() {
111:                Difference result = reflectionComparator.getDifference(arrayA,
112:                        arrayDifferentOrder);
113:
114:                assertNotNull(result);
115:                assertEquals("0", result.getFieldStack().get(0));
116:                assertEquals(1, result.getLeftValue());
117:                assertEquals(3, result.getRightValue());
118:            }
119:
120:            /**
121:             * Test for two equal arrays with different order but with lenient order.
122:             */
123:            public void testGetDifference_equalsLenientOrder() {
124:                Difference result = reflectionComparatorLenientOrder
125:                        .getDifference(arrayA, arrayDifferentOrder);
126:                assertNull(result);
127:            }
128:
129:            /**
130:             * Test for two equal primitives arrays but of different type (int vs long).
131:             */
132:            public void testGetDifference_differentTypes() {
133:                Difference result = reflectionComparator.getDifference(arrayA,
134:                        arrayDifferentType);
135:                assertNull(result);
136:            }
137:
138:            /**
139:             * Test for two arrays that contain different values.
140:             */
141:            public void testGetDifference_notEqualsDifferentValues() {
142:                Difference result = reflectionComparator.getDifference(arrayA,
143:                        arrayDifferentValue);
144:
145:                assertNotNull(result);
146:                assertEquals("1", result.getFieldStack().get(0));
147:                assertEquals(2, result.getLeftValue());
148:                assertEquals(9999, result.getRightValue());
149:            }
150:
151:            /**
152:             * Test for two arrays that have a different size.
153:             */
154:            public void testGetDifference_notEqualsDifferentSize() {
155:                Difference result = reflectionComparator.getDifference(arrayA,
156:                        arrayDifferentSize);
157:
158:                assertNotNull(result);
159:                assertTrue(result.getFieldStack().isEmpty());
160:                assertSame(arrayA, result.getLeftValue());
161:                assertSame(arrayDifferentSize, result.getRightValue());
162:            }
163:
164:            /**
165:             * Test for objects with inner arrays that contain different values.
166:             */
167:            public void testGetDifference_notEqualsInnerDifferentValues() {
168:                Difference result = reflectionComparator.getDifference(
169:                        arrayInnerA, arrayInnerDifferentValue);
170:
171:                assertNotNull(result);
172:                assertEquals("inner", result.getFieldStack().get(0));
173:                assertEquals("1", result.getFieldStack().get(1));
174:                assertEquals(2, result.getLeftValue());
175:                assertEquals(9999, result.getRightValue());
176:            }
177:
178:            /**
179:             * Tests for objects with inner arrays that have a different size.
180:             */
181:            public void testGetDifference_notEqualsInnerDifferentSize() {
182:                Difference result = reflectionComparator.getDifference(
183:                        arrayInnerA, arrayInnerDifferentSize);
184:
185:                assertNotNull(result);
186:                assertEquals("inner", result.getFieldStack().get(0));
187:                assertSame(arrayA, result.getLeftValue());
188:                assertSame(arrayDifferentSize, result.getRightValue());
189:            }
190:
191:            /**
192:             * Test class with failing equals.
193:             */
194:            private class Element {
195:
196:                /* An inner array */
197:                private int[] inner;
198:
199:                /**
200:                 * Creates and initializes the element.
201:                 *
202:                 * @param inner the inner array
203:                 */
204:                public Element(int[] inner) {
205:                    this .inner = inner;
206:                }
207:
208:                /**
209:                 * Gets the inner array
210:                 *
211:                 * @return the array
212:                 */
213:                public int[] getInner() {
214:                    return inner;
215:                }
216:
217:                /**
218:                 * Always returns false
219:                 *
220:                 * @param o the object to compare to
221:                 */
222:                @Override
223:                public boolean equals(Object o) {
224:                    return false;
225:                }
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.