1 42 43 package org.jfree.experimental.chart.plot.dial.junit; 44 45 import java.awt.Color ; 46 import java.awt.GradientPaint ; 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.experimental.chart.plot.dial.DialBackground; 59 import org.jfree.ui.GradientPaintTransformType; 60 import org.jfree.ui.StandardGradientPaintTransformer; 61 62 65 public class DialBackgroundTests extends TestCase { 66 67 72 public static Test suite() { 73 return new TestSuite(DialBackgroundTests.class); 74 } 75 76 81 public DialBackgroundTests(String name) { 82 super(name); 83 } 84 85 88 public void testEquals() { 89 DialBackground b1 = new DialBackground(); 90 DialBackground b2 = new DialBackground(); 91 assertTrue(b1.equals(b2)); 92 93 b1.setPaint(new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 4.0f, 95 Color.yellow)); 96 assertFalse(b1.equals(b2)); 97 b2.setPaint(new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 4.0f, 98 Color.yellow)); 99 assertTrue(b1.equals(b2)); 100 101 b1.setGradientPaintTransformer(new StandardGradientPaintTransformer( 103 GradientPaintTransformType.CENTER_VERTICAL)); 104 assertFalse(b1.equals(b2)); 105 b2.setGradientPaintTransformer(new StandardGradientPaintTransformer( 106 GradientPaintTransformType.CENTER_VERTICAL)); 107 assertTrue(b1.equals(b2)); 108 } 109 110 113 public void testHashCode() { 114 DialBackground b1 = new DialBackground(Color.red); 115 DialBackground b2 = new DialBackground(Color.red); 116 assertTrue(b1.equals(b2)); 117 int h1 = b1.hashCode(); 118 int h2 = b2.hashCode(); 119 assertEquals(h1, h2); 120 } 121 122 125 public void testCloning() { 126 DialBackground b1 = new DialBackground(); 128 DialBackground b2 = null; 129 try { 130 b2 = (DialBackground) b1.clone(); 131 } 132 catch (CloneNotSupportedException e) { 133 e.printStackTrace(); 134 } 135 assertTrue(b1 != b2); 136 assertTrue(b1.getClass() == b2.getClass()); 137 assertTrue(b1.equals(b2)); 138 139 b1 = new DialBackground(); 141 b1.setPaint(new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 4.0f, 142 Color.green)); 143 b1.setGradientPaintTransformer(new StandardGradientPaintTransformer( 144 GradientPaintTransformType.CENTER_VERTICAL)); 145 b2 = null; 146 try { 147 b2 = (DialBackground) b1.clone(); 148 } 149 catch (CloneNotSupportedException e) { 150 e.printStackTrace(); 151 } 152 assertTrue(b1 != b2); 153 assertTrue(b1.getClass() == b2.getClass()); 154 assertTrue(b1.equals(b2)); 155 } 156 157 158 161 public void testSerialization() { 162 DialBackground b1 = new DialBackground(); 164 DialBackground b2 = null; 165 166 try { 167 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 168 ObjectOutput out = new ObjectOutputStream (buffer); 169 out.writeObject(b1); 170 out.close(); 171 172 ObjectInput in = new ObjectInputStream ( 173 new ByteArrayInputStream (buffer.toByteArray())); 174 b2 = (DialBackground) in.readObject(); 175 in.close(); 176 } 177 catch (Exception e) { 178 e.printStackTrace(); 179 } 180 assertEquals(b1, b2); 181 182 b1 = new DialBackground(); 184 b1.setPaint(new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 4.0f, 185 Color.green)); 186 b1.setGradientPaintTransformer(new StandardGradientPaintTransformer( 187 GradientPaintTransformType.CENTER_VERTICAL)); 188 b2 = null; 189 190 try { 191 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 192 ObjectOutput out = new ObjectOutputStream (buffer); 193 out.writeObject(b1); 194 out.close(); 195 196 ObjectInput in = new ObjectInputStream ( 197 new ByteArrayInputStream (buffer.toByteArray())); 198 b2 = (DialBackground) in.readObject(); 199 in.close(); 200 } 201 catch (Exception e) { 202 e.printStackTrace(); 203 } 204 assertEquals(b1, b2); 205 } 206 207 } 208 | Popular Tags |