1 42 43 package org.jfree.chart.entity.junit; 44 45 import java.awt.geom.Rectangle2D ; 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.entity.TickLabelEntity; 58 59 62 public class TickLabelEntityTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(TickLabelEntityTests.class); 71 } 72 73 78 public TickLabelEntityTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 TickLabelEntity e1 = new TickLabelEntity( 87 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), "ToolTip", "URL" 88 ); 89 TickLabelEntity e2 = new TickLabelEntity( 90 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), "ToolTip", "URL" 91 ); 92 assertTrue(e1.equals(e2)); 93 94 e1.setArea(new Rectangle2D.Double (4.0, 3.0, 2.0, 1.0)); 95 assertFalse(e1.equals(e2)); 96 e2.setArea(new Rectangle2D.Double (4.0, 3.0, 2.0, 1.0)); 97 assertTrue(e1.equals(e2)); 98 99 e1.setToolTipText("New ToolTip"); 100 assertFalse(e1.equals(e2)); 101 e2.setToolTipText("New ToolTip"); 102 assertTrue(e1.equals(e2)); 103 104 e1.setURLText("New URL"); 105 assertFalse(e1.equals(e2)); 106 e2.setURLText("New URL"); 107 assertTrue(e1.equals(e2)); 108 } 109 110 113 public void testCloning() { 114 TickLabelEntity e1 = new TickLabelEntity( 115 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), "ToolTip", "URL" 116 ); 117 TickLabelEntity e2 = null; 118 try { 119 e2 = (TickLabelEntity) e1.clone(); 120 } 121 catch (CloneNotSupportedException e) { 122 System.err.println("Failed to clone."); 123 } 124 assertTrue(e1 != e2); 125 assertTrue(e1.getClass() == e2.getClass()); 126 assertTrue(e1.equals(e2)); 127 } 128 129 132 public void testSerialization() { 133 TickLabelEntity e1 = new TickLabelEntity( 134 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), "ToolTip", "URL" 135 ); 136 TickLabelEntity e2 = null; 137 try { 138 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 139 ObjectOutput out = new ObjectOutputStream (buffer); 140 out.writeObject(e1); 141 out.close(); 142 143 ObjectInput in = new ObjectInputStream ( 144 new ByteArrayInputStream (buffer.toByteArray()) 145 ); 146 e2 = (TickLabelEntity) in.readObject(); 147 in.close(); 148 } 149 catch (Exception e) { 150 System.out.println(e.toString()); 151 } 152 assertEquals(e1, e2); 153 } 154 155 } 156 | Popular Tags |