1 package org.jfree.experimental.chart.plot.dial.junit; 2 3 import java.awt.BasicStroke ; 4 import java.awt.Color ; 5 import java.awt.GradientPaint ; 6 import java.io.ByteArrayInputStream ; 7 import java.io.ByteArrayOutputStream ; 8 import java.io.ObjectInput ; 9 import java.io.ObjectInputStream ; 10 import java.io.ObjectOutput ; 11 import java.io.ObjectOutputStream ; 12 13 import junit.framework.Test; 14 import junit.framework.TestCase; 15 import junit.framework.TestSuite; 16 17 import org.jfree.experimental.chart.plot.dial.StandardDialFrame; 18 19 22 public class StandardDialFrameTests extends TestCase { 23 24 29 public static Test suite() { 30 return new TestSuite(StandardDialFrameTests.class); 31 } 32 33 38 public StandardDialFrameTests(String name) { 39 super(name); 40 } 41 42 45 public void testEquals() { 46 StandardDialFrame f1 = new StandardDialFrame(); 47 StandardDialFrame f2 = new StandardDialFrame(); 48 assertTrue(f1.equals(f2)); 49 50 f1.setBackgroundPaint(new GradientPaint (1.0f, 2.0f, Color.red, 52 3.0f, 4.0f, Color.yellow)); 53 assertFalse(f1.equals(f2)); 54 f2.setBackgroundPaint(new GradientPaint (1.0f, 2.0f, Color.red, 55 3.0f, 4.0f, Color.yellow)); 56 assertTrue(f1.equals(f2)); 57 58 f1.setForegroundPaint(new GradientPaint (1.0f, 2.0f, Color.red, 60 3.0f, 4.0f, Color.yellow)); 61 assertFalse(f1.equals(f2)); 62 f2.setForegroundPaint(new GradientPaint (1.0f, 2.0f, Color.red, 63 3.0f, 4.0f, Color.yellow)); 64 assertTrue(f1.equals(f2)); 65 66 f1.setStroke(new BasicStroke (1.1f)); 68 assertFalse(f1.equals(f2)); 69 f2.setStroke(new BasicStroke (1.1f)); 70 assertTrue(f1.equals(f2)); 71 72 f1.setInnerRadius(0.11); 74 assertFalse(f1.equals(f2)); 75 f2.setInnerRadius(0.11); 76 assertTrue(f1.equals(f2)); 77 78 f1.setOuterRadius(0.88); 80 assertFalse(f1.equals(f2)); 81 f2.setOuterRadius(0.88); 82 assertTrue(f1.equals(f2)); 83 84 f1.setStartAngle(99); 86 assertFalse(f1.equals(f2)); 87 f2.setStartAngle(99); 88 assertTrue(f1.equals(f2)); 89 90 f1.setExtent(33); 92 assertFalse(f1.equals(f2)); 93 f2.setExtent(33); 94 assertTrue(f1.equals(f2)); 95 96 } 97 98 101 public void testHashCode() { 102 StandardDialFrame f1 = new StandardDialFrame(); 103 StandardDialFrame f2 = new StandardDialFrame(); 104 assertTrue(f1.equals(f2)); 105 int h1 = f1.hashCode(); 106 int h2 = f2.hashCode(); 107 assertEquals(h1, h2); 108 } 109 110 113 public void testCloning() { 114 StandardDialFrame f1 = new StandardDialFrame(); 115 StandardDialFrame f2 = null; 116 try { 117 f2 = (StandardDialFrame) f1.clone(); 118 } 119 catch (CloneNotSupportedException e) { 120 e.printStackTrace(); 121 } 122 assertTrue(f1 != f2); 123 assertTrue(f1.getClass() == f2.getClass()); 124 assertTrue(f1.equals(f2)); 125 } 126 127 128 131 public void testSerialization() { 132 StandardDialFrame f1 = new StandardDialFrame(); 133 StandardDialFrame f2 = null; 134 135 try { 136 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 137 ObjectOutput out = new ObjectOutputStream (buffer); 138 out.writeObject(f1); 139 out.close(); 140 141 ObjectInput in = new ObjectInputStream ( 142 new ByteArrayInputStream (buffer.toByteArray())); 143 f2 = (StandardDialFrame) in.readObject(); 144 in.close(); 145 } 146 catch (Exception e) { 147 e.printStackTrace(); 148 } 149 assertEquals(f1, f2); 150 } 151 152 } 153 | Popular Tags |