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.CategoryLabelPosition; 58 import org.jfree.chart.axis.CategoryLabelWidthType; 59 import org.jfree.text.TextBlockAnchor; 60 import org.jfree.ui.RectangleAnchor; 61 import org.jfree.ui.TextAnchor; 62 63 66 public class CategoryLabelPositionTests extends TestCase { 67 68 73 public static Test suite() { 74 return new TestSuite(CategoryLabelPositionTests.class); 75 } 76 77 82 public CategoryLabelPositionTests(String name) { 83 super(name); 84 } 85 86 89 public void testEquals() { 90 CategoryLabelPosition p1 = new CategoryLabelPosition( 91 RectangleAnchor.BOTTOM_LEFT, TextBlockAnchor.CENTER_RIGHT, 92 TextAnchor.BASELINE_LEFT, Math.PI / 4.0, 93 CategoryLabelWidthType.RANGE, 0.44f 94 ); 95 CategoryLabelPosition p2 = new CategoryLabelPosition( 96 RectangleAnchor.BOTTOM_LEFT, TextBlockAnchor.CENTER_RIGHT, 97 TextAnchor.BASELINE_LEFT, Math.PI / 4.0, 98 CategoryLabelWidthType.RANGE, 0.44f 99 ); 100 assertTrue(p1.equals(p2)); 101 assertTrue(p2.equals(p1)); 102 103 p1 = new CategoryLabelPosition( 104 RectangleAnchor.TOP, TextBlockAnchor.CENTER_RIGHT, 105 TextAnchor.BASELINE_LEFT, Math.PI / 4.0, 106 CategoryLabelWidthType.RANGE, 0.44f 107 ); 108 assertFalse(p1.equals(p2)); 109 p2 = new CategoryLabelPosition( 110 RectangleAnchor.TOP, TextBlockAnchor.CENTER_RIGHT, 111 TextAnchor.BASELINE_LEFT, Math.PI / 4.0, 112 CategoryLabelWidthType.RANGE, 0.44f 113 ); 114 assertTrue(p1.equals(p2)); 115 116 p1 = new CategoryLabelPosition(RectangleAnchor.TOP, 117 TextBlockAnchor.CENTER, TextAnchor.BASELINE_LEFT, Math.PI / 4.0, 118 CategoryLabelWidthType.RANGE, 0.44f 119 ); 120 assertFalse(p1.equals(p2)); 121 p2 = new CategoryLabelPosition(RectangleAnchor.TOP, 122 TextBlockAnchor.CENTER, TextAnchor.BASELINE_LEFT, Math.PI / 4.0, 123 CategoryLabelWidthType.RANGE, 0.44f 124 ); 125 assertTrue(p1.equals(p2)); 126 127 p1 = new CategoryLabelPosition(RectangleAnchor.TOP, 128 TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 4.0, 129 CategoryLabelWidthType.RANGE, 0.44f 130 ); 131 assertFalse(p1.equals(p2)); 132 p2 = new CategoryLabelPosition(RectangleAnchor.TOP, 133 TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 4.0, 134 CategoryLabelWidthType.RANGE, 0.44f 135 ); 136 assertTrue(p1.equals(p2)); 137 138 p1 = new CategoryLabelPosition( 139 RectangleAnchor.TOP, TextBlockAnchor.CENTER, TextAnchor.CENTER, 140 Math.PI / 6.0, CategoryLabelWidthType.RANGE, 0.44f 141 ); 142 assertFalse(p1.equals(p2)); 143 p2 = new CategoryLabelPosition( 144 RectangleAnchor.TOP, TextBlockAnchor.CENTER, TextAnchor.CENTER, 145 Math.PI / 6.0, CategoryLabelWidthType.RANGE, 0.44f 146 ); 147 assertTrue(p1.equals(p2)); 148 149 p1 = new CategoryLabelPosition( 150 RectangleAnchor.TOP, TextBlockAnchor.CENTER, TextAnchor.CENTER, 151 Math.PI / 6.0, CategoryLabelWidthType.CATEGORY, 0.44f 152 ); 153 assertFalse(p1.equals(p2)); 154 p2 = new CategoryLabelPosition( 155 RectangleAnchor.TOP, TextBlockAnchor.CENTER, TextAnchor.CENTER, 156 Math.PI / 6.0, CategoryLabelWidthType.CATEGORY, 0.44f 157 ); 158 assertTrue(p1.equals(p2)); 159 160 p1 = new CategoryLabelPosition( 161 RectangleAnchor.TOP, TextBlockAnchor.CENTER, TextAnchor.CENTER, 162 Math.PI / 6.0, CategoryLabelWidthType.CATEGORY, 0.55f 163 ); 164 assertFalse(p1.equals(p2)); 165 p2 = new CategoryLabelPosition( 166 RectangleAnchor.TOP, TextBlockAnchor.CENTER, TextAnchor.CENTER, 167 Math.PI / 6.0, CategoryLabelWidthType.CATEGORY, 0.55f 168 ); 169 assertTrue(p1.equals(p2)); 170 } 171 172 175 public void testHashCode() { 176 CategoryLabelPosition a1 = new CategoryLabelPosition(); 177 CategoryLabelPosition a2 = new CategoryLabelPosition(); 178 assertTrue(a1.equals(a2)); 179 int h1 = a1.hashCode(); 180 int h2 = a2.hashCode(); 181 assertEquals(h1, h2); 182 } 183 184 187 public void testSerialization() { 188 189 CategoryLabelPosition p1 = new CategoryLabelPosition(); 190 CategoryLabelPosition p2 = null; 191 192 try { 193 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 194 ObjectOutput out = new ObjectOutputStream (buffer); 195 out.writeObject(p1); 196 out.close(); 197 198 ObjectInput in = new ObjectInputStream ( 199 new ByteArrayInputStream (buffer.toByteArray()) 200 ); 201 p2 = (CategoryLabelPosition) in.readObject(); 202 in.close(); 203 } 204 catch (Exception e) { 205 System.out.println(e.toString()); 206 } 207 assertEquals(p1, p2); 208 } 209 210 } 211 | Popular Tags |