1 42 43 package org.jfree.chart.title.junit; 44 45 import java.awt.Color ; 46 import java.io.ByteArrayInputStream ; 47 import java.io.ByteArrayOutputStream ; 48 import java.io.ObjectInput ; 49 import java.io.ObjectInputStream ; 50 import java.io.ObjectOutput ; 51 import java.io.ObjectOutputStream ; 52 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.chart.block.BlockBorder; 58 import org.jfree.chart.block.BlockContainer; 59 import org.jfree.chart.title.CompositeTitle; 60 import org.jfree.chart.title.TextTitle; 61 import org.jfree.ui.RectangleInsets; 62 63 66 public class CompositeTitleTests extends TestCase { 67 68 73 public static Test suite() { 74 return new TestSuite(CompositeTitleTests.class); 75 } 76 77 82 public CompositeTitleTests(String name) { 83 super(name); 84 } 85 86 89 public void testEquals() { 90 CompositeTitle t1 = new CompositeTitle(new BlockContainer()); 91 CompositeTitle t2 = new CompositeTitle(new BlockContainer()); 92 assertEquals(t1, t2); 93 assertEquals(t2, t1); 94 95 t1.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); 97 assertFalse(t1.equals(t2)); 98 t2.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); 99 assertTrue(t1.equals(t2)); 100 101 t1.setBorder(new BlockBorder(Color.red)); 103 assertFalse(t1.equals(t2)); 104 t2.setBorder(new BlockBorder(Color.red)); 105 assertTrue(t1.equals(t2)); 106 107 t1.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); 109 assertFalse(t1.equals(t2)); 110 t2.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); 111 assertTrue(t1.equals(t2)); 112 113 t1.getContainer().add(new TextTitle("T1")); 115 assertFalse(t1.equals(t2)); 116 t2.getContainer().add(new TextTitle("T1")); 117 assertTrue(t1.equals(t2)); 118 119 } 120 121 124 public void testHashcode() { 125 CompositeTitle t1 = new CompositeTitle(new BlockContainer()); 126 t1.getContainer().add(new TextTitle("T1")); 127 CompositeTitle t2 = new CompositeTitle(new BlockContainer()); 128 t2.getContainer().add(new TextTitle("T1")); 129 assertTrue(t1.equals(t2)); 130 int h1 = t1.hashCode(); 131 int h2 = t2.hashCode(); 132 assertEquals(h1, h2); 133 } 134 135 138 public void testCloning() { 139 CompositeTitle t1 = new CompositeTitle(new BlockContainer()); 140 t1.getContainer().add(new TextTitle("T1")); 141 CompositeTitle t2 = null; 142 try { 143 t2 = (CompositeTitle) t1.clone(); 144 } 145 catch (CloneNotSupportedException e) { 146 fail(e.toString()); 147 } 148 assertTrue(t1 != t2); 149 assertTrue(t1.getClass() == t2.getClass()); 150 assertTrue(t1.equals(t2)); 151 } 152 153 156 public void testSerialization() { 157 CompositeTitle t1 = new CompositeTitle(new BlockContainer()); 158 t1.getContainer().add(new TextTitle("T1")); 159 CompositeTitle t2 = null; 160 try { 161 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 162 ObjectOutput out = new ObjectOutputStream (buffer); 163 out.writeObject(t1); 164 out.close(); 165 166 ObjectInput in = new ObjectInputStream ( 167 new ByteArrayInputStream (buffer.toByteArray()) 168 ); 169 t2 = (CompositeTitle) in.readObject(); 170 in.close(); 171 } 172 catch (Exception e) { 173 System.out.println(e.toString()); 174 } 175 assertEquals(t1, t2); 176 } 177 178 } 179 | Popular Tags |