1 42 43 package org.jfree.chart.axis.junit; 44 45 import java.awt.BasicStroke ; 46 import java.awt.Color ; 47 import java.awt.Font ; 48 49 import junit.framework.Test; 50 import junit.framework.TestCase; 51 import junit.framework.TestSuite; 52 53 import org.jfree.chart.axis.Axis; 54 import org.jfree.chart.axis.CategoryAxis; 55 import org.jfree.ui.RectangleInsets; 56 57 60 public class AxisTests extends TestCase { 61 62 67 public static Test suite() { 68 return new TestSuite(AxisTests.class); 69 } 70 71 76 public AxisTests(String name) { 77 super(name); 78 } 79 80 83 public void testCloning() { 84 CategoryAxis a1 = new CategoryAxis("Test"); 85 a1.setAxisLinePaint(Color.red); 86 CategoryAxis a2 = null; 87 try { 88 a2 = (CategoryAxis) a1.clone(); 89 } 90 catch (CloneNotSupportedException e) { 91 System.err.println("Failed to clone."); 92 } 93 assertTrue(a1 != a2); 94 assertTrue(a1.getClass() == a2.getClass()); 95 assertTrue(a1.equals(a2)); 96 } 97 98 101 public void testEquals() { 102 103 Axis a1 = new CategoryAxis("Test"); 104 Axis a2 = new CategoryAxis("Test"); 105 assertTrue(a1.equals(a2)); 106 107 a1.setVisible(false); 109 assertFalse(a1.equals(a2)); 110 a2.setVisible(false); 111 assertTrue(a1.equals(a2)); 112 113 a1.setLabel("New Label"); 115 assertFalse(a1.equals(a2)); 116 a2.setLabel("New Label"); 117 assertTrue(a1.equals(a2)); 118 119 a1.setLabelFont(new Font ("Dialog", Font.PLAIN, 8)); 121 assertFalse(a1.equals(a2)); 122 a2.setLabelFont(new Font ("Dialog", Font.PLAIN, 8)); 123 assertTrue(a1.equals(a2)); 124 125 a1.setLabelPaint(Color.blue); 127 assertFalse(a1.equals(a2)); 128 a2.setLabelPaint(Color.blue); 129 assertTrue(a1.equals(a2)); 130 131 a1.setLabelInsets(new RectangleInsets(10.0, 10.0, 10.0, 10.0)); 133 assertFalse(a1.equals(a2)); 134 a2.setLabelInsets(new RectangleInsets(10.0, 10.0, 10.0, 10.0)); 135 assertTrue(a1.equals(a2)); 136 137 a1.setLabelAngle(1.23); 139 assertFalse(a1.equals(a2)); 140 a2.setLabelAngle(1.23); 141 assertTrue(a1.equals(a2)); 142 143 a1.setAxisLineVisible(false); 145 assertFalse(a1.equals(a2)); 146 a2.setAxisLineVisible(false); 147 assertTrue(a1.equals(a2)); 148 149 BasicStroke s = new BasicStroke (1.1f); 151 a1.setAxisLineStroke(s); 152 assertFalse(a1.equals(a2)); 153 a2.setAxisLineStroke(s); 154 assertTrue(a1.equals(a2)); 155 156 a1.setAxisLinePaint(Color.blue); 158 assertFalse(a1.equals(a2)); 159 a2.setAxisLinePaint(Color.blue); 160 assertTrue(a1.equals(a2)); 161 162 a1.setTickLabelsVisible(false); 164 assertFalse(a1.equals(a2)); 165 a2.setTickLabelsVisible(false); 166 assertTrue(a1.equals(a2)); 167 168 a1.setTickLabelFont(new Font ("Dialog", Font.PLAIN, 12)); 170 assertFalse(a1.equals(a2)); 171 a2.setTickLabelFont(new Font ("Dialog", Font.PLAIN, 12)); 172 assertTrue(a1.equals(a2)); 173 174 a1.setTickLabelPaint(Color.red); 176 assertFalse(a1.equals(a2)); 177 a2.setTickLabelPaint(Color.red); 178 assertTrue(a1.equals(a2)); 179 180 a1.setTickLabelInsets(new RectangleInsets(10.0, 10.0, 10.0, 10.0)); 182 assertFalse(a1.equals(a2)); 183 a2.setTickLabelInsets(new RectangleInsets(10.0, 10.0, 10.0, 10.0)); 184 assertTrue(a1.equals(a2)); 185 186 a1.setTickMarksVisible(true); 188 assertFalse(a1.equals(a2)); 189 a2.setTickMarksVisible(true); 190 assertTrue(a1.equals(a2)); 191 192 a1.setTickMarkInsideLength(1.23f); 194 assertFalse(a1.equals(a2)); 195 a2.setTickMarkInsideLength(1.23f); 196 assertTrue(a1.equals(a2)); 197 198 a1.setTickMarkOutsideLength(1.23f); 200 assertFalse(a1.equals(a2)); 201 a2.setTickMarkOutsideLength(1.23f); 202 assertTrue(a1.equals(a2)); 203 204 a1.setTickMarkStroke(new BasicStroke (2.0f)); 206 assertFalse(a1.equals(a2)); 207 a2.setTickMarkStroke(new BasicStroke (2.0f)); 208 assertTrue(a1.equals(a2)); 209 210 a1.setTickMarkPaint(Color.green); 212 assertFalse(a1.equals(a2)); 213 a2.setTickMarkPaint(Color.green); 214 assertTrue(a1.equals(a2)); 215 216 a1.setFixedDimension(3.21f); 218 assertFalse(a1.equals(a2)); 219 a2.setFixedDimension(3.21f); 220 assertTrue(a1.equals(a2)); 221 222 } 223 224 227 public void testHashCode() { 228 Axis a1 = new CategoryAxis("Test"); 229 Axis a2 = new CategoryAxis("Test"); 230 assertTrue(a1.equals(a2)); 231 int h1 = a1.hashCode(); 232 int h2 = a2.hashCode(); 233 assertEquals(h1, h2); 234 } 235 236 } 237 | Popular Tags |