1 42 43 package org.jfree.chart.block.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.chart.block.BlockContainer; 57 import org.jfree.chart.block.ColumnArrangement; 58 import org.jfree.chart.block.EmptyBlock; 59 import org.jfree.chart.block.FlowArrangement; 60 61 64 public class BlockContainerTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(BlockContainerTests.class); 73 } 74 75 80 public BlockContainerTests(String name) { 81 super(name); 82 } 83 84 87 public void testEquals() { 88 BlockContainer c1 = new BlockContainer(new FlowArrangement()); 89 BlockContainer c2 = new BlockContainer(new FlowArrangement()); 90 assertTrue(c1.equals(c2)); 91 assertTrue(c2.equals(c2)); 92 93 c1.setArrangement(new ColumnArrangement()); 94 assertFalse(c1.equals(c2)); 95 c2.setArrangement(new ColumnArrangement()); 96 assertTrue(c1.equals(c2)); 97 98 c1.add(new EmptyBlock(1.2, 3.4)); 99 assertFalse(c1.equals(c2)); 100 c2.add(new EmptyBlock(1.2, 3.4)); 101 assertTrue(c1.equals(c2)); 102 } 103 104 107 public void testCloning() { 108 BlockContainer c1 = new BlockContainer(new FlowArrangement()); 109 c1.add(new EmptyBlock(1.2, 3.4)); 110 111 BlockContainer c2 = null; 112 113 try { 114 c2 = (BlockContainer) c1.clone(); 115 } 116 catch (CloneNotSupportedException e) { 117 System.err.println("Failed to clone."); 118 } 119 assertTrue(c1 != c2); 120 assertTrue(c1.getClass() == c2.getClass()); 121 assertTrue(c1.equals(c2)); 122 } 123 124 127 public void testSerialization() { 128 BlockContainer c1 = new BlockContainer(); 129 c1.add(new EmptyBlock(1.2, 3.4)); 130 BlockContainer c2 = null; 131 try { 132 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 133 ObjectOutput out = new ObjectOutputStream (buffer); 134 out.writeObject(c1); 135 out.close(); 136 137 ObjectInput in = new ObjectInputStream ( 138 new ByteArrayInputStream (buffer.toByteArray()) 139 ); 140 c2 = (BlockContainer) in.readObject(); 141 in.close(); 142 } 143 catch (Exception e) { 144 fail(e.toString()); 145 } 146 assertEquals(c1, c2); 147 } 148 149 } 150 | Popular Tags |