1 42 43 package org.jfree.chart.axis.junit; 44 45 import java.awt.Color ; 46 import java.io.ByteArrayInputStream ; 47 import java.io.ByteArrayOutputStream ; 48 import java.io.ObjectInput ; 49 import java.io.ObjectInputStream ; 50 import java.io.ObjectOutput ; 51 import java.io.ObjectOutputStream ; 52 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.chart.axis.SymbolAxis; 58 59 62 public class SymbolAxisTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(SymbolAxisTests.class); 71 } 72 73 78 public SymbolAxisTests(String name) { 79 super(name); 80 } 81 82 85 public void testSerialization() { 86 87 String [] tickLabels = new String [] {"One", "Two", "Three"}; 88 SymbolAxis a1 = new SymbolAxis("Test Axis", tickLabels); 89 SymbolAxis a2 = null; 90 91 try { 92 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 93 ObjectOutput out = new ObjectOutputStream (buffer); 94 out.writeObject(a1); 95 out.close(); 96 97 ObjectInput in = new ObjectInputStream ( 98 new ByteArrayInputStream (buffer.toByteArray()) 99 ); 100 a2 = (SymbolAxis) in.readObject(); 101 in.close(); 102 } 103 catch (Exception e) { 104 System.out.println(e.toString()); 105 } 106 assertEquals(a1, a2); 107 108 } 109 110 113 public void testCloning() { 114 SymbolAxis a1 = new SymbolAxis("Axis", new String [] {"A", "B"}); 115 SymbolAxis a2 = null; 116 try { 117 a2 = (SymbolAxis) a1.clone(); 118 } 119 catch (CloneNotSupportedException e) { 120 e.printStackTrace(); 121 } 122 assertTrue(a1 != a2); 123 assertTrue(a1.getClass() == a2.getClass()); 124 assertTrue(a1.equals(a2)); 125 } 126 127 130 public void testEquals() { 131 SymbolAxis a1 = new SymbolAxis("Axis", new String [] {"A", "B"}); 132 SymbolAxis a2 = new SymbolAxis("Axis", new String [] {"A", "B"}); 133 assertTrue(a1.equals(a2)); 134 assertTrue(a2.equals(a1)); 135 136 a1 = new SymbolAxis("Axis 2", new String [] {"A", "B"}); 137 assertFalse(a1.equals(a2)); 138 a2 = new SymbolAxis("Axis 2", new String [] {"A", "B"}); 139 assertTrue(a1.equals(a2)); 140 141 a1 = new SymbolAxis("Axis 2", new String [] {"C", "B"}); 142 assertFalse(a1.equals(a2)); 143 a2 = new SymbolAxis("Axis 2", new String [] {"C", "B"}); 144 assertTrue(a1.equals(a2)); 145 146 a1.setGridBandPaint(Color.black); 147 assertFalse(a1.equals(a2)); 148 a2.setGridBandPaint(Color.black); 149 assertTrue(a1.equals(a2)); 150 151 a1.setGridBandsVisible(false); 152 assertFalse(a1.equals(a2)); 153 a2.setGridBandsVisible(false); 154 assertTrue(a1.equals(a2)); 155 } 156 157 } 158 | Popular Tags |