1 package com.tirsen.nanning.samples.prevayler; 2 3 import junit.framework.TestCase; 4 5 public class ObjectGraphVisitorTest extends TestCase { 6 7 public static class ABase { 8 B[] array = {new B(), new B()}; 9 B b = new B(); 10 Object nullField = null; 11 } 12 13 public static class A extends ABase { 14 public String toString() { 15 return "A"; 16 } 17 } 18 19 public static class B { 20 A circularity; 21 22 public String toString() { 23 return "B"; 24 } 25 } 26 27 28 public void test() { 29 final StringBuffer log = new StringBuffer (); 30 A a = new A(); 31 a.b.circularity = a; 32 ObjectGraphVisitor.visit(a, new ObjectGraphVisitor() { 33 public void visit(Object o) { 34 log.append(o); 35 super.visit(o); 36 } 37 }); 38 assertEquals("ABBB", log.toString()); 39 } 40 } 41 | Popular Tags |