1 43 44 package org.jfree.chart.axis.junit; 45 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.CategoryAxis; 58 import org.jfree.chart.axis.CategoryLabelPositions; 59 60 63 public class CategoryAxisTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(CategoryAxisTests.class); 72 } 73 74 79 public CategoryAxisTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 88 CategoryAxis a1 = new CategoryAxis("Test"); 89 CategoryAxis a2 = new CategoryAxis("Test"); 90 assertTrue(a1.equals(a2)); 91 92 a1.setLowerMargin(0.15); 94 assertFalse(a1.equals(a2)); 95 a2.setLowerMargin(0.15); 96 assertTrue(a1.equals(a2)); 97 98 a1.setUpperMargin(0.15); 100 assertFalse(a1.equals(a2)); 101 a2.setUpperMargin(0.15); 102 assertTrue(a1.equals(a2)); 103 104 a1.setCategoryMargin(0.15); 106 assertFalse(a1.equals(a2)); 107 a2.setCategoryMargin(0.15); 108 assertTrue(a1.equals(a2)); 109 110 a1.setMaximumCategoryLabelWidthRatio(0.98f); 112 assertFalse(a1.equals(a2)); 113 a2.setMaximumCategoryLabelWidthRatio(0.98f); 114 assertTrue(a1.equals(a2)); 115 116 a1.setCategoryLabelPositionOffset(11); 118 assertFalse(a1.equals(a2)); 119 a2.setCategoryLabelPositionOffset(11); 120 assertTrue(a1.equals(a2)); 121 122 a1.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); 124 assertFalse(a1.equals(a2)); 125 a2.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); 126 assertTrue(a1.equals(a2)); 127 128 a1.addCategoryLabelToolTip("Test", "Check"); 130 assertFalse(a1.equals(a2)); 131 a2.addCategoryLabelToolTip("Test", "Check"); 132 assertTrue(a1.equals(a2)); 133 134 } 135 136 139 public void testHashCode() { 140 CategoryAxis a1 = new CategoryAxis("Test"); 141 CategoryAxis a2 = new CategoryAxis("Test"); 142 assertTrue(a1.equals(a2)); 143 int h1 = a1.hashCode(); 144 int h2 = a2.hashCode(); 145 assertEquals(h1, h2); 146 } 147 148 151 public void testCloning() { 152 CategoryAxis a1 = new CategoryAxis("Test"); 153 CategoryAxis a2 = null; 154 try { 155 a2 = (CategoryAxis) a1.clone(); 156 } 157 catch (CloneNotSupportedException e) { 158 System.err.println("Failed to clone."); 159 } 160 assertTrue(a1 != a2); 161 assertTrue(a1.getClass() == a2.getClass()); 162 assertTrue(a1.equals(a2)); 163 } 164 165 168 public void testSerialization() { 169 170 CategoryAxis a1 = new CategoryAxis("Test Axis"); 171 CategoryAxis a2 = null; 172 173 try { 174 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 175 ObjectOutput out = new ObjectOutputStream (buffer); 176 out.writeObject(a1); 177 out.close(); 178 179 ObjectInput in = new ObjectInputStream ( 180 new ByteArrayInputStream (buffer.toByteArray()) 181 ); 182 a2 = (CategoryAxis) in.readObject(); 183 in.close(); 184 } 185 catch (Exception e) { 186 System.out.println(e.toString()); 187 } 188 assertEquals(a1, a2); 189 190 } 191 192 } 193 | Popular Tags |