1 42 43 package org.jfree.experimental.chart.renderer.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 52 import org.jfree.experimental.chart.renderer.GrayPaintScale; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 59 62 public class GrayPaintScaleTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(GrayPaintScaleTests.class); 71 } 72 73 78 public GrayPaintScaleTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 GrayPaintScale g1 = new GrayPaintScale(); 87 GrayPaintScale g2 = new GrayPaintScale(); 88 assertTrue(g1.equals(g2)); 89 assertTrue(g2.equals(g1)); 90 91 g1 = new GrayPaintScale(0.0, 1.0); 92 g2 = new GrayPaintScale(0.0, 1.0); 93 assertTrue(g1.equals(g2)); 94 g1 = new GrayPaintScale(0.1, 1.0); 95 assertFalse(g1.equals(g2)); 96 g2 = new GrayPaintScale(0.1, 1.0); 97 assertTrue(g1.equals(g2)); 98 99 g1 = new GrayPaintScale(0.1, 0.9); 100 assertFalse(g1.equals(g2)); 101 g2 = new GrayPaintScale(0.1, 0.9); 102 assertTrue(g1.equals(g2)); 103 } 104 105 108 public void testCloning() { 109 GrayPaintScale g1 = new GrayPaintScale(); 110 GrayPaintScale g2 = null; 111 try { 112 g2 = (GrayPaintScale) g1.clone(); 113 } 114 catch (CloneNotSupportedException e) { 115 e.printStackTrace(); 116 } 117 assertTrue(g1 != g2); 118 assertTrue(g1.getClass() == g2.getClass()); 119 assertTrue(g1.equals(g2)); 120 } 121 122 125 public void testSerialization() { 126 GrayPaintScale g1 = new GrayPaintScale(); 127 GrayPaintScale g2 = null; 128 try { 129 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 130 ObjectOutput out = new ObjectOutputStream (buffer); 131 out.writeObject(g1); 132 out.close(); 133 134 ObjectInput in = new ObjectInputStream ( 135 new ByteArrayInputStream (buffer.toByteArray())); 136 g2 = (GrayPaintScale) in.readObject(); 137 in.close(); 138 } 139 catch (Exception e) { 140 e.printStackTrace(); 141 } 142 assertEquals(g1, g2); 143 } 144 145 } 146 | Popular Tags |