1 42 43 package org.jfree.chart.junit; 44 45 import java.awt.BasicStroke ; 46 import java.awt.Color ; 47 import java.awt.geom.Line2D ; 48 import java.awt.geom.Rectangle2D ; 49 import java.io.ByteArrayInputStream ; 50 import java.io.ByteArrayOutputStream ; 51 import java.io.ObjectInput ; 52 import java.io.ObjectInputStream ; 53 import java.io.ObjectOutput ; 54 import java.io.ObjectOutputStream ; 55 56 import junit.framework.Test; 57 import junit.framework.TestCase; 58 import junit.framework.TestSuite; 59 60 import org.jfree.chart.LegendItem; 61 import org.jfree.chart.LegendItemCollection; 62 63 66 public class LegendItemCollectionTests extends TestCase { 67 68 73 public static Test suite() { 74 return new TestSuite(LegendItemCollectionTests.class); 75 } 76 77 82 public LegendItemCollectionTests(String name) { 83 super(name); 84 } 85 86 89 public void testEquals() { 90 91 LegendItemCollection c1 = new LegendItemCollection(); 92 LegendItemCollection c2 = new LegendItemCollection(); 93 assertTrue(c1.equals(c2)); 94 assertTrue(c2.equals(c1)); 95 96 LegendItem item1 = new LegendItem("Label", "Description", 97 "ToolTip", "URL", true, 98 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), true, Color.red, 99 true, Color.blue, new BasicStroke (1.2f), true, 100 new Line2D.Double (1.0, 2.0, 3.0, 4.0), 101 new BasicStroke (2.1f), Color.green); 102 LegendItem item2 = new LegendItem("Label", "Description", 103 "ToolTip", "URL", true, 104 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), 105 true, Color.red, true, Color.blue, new BasicStroke (1.2f), true, 106 new Line2D.Double (1.0, 2.0, 3.0, 4.0), new BasicStroke (2.1f), 107 Color.green); 108 c1.add(item1); 109 c2.add(item2); 110 assertTrue(c1.equals(c2)); 111 112 } 113 114 115 118 public void testSerialization() { 119 LegendItemCollection c1 = new LegendItemCollection(); 120 c1.add(new LegendItem("Item", "Description", "ToolTip", "URL", 121 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), Color.red)); 122 LegendItemCollection c2 = null; 123 try { 124 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 125 ObjectOutput out = new ObjectOutputStream (buffer); 126 out.writeObject(c1); 127 out.close(); 128 129 ObjectInput in = new ObjectInputStream ( 130 new ByteArrayInputStream (buffer.toByteArray()) 131 ); 132 c2 = (LegendItemCollection) in.readObject(); 133 in.close(); 134 } 135 catch (Exception e) { 136 System.out.println(e.toString()); 137 } 138 assertEquals(c1, c2); 139 } 140 141 144 public void testCloning() { 145 146 LegendItemCollection c1 = new LegendItemCollection(); 147 c1.add(new LegendItem("Item", "Description", "ToolTip", "URL", 148 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), Color.red)); 149 LegendItemCollection c2 = null; 150 try { 151 c2 = (LegendItemCollection) c1.clone(); 152 } 153 catch (CloneNotSupportedException e) { 154 System.err.println("Failed to clone."); 155 } 156 assertTrue(c1 != c2); 157 assertTrue(c1.getClass() == c2.getClass()); 158 assertTrue(c1.equals(c2)); 159 160 } 161 162 } 163 | Popular Tags |