1 43 44 package org.jfree.chart.axis.junit; 45 46 import java.awt.BasicStroke ; 47 import java.awt.Color ; 48 import java.awt.Stroke ; 49 import java.io.ByteArrayInputStream ; 50 import java.io.ByteArrayOutputStream ; 51 import java.io.ObjectInput ; 52 import java.io.ObjectInputStream ; 53 import java.io.ObjectOutput ; 54 import java.io.ObjectOutputStream ; 55 56 import junit.framework.Test; 57 import junit.framework.TestCase; 58 import junit.framework.TestSuite; 59 60 import org.jfree.chart.axis.CyclicNumberAxis; 61 62 67 public class CyclicNumberAxisTests extends TestCase { 68 69 74 public static Test suite() { 75 return new TestSuite(CyclicNumberAxisTests.class); 76 } 77 78 83 public CyclicNumberAxisTests(String name) { 84 super(name); 85 } 86 87 90 public void testCloning() { 91 CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test"); 92 CyclicNumberAxis a2 = null; 93 try { 94 a2 = (CyclicNumberAxis) a1.clone(); 95 } 96 catch (CloneNotSupportedException e) { 97 System.err.println("Failed to clone."); 98 } 99 assertTrue(a1 != a2); 100 assertTrue(a1.getClass() == a2.getClass()); 101 assertTrue(a1.equals(a2)); 102 } 103 104 107 public void testEquals() { 108 109 CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test"); 110 CyclicNumberAxis a2 = new CyclicNumberAxis(10, 0, "Test"); 111 assertTrue(a1.equals(a2)); 112 113 a1.setPeriod(5); 115 assertFalse(a1.equals(a2)); 116 a2.setPeriod(5); 117 assertTrue(a1.equals(a2)); 118 119 a1.setOffset(2.0); 121 assertFalse(a1.equals(a2)); 122 a2.setOffset(2.0); 123 assertTrue(a1.equals(a2)); 124 125 a1.setAdvanceLinePaint(Color.cyan); 127 assertFalse(a1.equals(a2)); 128 a2.setAdvanceLinePaint(Color.cyan); 129 assertTrue(a1.equals(a2)); 130 131 Stroke stroke = new BasicStroke (0.2f); 133 a1.setAdvanceLineStroke(stroke); 134 assertFalse(a1.equals(a2)); 135 a2.setAdvanceLineStroke(stroke); 136 assertTrue(a1.equals(a2)); 137 138 a1.setAdvanceLineVisible(!a1.isAdvanceLineVisible()); 140 assertFalse(a1.equals(a2)); 141 a2.setAdvanceLineVisible(a1.isAdvanceLineVisible()); 142 assertTrue(a1.equals(a2)); 143 144 a1.setBoundMappedToLastCycle(!a1.isBoundMappedToLastCycle()); 146 assertFalse(a1.equals(a2)); 147 a2.setBoundMappedToLastCycle(a1.isBoundMappedToLastCycle()); 148 assertTrue(a1.equals(a2)); 149 150 } 151 152 155 public void testHashCode() { 156 CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test"); 157 CyclicNumberAxis a2 = new CyclicNumberAxis(10, 0, "Test"); 158 assertTrue(a1.equals(a2)); 159 int h1 = a1.hashCode(); 160 int h2 = a2.hashCode(); 161 assertEquals(h1, h2); 162 } 163 164 167 public void testSerialization() { 168 169 CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test Axis"); 170 CyclicNumberAxis a2 = null; 171 172 try { 173 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 174 ObjectOutput out = new ObjectOutputStream (buffer); 175 out.writeObject(a1); 176 out.close(); 177 178 ObjectInput in = new ObjectInputStream ( 179 new ByteArrayInputStream (buffer.toByteArray()) 180 ); 181 a2 = (CyclicNumberAxis) in.readObject(); 182 in.close(); 183 } 184 catch (Exception e) { 185 System.out.println(e.toString()); 186 } 187 assertEquals(a1, a2); 188 189 } 190 191 } 192 193 | Popular Tags |