1 42 43 package org.jfree.chart.block.junit; 44 45 import java.awt.Color ; 46 import java.awt.Font ; 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectInputStream ; 51 import java.io.ObjectOutput ; 52 import java.io.ObjectOutputStream ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.chart.block.LabelBlock; 59 60 63 public class LabelBlockTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(LabelBlockTests.class); 72 } 73 74 79 public LabelBlockTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 LabelBlock b1 = new LabelBlock("ABC", new Font ("Dialog", 88 Font.PLAIN, 12), Color.red); 89 LabelBlock b2 = new LabelBlock("ABC", new Font ("Dialog", 90 Font.PLAIN, 12), Color.red); 91 assertTrue(b1.equals(b2)); 92 assertTrue(b2.equals(b2)); 93 94 b1 = new LabelBlock("XYZ", new Font ("Dialog", Font.PLAIN, 12), 95 Color.red); 96 assertFalse(b1.equals(b2)); 97 b2 = new LabelBlock("XYZ", new Font ("Dialog", Font.PLAIN, 12), 98 Color.red); 99 assertTrue(b1.equals(b2)); 100 101 b1 = new LabelBlock("XYZ", new Font ("Dialog", Font.BOLD, 12), 102 Color.red); 103 assertFalse(b1.equals(b2)); 104 b2 = new LabelBlock("XYZ", new Font ("Dialog", Font.BOLD, 12), 105 Color.red); 106 assertTrue(b1.equals(b2)); 107 108 b1 = new LabelBlock("XYZ", new Font ("Dialog", Font.BOLD, 12), 109 Color.blue); 110 assertFalse(b1.equals(b2)); 111 b2 = new LabelBlock("XYZ", new Font ("Dialog", Font.BOLD, 12), 112 Color.blue); 113 assertTrue(b1.equals(b2)); 114 115 b1.setToolTipText("Tooltip"); 116 assertFalse(b1.equals(b2)); 117 b2.setToolTipText("Tooltip"); 118 assertTrue(b1.equals(b2)); 119 120 b1.setURLText("URL"); 121 assertFalse(b1.equals(b2)); 122 b2.setURLText("URL"); 123 assertTrue(b1.equals(b2)); 124 } 125 126 129 public void testCloning() { 130 LabelBlock b1 = new LabelBlock("ABC", new Font ("Dialog", 131 Font.PLAIN, 12), Color.red); 132 LabelBlock b2 = null; 133 134 try { 135 b2 = (LabelBlock) b1.clone(); 136 } 137 catch (CloneNotSupportedException e) { 138 fail(e.toString()); 139 } 140 assertTrue(b1 != b2); 141 assertTrue(b1.getClass() == b2.getClass()); 142 assertTrue(b1.equals(b2)); 143 } 144 145 148 public void testSerialization() { 149 LabelBlock b1 = new LabelBlock("ABC", new Font ("Dialog", 150 Font.PLAIN, 12), Color.red); 151 LabelBlock b2 = null; 152 try { 153 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 154 ObjectOutput out = new ObjectOutputStream (buffer); 155 out.writeObject(b1); 156 out.close(); 157 158 ObjectInput in = new ObjectInputStream ( 159 new ByteArrayInputStream (buffer.toByteArray()) 160 ); 161 b2 = (LabelBlock) in.readObject(); 162 in.close(); 163 } 164 catch (Exception e) { 165 fail(e.toString()); 166 } 167 assertEquals(b1, b2); 168 } 169 170 } 171 | Popular Tags |