1 42 43 package org.jfree.chart.axis.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 junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.chart.axis.ColorBar; 57 import org.jfree.chart.axis.NumberAxis; 58 import org.jfree.chart.ui.GreyPalette; 59 60 63 public class ColorBarTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(ColorBarTests.class); 72 } 73 74 79 public ColorBarTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 ColorBar c1 = new ColorBar("Test"); 88 ColorBar c2 = new ColorBar("Test"); 89 assertEquals(c1, c2); 90 91 c1.setAxis(new NumberAxis("Axis 1")); 92 assertTrue(!c1.equals(c2)); 93 c2.setAxis(new NumberAxis("Axis 1")); 94 assertTrue(c1.equals(c2)); 95 96 c1.setColorPalette(new GreyPalette()); 97 assertTrue(!c1.equals(c2)); 98 c2.setColorPalette(new GreyPalette()); 99 assertTrue(c1.equals(c2)); 100 } 101 102 105 public void testHashCode() { 106 ColorBar c1 = new ColorBar("Test"); 107 ColorBar c2 = new ColorBar("Test"); 108 assertTrue(c1.equals(c2)); 109 int h1 = c1.hashCode(); 110 int h2 = c2.hashCode(); 111 assertEquals(h1, h2); 112 } 113 114 117 public void testCloning() { 118 ColorBar c1 = new ColorBar("Test"); 119 ColorBar c2 = null; 120 try { 121 c2 = (ColorBar) c1.clone(); 122 } 123 catch (CloneNotSupportedException e) { 124 System.err.println("Failed to clone."); 125 } 126 assertTrue(c1 != c2); 127 assertTrue(c1.getClass() == c2.getClass()); 128 assertTrue(c1.equals(c2)); 129 } 130 131 134 public void testSerialization() { 135 136 ColorBar a1 = new ColorBar("Test Axis"); 137 ColorBar a2 = null; 138 139 try { 140 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 141 ObjectOutput out = new ObjectOutputStream (buffer); 142 out.writeObject(a1); 143 out.close(); 144 145 ObjectInput in = new ObjectInputStream ( 146 new ByteArrayInputStream (buffer.toByteArray()) 147 ); 148 a2 = (ColorBar) in.readObject(); 149 in.close(); 150 } 151 catch (Exception e) { 152 System.out.println(e.toString()); 153 } 154 assertEquals(a1, a2); 155 156 } 157 158 } 159 | Popular Tags |