Source Code Cross Referenced for DifferenceBuilderTest.java in  » Net » Terracotta » com » tc » util » diff » 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 » Net » Terracotta » com.tc.util.diff 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tc.util.diff;
005:
006:        import org.apache.commons.lang.builder.EqualsBuilder;
007:
008:        import com.tc.test.TCTestCase;
009:        import com.tc.util.Stringifier;
010:
011:        /**
012:         * Unit test for {@link DifferenceBuilder}.
013:         */
014:        public class DifferenceBuilderTest extends TCTestCase {
015:
016:            private static boolean USE_REFLECTION = false;
017:
018:            public static class TestObject implements  Differenceable {
019:                private final boolean aBoolean;
020:                private final char aChar;
021:                private final byte aByte;
022:                private final short aShort;
023:                private final int anInt;
024:                private final long aLong;
025:                private final float aFloat;
026:                private final double aDouble;
027:                private final Object anObject;
028:
029:                private final boolean[] arrBoolean;
030:                private final char[] arrChar;
031:                private final byte[] arrByte;
032:                private final short[] arrShort;
033:                private final int[] arrInt;
034:                private final long[] arrLong;
035:                private final float[] arrFloat;
036:                private final double[] arrDouble;
037:                private final Object[] arrObject;
038:
039:                public TestObject(boolean boolean1, char char1, byte byte1,
040:                        short short1, int anInt, long long1, float float1,
041:                        double double1, Object anObject, boolean[] arrBoolean,
042:                        char[] arrChar, byte[] arrByte, short[] arrShort,
043:                        int[] arrInt, long[] arrLong, float[] arrFloat,
044:                        double[] arrDouble, Object[] arrObject) {
045:                    super ();
046:
047:                    this .aBoolean = boolean1;
048:                    this .aChar = char1;
049:                    this .aByte = byte1;
050:                    this .aShort = short1;
051:                    this .anInt = anInt;
052:                    this .aLong = long1;
053:                    this .aFloat = float1;
054:                    this .aDouble = double1;
055:                    this .anObject = anObject;
056:                    this .arrBoolean = arrBoolean;
057:                    this .arrChar = arrChar;
058:                    this .arrByte = arrByte;
059:                    this .arrShort = arrShort;
060:                    this .arrInt = arrInt;
061:                    this .arrLong = arrLong;
062:                    this .arrFloat = arrFloat;
063:                    this .arrDouble = arrDouble;
064:                    this .arrObject = arrObject;
065:                }
066:
067:                public TestObject() {
068:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
069:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
070:                            new boolean[] { true, false, true }, new char[] {
071:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
072:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
073:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
074:                                    0.2f, 0.3f },
075:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
076:                                    "foo", "bar", "baz" });
077:                }
078:
079:                public TestObject(boolean bool) {
080:                    this (bool, 'x', (byte) 37, (short) 137, 1238415,
081:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
082:                            new boolean[] { true, false, true }, new char[] {
083:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
084:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
085:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
086:                                    0.2f, 0.3f },
087:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
088:                                    "foo", "bar", "baz" });
089:                }
090:
091:                public TestObject(char ch) {
092:                    this (true, ch, (byte) 37, (short) 137, 1238415,
093:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
094:                            new boolean[] { true, false, true }, new char[] {
095:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
096:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
097:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
098:                                    0.2f, 0.3f },
099:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
100:                                    "foo", "bar", "baz" });
101:                }
102:
103:                public TestObject(byte b) {
104:                    this (true, 'x', b, (short) 137, 1238415, 1238947198L,
105:                            4.34e+27f, 1.32523482759e+109, "foo",
106:                            new boolean[] { true, false, true }, new char[] {
107:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
108:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
109:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
110:                                    0.2f, 0.3f },
111:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
112:                                    "foo", "bar", "baz" });
113:                }
114:
115:                public TestObject(short s) {
116:                    this (true, 'x', (byte) 37, s, 1238415, 1238947198L,
117:                            4.34e+27f, 1.32523482759e+109, "foo",
118:                            new boolean[] { true, false, true }, new char[] {
119:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
120:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
121:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
122:                                    0.2f, 0.3f },
123:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
124:                                    "foo", "bar", "baz" });
125:                }
126:
127:                public TestObject(int i) {
128:                    this (true, 'x', (byte) 37, (short) 137, i, 1238947198L,
129:                            4.34e+27f, 1.32523482759e+109, "foo",
130:                            new boolean[] { true, false, true }, new char[] {
131:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
132:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
133:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
134:                                    0.2f, 0.3f },
135:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
136:                                    "foo", "bar", "baz" });
137:                }
138:
139:                public TestObject(long l) {
140:                    this (true, 'x', (byte) 37, (short) 137, 1238415, l,
141:                            4.34e+27f, 1.32523482759e+109, "foo",
142:                            new boolean[] { true, false, true }, new char[] {
143:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
144:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
145:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
146:                                    0.2f, 0.3f },
147:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
148:                                    "foo", "bar", "baz" });
149:                }
150:
151:                public TestObject(float f) {
152:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
153:                            1238947198L, f, 1.32523482759e+109, "foo",
154:                            new boolean[] { true, false, true }, new char[] {
155:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
156:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
157:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
158:                                    0.2f, 0.3f },
159:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
160:                                    "foo", "bar", "baz" });
161:                }
162:
163:                public TestObject(double d) {
164:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
165:                            1238947198L, 4.34e+27f, d, "foo", new boolean[] {
166:                                    true, false, true }, new char[] { 'a', 'b',
167:                                    'c' }, new byte[] { 3, 4, 5 }, new short[] {
168:                                    4, 5, 6 }, new int[] { 7, 8, 9 },
169:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
170:                                    0.2f, 0.3f },
171:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
172:                                    "foo", "bar", "baz" });
173:                }
174:
175:                public TestObject(Object o) {
176:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
177:                            1238947198L, 4.34e+27f, 1.32523482759e+109, o,
178:                            new boolean[] { true, false, true }, new char[] {
179:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
180:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
181:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
182:                                    0.2f, 0.3f },
183:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
184:                                    "foo", "bar", "baz" });
185:                }
186:
187:                public TestObject(boolean[] ab) {
188:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
189:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
190:                            ab, new char[] { 'a', 'b', 'c' }, new byte[] { 3,
191:                                    4, 5 }, new short[] { 4, 5, 6 }, new int[] {
192:                                    7, 8, 9 }, new long[] { 10, 11, 12 },
193:                            new float[] { 0.1f, 0.2f, 0.3f }, new double[] {
194:                                    0.4, 0.5, 0.6 }, new Object[] { "foo",
195:                                    "bar", "baz" });
196:                }
197:
198:                public TestObject(char[] ac) {
199:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
200:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
201:                            new boolean[] { true, false, true }, ac,
202:                            new byte[] { 3, 4, 5 }, new short[] { 4, 5, 6 },
203:                            new int[] { 7, 8, 9 }, new long[] { 10, 11, 12 },
204:                            new float[] { 0.1f, 0.2f, 0.3f }, new double[] {
205:                                    0.4, 0.5, 0.6 }, new Object[] { "foo",
206:                                    "bar", "baz" });
207:                }
208:
209:                public TestObject(byte[] ab) {
210:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
211:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
212:                            new boolean[] { true, false, true }, new char[] {
213:                                    'a', 'b', 'c' }, ab,
214:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
215:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
216:                                    0.2f, 0.3f },
217:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
218:                                    "foo", "bar", "baz" });
219:                }
220:
221:                public TestObject(short[] as) {
222:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
223:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
224:                            new boolean[] { true, false, true }, new char[] {
225:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
226:                            as, new int[] { 7, 8, 9 },
227:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
228:                                    0.2f, 0.3f },
229:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
230:                                    "foo", "bar", "baz" });
231:                }
232:
233:                public TestObject(int[] ai) {
234:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
235:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
236:                            new boolean[] { true, false, true }, new char[] {
237:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
238:                            new short[] { 4, 5, 6 }, ai, new long[] { 10, 11,
239:                                    12 }, new float[] { 0.1f, 0.2f, 0.3f },
240:                            new double[] { 0.4, 0.5, 0.6 }, new Object[] {
241:                                    "foo", "bar", "baz" });
242:                }
243:
244:                public TestObject(long[] al) {
245:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
246:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
247:                            new boolean[] { true, false, true }, new char[] {
248:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
249:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 }, al,
250:                            new float[] { 0.1f, 0.2f, 0.3f }, new double[] {
251:                                    0.4, 0.5, 0.6 }, new Object[] { "foo",
252:                                    "bar", "baz" });
253:                }
254:
255:                public TestObject(float[] af) {
256:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
257:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
258:                            new boolean[] { true, false, true }, new char[] {
259:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
260:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
261:                            new long[] { 10, 11, 12 }, af, new double[] { 0.4,
262:                                    0.5, 0.6 }, new Object[] { "foo", "bar",
263:                                    "baz" });
264:                }
265:
266:                public TestObject(double[] ad) {
267:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
268:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
269:                            new boolean[] { true, false, true }, new char[] {
270:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
271:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
272:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
273:                                    0.2f, 0.3f }, ad, new Object[] { "foo",
274:                                    "bar", "baz" });
275:                }
276:
277:                public TestObject(Object[] ao) {
278:                    this (true, 'x', (byte) 37, (short) 137, 1238415,
279:                            1238947198L, 4.34e+27f, 1.32523482759e+109, "foo",
280:                            new boolean[] { true, false, true }, new char[] {
281:                                    'a', 'b', 'c' }, new byte[] { 3, 4, 5 },
282:                            new short[] { 4, 5, 6 }, new int[] { 7, 8, 9 },
283:                            new long[] { 10, 11, 12 }, new float[] { 0.1f,
284:                                    0.2f, 0.3f },
285:                            new double[] { 0.4, 0.5, 0.6 }, ao);
286:                }
287:
288:                public void addDifferences(DifferenceContext context,
289:                        Object rawThat) {
290:                    TestObject that = (TestObject) rawThat;
291:
292:                    if (USE_REFLECTION) {
293:                        new DifferenceBuilder(context).reflectionDifference(
294:                                this , rawThat);
295:                    } else {
296:                        new DifferenceBuilder(context).append("aBoolean",
297:                                this .aBoolean, that.aBoolean).append("aChar",
298:                                this .aChar, that.aChar).append("aByte",
299:                                this .aByte, that.aByte).append("aShort",
300:                                this .aShort, that.aShort).append("anInt",
301:                                this .anInt, that.anInt).append("aLong",
302:                                this .aLong, that.aLong).append("aFloat",
303:                                this .aFloat, that.aFloat).append("aDouble",
304:                                this .aDouble, that.aDouble).append("anObject",
305:                                this .anObject, that.anObject).append(
306:                                "arrBoolean", this .arrBoolean, that.arrBoolean)
307:                                .append("arrChar", this .arrChar, that.arrChar)
308:                                .append("arrByte", this .arrByte, that.arrByte)
309:                                .append("arrShort", this .arrShort,
310:                                        that.arrShort).append("arrInt",
311:                                        this .arrInt, that.arrInt).append(
312:                                        "arrLong", this .arrLong, that.arrLong)
313:                                .append("arrFloat", this .arrFloat,
314:                                        that.arrFloat).append("arrDouble",
315:                                        this .arrDouble, that.arrDouble).append(
316:                                        "arrObject", this .arrObject,
317:                                        that.arrObject);
318:                    }
319:                }
320:
321:                public boolean equals(Object that) {
322:                    if (!(that instanceof  TestObject))
323:                        return false;
324:
325:                    TestObject testThat = (TestObject) that;
326:
327:                    return EqualsBuilder.reflectionEquals(this , testThat);
328:                }
329:            }
330:
331:            public void testConstruction() throws Exception {
332:                try {
333:                    new DifferenceBuilder(null);
334:                    fail("Didn't get NPE on no context");
335:                } catch (NullPointerException npe) {
336:                    // ok
337:                }
338:            }
339:
340:            public void testNoDifference() throws Exception {
341:                TestObject one = new TestObject();
342:                TestObject two = new TestObject();
343:
344:                assertEqualsUnordered(new Object[0], DifferenceBuilder
345:                        .getDifferences(one, two));
346:                assertEqualsUnordered(new Object[0], DifferenceBuilder
347:                        .getDifferencesAsArray(one, two));
348:            }
349:
350:            public void testPrimitives() throws Exception {
351:                USE_REFLECTION = false;
352:                checkPrimitives();
353:                USE_REFLECTION = true;
354:                checkPrimitives();
355:            }
356:
357:            public void testPrimitiveArrays() throws Exception {
358:                USE_REFLECTION = false;
359:                checkPrimitiveArrays();
360:                USE_REFLECTION = true;
361:                checkPrimitiveArrays();
362:            }
363:
364:            public void testObjects() throws Exception {
365:                USE_REFLECTION = true;
366:                checkObjects();
367:                USE_REFLECTION = false;
368:                checkObjects();
369:            }
370:
371:            public void testObjectArrays() throws Exception {
372:                USE_REFLECTION = true;
373:                checkObjectArrays();
374:                USE_REFLECTION = false;
375:                checkObjectArrays();
376:            }
377:
378:            public void testNestedObjects() throws Exception {
379:                USE_REFLECTION = true;
380:                checkNestedObjects();
381:                USE_REFLECTION = false;
382:                checkNestedObjects();
383:            }
384:
385:            public void testUsesStringifier() throws Exception {
386:                USE_REFLECTION = true;
387:                checkStringifier();
388:                USE_REFLECTION = false;
389:                checkStringifier();
390:            }
391:
392:            public void testDifferentClasses() throws Exception {
393:                USE_REFLECTION = true;
394:                checkDifferentClasses();
395:                USE_REFLECTION = false;
396:                checkDifferentClasses();
397:            }
398:
399:            public void testDerivedClasses() throws Exception {
400:                USE_REFLECTION = true;
401:                checkDerivedClasses();
402:                USE_REFLECTION = false;
403:                checkDerivedClasses();
404:            }
405:
406:            private static class OtherDifferenceable implements  Differenceable {
407:                private final Object a;
408:
409:                public OtherDifferenceable(Object a) {
410:                    this .a = a;
411:                }
412:
413:                public void addDifferences(DifferenceContext context,
414:                        Object that) {
415:                    if (USE_REFLECTION) {
416:                        new DifferenceBuilder(context).reflectionDifference(
417:                                this , that);
418:                    } else {
419:                        new DifferenceBuilder(context).append("a", this .a,
420:                                ((OtherDifferenceable) that).a);
421:                    }
422:                }
423:
424:                public boolean equals(Object o) {
425:                    return (o instanceof  OtherDifferenceable)
426:                            && (this .a.equals(((OtherDifferenceable) o).a));
427:                }
428:            }
429:
430:            private static class FieldAdded extends OtherDifferenceable {
431:                private final Object b;
432:
433:                public FieldAdded(Object a, Object b) {
434:                    super (a);
435:                    this .b = b;
436:                }
437:
438:                public void addDifferences(DifferenceContext context,
439:                        Object that) {
440:                    super .addDifferences(context, that);
441:                    if (USE_REFLECTION) {
442:                        new DifferenceBuilder(context).reflectionDifference(
443:                                this , that);
444:                    } else {
445:                        new DifferenceBuilder(context).append("b", this .b,
446:                                ((FieldAdded) that).b);
447:                    }
448:                }
449:
450:                public boolean equals(Object that) {
451:                    if (!super .equals(that))
452:                        return false;
453:                    if (!(that instanceof  FieldAdded))
454:                        return false;
455:                    return ((FieldAdded) that).b.equals(this .b);
456:                }
457:            }
458:
459:            private static class FieldIgnored extends OtherDifferenceable {
460:                private final Object b;
461:
462:                public FieldIgnored(Object a, Object b) {
463:                    super (a);
464:                    this .b = b;
465:                }
466:
467:                Object getB() {
468:                    return this .b;
469:                }
470:            }
471:
472:            private void checkDifferentClasses() throws Exception {
473:                TestObject oneSub = new TestObject();
474:                TestObject one = new TestObject(oneSub);
475:                OtherDifferenceable twoSub = new OtherDifferenceable("foo");
476:                TestObject two = new TestObject(twoSub);
477:                OtherDifferenceable three = new OtherDifferenceable(oneSub);
478:
479:                DifferenceContext initial = DifferenceContext.createInitial(), context;
480:                context = initial.sub("anObject");
481:                assertEqualsUnordered(new Object[] { contextify(context,
482:                        new BasicObjectDifference(context, oneSub, twoSub)) },
483:                        DifferenceBuilder.getDifferences(one, two));
484:
485:                initial = DifferenceContext.createInitial();
486:                context = initial.sub("anObject");
487:                assertEqualsUnordered(new Object[] { contextify(context,
488:                        new BasicObjectDifference(context, twoSub, oneSub)) },
489:                        DifferenceBuilder.getDifferences(two, one));
490:
491:                initial = DifferenceContext.createInitial();
492:                context = initial;
493:                assertEqualsUnordered(new Object[] { contextify(context,
494:                        new BasicObjectDifference(context, one, three)) },
495:                        DifferenceBuilder.getDifferences(one, three));
496:
497:                initial = DifferenceContext.createInitial();
498:                context = initial;
499:                assertEqualsUnordered(new Object[] { contextify(context,
500:                        new BasicObjectDifference(context, three, one)) },
501:                        DifferenceBuilder.getDifferences(three, one));
502:            }
503:
504:            private void checkDerivedClasses() throws Exception {
505:                OtherDifferenceable base = new OtherDifferenceable("a");
506:                OtherDifferenceable added = new FieldAdded("a", "b");
507:                OtherDifferenceable ignored = new FieldIgnored("a", "b");
508:
509:                DifferenceContext initial = DifferenceContext.createInitial(), context;
510:                context = initial;
511:                assertEqualsUnordered(new Object[] { contextify(context,
512:                        new BasicObjectDifference(context, base, added)) },
513:                        DifferenceBuilder.getDifferences(base, added));
514:
515:                initial = DifferenceContext.createInitial();
516:                context = initial;
517:                assertEqualsUnordered(new Object[] { contextify(context,
518:                        new BasicObjectDifference(context, added, base)) },
519:                        DifferenceBuilder.getDifferences(added, base));
520:
521:                initial = DifferenceContext.createInitial();
522:                context = initial;
523:                assertEqualsUnordered(new Object[] { contextify(context,
524:                        new BasicObjectDifference(context, base, ignored)) },
525:                        DifferenceBuilder.getDifferences(base, ignored));
526:
527:                initial = DifferenceContext.createInitial();
528:                context = initial;
529:                assertEqualsUnordered(new Object[] { contextify(context,
530:                        new BasicObjectDifference(context, ignored, base)) },
531:                        DifferenceBuilder.getDifferences(ignored, base));
532:            }
533:
534:            private void checkStringifier() throws Exception {
535:                Stringifier s = new Stringifier() {
536:                    public String toString(Object o) {
537:                        return "X" + o + "Y";
538:                    }
539:                };
540:
541:                TestObject one, two;
542:                DifferenceContext initial = DifferenceContext.createInitial(s);
543:
544:                one = new TestObject("foo");
545:                two = new TestObject("foof");
546:                initial.sub("anObject");
547:                Difference[] differences = DifferenceBuilder
548:                        .getDifferencesAsArray(one, two, s);
549:                String theString = differences[0].toString();
550:                assertTrue(theString.indexOf("XfooY") >= 0);
551:                assertTrue(theString.indexOf("XfoofY") >= 0);
552:            }
553:
554:            private void checkNestedObjects() throws Exception {
555:                TestObject one, two;
556:                DifferenceContext initial = DifferenceContext.createInitial(), context;
557:
558:                TestObject diffOne = new TestObject("foo");
559:                TestObject diffTwo = new TestObject("bar");
560:
561:                one = new TestObject(new TestObject(new Object[] {
562:                        new TestObject(),
563:                        new TestObject(new Object[] { "a", "b", "c", "d",
564:                                new TestObject(diffOne) }) }));
565:                two = new TestObject(new TestObject(new Object[] {
566:                        new TestObject(),
567:                        new TestObject(new Object[] { "a", "b", "c", "d",
568:                                new TestObject(diffTwo) }) }));
569:
570:                context = initial.sub("anObject").sub("arrObject[1]").sub(
571:                        "arrObject[4]").sub("anObject").sub("anObject");
572:                assertEqualsUnordered(new Object[] { contextify(context,
573:                        new BasicObjectDifference(context, "foo", "bar")) },
574:                        DifferenceBuilder.getDifferences(one, two));
575:            }
576:
577:            private void checkObjects() throws Exception {
578:                TestObject one, two;
579:                DifferenceContext initial = DifferenceContext.createInitial(), context;
580:
581:                one = new TestObject("foo");
582:                two = new TestObject("foof");
583:                context = initial.sub("anObject");
584:                assertEqualsUnordered(new Object[] { contextify(context,
585:                        new BasicObjectDifference(context, "foo", "foof")) },
586:                        DifferenceBuilder.getDifferences(one, two));
587:            }
588:
589:            private void checkObjectArrays() throws Exception {
590:                TestObject one, two;
591:                DifferenceContext initial = DifferenceContext.createInitial(), context;
592:
593:                one = new TestObject(new String[] { "a", "foo", "b" });
594:                two = new TestObject(new String[] { "a", "foof", "b" });
595:                context = initial.sub("arrObject[1]");
596:                assertEqualsUnordered(new Object[] { contextify(context,
597:                        new BasicObjectDifference(context, "foo", "foof")) },
598:                        DifferenceBuilder.getDifferences(one, two));
599:            }
600:
601:            private void checkPrimitives() throws Exception {
602:                TestObject one, two;
603:                DifferenceContext initial = DifferenceContext.createInitial(), context;
604:
605:                one = new TestObject(true);
606:                two = new TestObject(false);
607:                context = initial.sub("aBoolean");
608:                assertEqualsUnordered(new Object[] { contextify(context,
609:                        new PrimitiveDifference(context, true, false)) },
610:                        DifferenceBuilder.getDifferences(one, two));
611:
612:                one = new TestObject('x');
613:                two = new TestObject('y');
614:                context = initial.sub("aChar");
615:                assertEqualsUnordered(new Object[] { contextify(context,
616:                        new PrimitiveDifference(context, 'x', 'y')) },
617:                        DifferenceBuilder.getDifferences(one, two));
618:
619:                one = new TestObject((byte) 14);
620:                two = new TestObject((byte) 15);
621:                context = initial.sub("aByte");
622:                assertEqualsUnordered(
623:                        new Object[] { contextify(context,
624:                                new PrimitiveDifference(context, (byte) 14,
625:                                        (byte) 15)) }, DifferenceBuilder
626:                                .getDifferences(one, two));
627:
628:                one = new TestObject((short) 14);
629:                two = new TestObject((short) 15);
630:                context = initial.sub("aShort");
631:                assertEqualsUnordered(
632:                        new Object[] { contextify(context,
633:                                new PrimitiveDifference(context, (short) 14,
634:                                        (short) 15)) }, DifferenceBuilder
635:                                .getDifferences(one, two));
636:
637:                one = new TestObject(14);
638:                two = new TestObject(15);
639:                context = initial.sub("anInt");
640:                assertEqualsUnordered(new Object[] { contextify(context,
641:                        new PrimitiveDifference(context, 14, 15)) },
642:                        DifferenceBuilder.getDifferences(one, two));
643:
644:                one = new TestObject(14L);
645:                two = new TestObject(15L);
646:                context = initial.sub("aLong");
647:                assertEqualsUnordered(new Object[] { contextify(context,
648:                        new PrimitiveDifference(context, 14L, 15L)) },
649:                        DifferenceBuilder.getDifferences(one, two));
650:
651:                one = new TestObject(14.0f);
652:                two = new TestObject(15.0f);
653:                context = initial.sub("aFloat");
654:                assertEqualsUnordered(new Object[] { contextify(context,
655:                        new PrimitiveDifference(context, 14.0f, 15.0f)) },
656:                        DifferenceBuilder.getDifferences(one, two));
657:
658:                one = new TestObject(14.0);
659:                two = new TestObject(15.0);
660:                context = initial.sub("aDouble");
661:                assertEqualsUnordered(new Object[] { contextify(context,
662:                        new PrimitiveDifference(context, 14.0, 15.0)) },
663:                        DifferenceBuilder.getDifferences(one, two));
664:            }
665:
666:            private void checkPrimitiveArrays() throws Exception {
667:                TestObject one, two;
668:                DifferenceContext initial = DifferenceContext.createInitial(), context;
669:
670:                one = new TestObject(new boolean[] { true, false, true });
671:                two = new TestObject(new boolean[] { true, false, false });
672:                context = initial.sub("arrBoolean[2]");
673:                assertEqualsUnordered(new Object[] { contextify(context,
674:                        new PrimitiveDifference(context, true, false)) },
675:                        DifferenceBuilder.getDifferences(one, two));
676:
677:                one = new TestObject(new char[] { 'a', 'x', 'c' });
678:                two = new TestObject(new char[] { 'a', 'y', 'c' });
679:                context = initial.sub("arrChar[1]");
680:                assertEqualsUnordered(new Object[] { contextify(context,
681:                        new PrimitiveDifference(context, 'x', 'y')) },
682:                        DifferenceBuilder.getDifferences(one, two));
683:
684:                one = new TestObject(new byte[] { (byte) 14, (byte) 14,
685:                        (byte) 15 });
686:                two = new TestObject(new byte[] { (byte) 15, (byte) 14,
687:                        (byte) 15 });
688:                context = initial.sub("arrByte[0]");
689:                assertEqualsUnordered(
690:                        new Object[] { contextify(context,
691:                                new PrimitiveDifference(context, (byte) 14,
692:                                        (byte) 15)) }, DifferenceBuilder
693:                                .getDifferences(one, two));
694:
695:                one = new TestObject(new short[] { (short) 3, (short) 4,
696:                        (short) 14 });
697:                two = new TestObject(new short[] { (short) 3, (short) 4,
698:                        (short) 15 });
699:                context = initial.sub("arrShort[2]");
700:                assertEqualsUnordered(
701:                        new Object[] { contextify(context,
702:                                new PrimitiveDifference(context, (short) 14,
703:                                        (short) 15)) }, DifferenceBuilder
704:                                .getDifferences(one, two));
705:
706:                one = new TestObject(new int[] { 3, 14, 5 });
707:                two = new TestObject(new int[] { 3, 15, 5 });
708:                context = initial.sub("arrInt[1]");
709:                assertEqualsUnordered(new Object[] { contextify(context,
710:                        new PrimitiveDifference(context, 14, 15)) },
711:                        DifferenceBuilder.getDifferences(one, two));
712:
713:                one = new TestObject(new long[] { 14, 3, 4 });
714:                two = new TestObject(new long[] { 15, 3, 4 });
715:                context = initial.sub("arrLong[0]");
716:                assertEqualsUnordered(new Object[] { contextify(context,
717:                        new PrimitiveDifference(context, 14L, 15L)) },
718:                        DifferenceBuilder.getDifferences(one, two));
719:
720:                one = new TestObject(new float[] { 3.0f, 4.0f, 14.0f });
721:                two = new TestObject(new float[] { 3.0f, 4.0f, 15.0f });
722:                context = initial.sub("arrFloat[2]");
723:                assertEqualsUnordered(new Object[] { contextify(context,
724:                        new PrimitiveDifference(context, 14.0f, 15.0f)) },
725:                        DifferenceBuilder.getDifferences(one, two));
726:
727:                one = new TestObject(new double[] { 3.0, 14.0, 5.0 });
728:                two = new TestObject(new double[] { 3.0, 15.0, 5.0 });
729:                context = initial.sub("arrDouble[1]");
730:                assertEqualsUnordered(new Object[] { contextify(context,
731:                        new PrimitiveDifference(context, 14.0, 15.0)) },
732:                        DifferenceBuilder.getDifferences(one, two));
733:            }
734:
735:            private Difference contextify(DifferenceContext context,
736:                    Difference difference) {
737:                context.addDifference(difference);
738:                return difference;
739:            }
740:
741:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.