1 43 44 package org.jfree.chart.axis.junit; 45 46 import java.awt.Color ; 47 import java.awt.Font ; 48 import java.io.ByteArrayInputStream ; 49 import java.io.ByteArrayOutputStream ; 50 import java.io.ObjectInput ; 51 import java.io.ObjectInputStream ; 52 import java.io.ObjectOutput ; 53 import java.io.ObjectOutputStream ; 54 55 import junit.framework.Test; 56 import junit.framework.TestCase; 57 import junit.framework.TestSuite; 58 59 import org.jfree.chart.axis.SubCategoryAxis; 60 61 64 public class SubCategoryAxisTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(CategoryAxisTests.class); 73 } 74 75 80 public SubCategoryAxisTests(String name) { 81 super(name); 82 } 83 84 87 public void testEquals() { 88 89 SubCategoryAxis a1 = new SubCategoryAxis("Test"); 90 SubCategoryAxis a2 = new SubCategoryAxis("Test"); 91 assertTrue(a1.equals(a2)); 92 assertTrue(a2.equals(a1)); 93 94 a1.addSubCategory("Sub 1"); 96 assertFalse(a1.equals(a2)); 97 a2.addSubCategory("Sub 1"); 98 assertTrue(a1.equals(a2)); 99 100 a1.setSubLabelFont(new Font ("Serif", Font.BOLD, 15)); 102 assertFalse(a1.equals(a2)); 103 a2.setSubLabelFont(new Font ("Serif", Font.BOLD, 15)); 104 assertTrue(a1.equals(a2)); 105 106 a1.setSubLabelPaint(Color.red); 108 assertFalse(a1.equals(a2)); 109 a2.setSubLabelPaint(Color.red); 110 assertTrue(a1.equals(a2)); 111 112 } 113 114 117 public void testHashCode() { 118 SubCategoryAxis a1 = new SubCategoryAxis("Test"); 119 SubCategoryAxis a2 = new SubCategoryAxis("Test"); 120 assertTrue(a1.equals(a2)); 121 int h1 = a1.hashCode(); 122 int h2 = a2.hashCode(); 123 assertEquals(h1, h2); 124 } 125 126 129 public void testCloning() { 130 SubCategoryAxis a1 = new SubCategoryAxis("Test"); 131 SubCategoryAxis a2 = null; 132 try { 133 a2 = (SubCategoryAxis) a1.clone(); 134 } 135 catch (CloneNotSupportedException e) { 136 System.err.println("Failed to clone."); 137 } 138 assertTrue(a1 != a2); 139 assertTrue(a1.getClass() == a2.getClass()); 140 assertTrue(a1.equals(a2)); 141 } 142 143 146 public void testSerialization() { 147 148 SubCategoryAxis a1 = new SubCategoryAxis("Test Axis"); 149 SubCategoryAxis a2 = null; 150 151 try { 152 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 153 ObjectOutput out = new ObjectOutputStream (buffer); 154 out.writeObject(a1); 155 out.close(); 156 157 ObjectInput in = new ObjectInputStream ( 158 new ByteArrayInputStream (buffer.toByteArray()) 159 ); 160 a2 = (SubCategoryAxis) in.readObject(); 161 in.close(); 162 } 163 catch (Exception e) { 164 System.out.println(e.toString()); 165 } 166 assertEquals(a1, a2); 167 168 } 169 170 } 171 | Popular Tags |