package Sequenic.T2.Obj; import java.io.File; import java.util.*; import org.junit.* ; import static org.junit.Assert.* ; public class TestXShow { static class Tree { Object left ; Object right ; int id = 0 ; String name = "bla" ; Tree(Object t1, Object t2) { this.left = t1 ; this.right = t2 ; } } Tree singleton = new Tree(null,null) ; Tree cycle1() { Tree c = new Tree(null,null) ; c.left = c ; return c ; } Tree cycle2() { Tree c = new Tree(new Tree(null,null),null) ; ((Tree) c.left).left = c ; return c ; } Tree tree2() { Tree c = new Tree(new Tree(new Tree(null,null),null),new Object()) ; return c ; } Tree deep() { Tree c = new Tree(new Tree(new Tree(null,null),null),new Object()) ; for (int k=0; k<10; k++) c = new Tree(c,c) ; return c ; } @Test public void show() { assertTrue(XShow.show(new Object()).indexOf("Object") >= 0) ; String s = XShow.show(singleton) ; assertTrue(s.contains("Tree")) ; assertTrue(s.contains("left")) ; assertTrue(s.contains("NULL")) ; s = XShow.show(cycle1()) ; //System.out.println(s) ; assertTrue(s.contains("left (Tree) ---> @0")) ; s = XShow.show(cycle2()) ; //System.out.println(s) ; assertTrue(s.contains("left (Tree) ---> @0")) ; s = XShow.show(tree2()) ; //System.out.println(s) ; assertTrue(s.contains("5")) ; s = XShow.show(deep()) ; //System.out.println(s) ; assertFalse(s.contains("5")) ; assertTrue(s.contains("4")) ; assertTrue(s.contains("right (Tree) ---> @3")) ; assertTrue(s.contains("right (Tree) ---> @4")) ; assertFalse(s.contains("right (Tree) ---> @0")) ; List lt = new LinkedList() ; lt.add(singleton) ; lt.add(cycle1()) ; s = XShow.show(lt) ; //System.out.println(s) ; assertTrue(s.contains("left (Tree) ---> @3")) ; String[] a = { "hello", null, "world" } ; s = XShow.show(a) ; //System.out.println(s) ; assertTrue(s.contains("hello")) ; assertTrue(s.contains("NULL")) ; assertTrue(s.contains("world")) ; assertTrue(s.contains("[2]")) ; s = XShow.show(new File("foo")) ; //System.out.println(s) ; assertTrue(s.contains("(File) : ...")) ; } }