1 42 43 package org.jfree.chart.axis.junit; 44 45 import java.awt.Font ; 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.MarkerAxisBand; 58 59 62 public class MarkerAxisBandTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(MarkerAxisBandTests.class); 71 } 72 73 78 public MarkerAxisBandTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 Font font1 = new Font ("SansSerif", Font.PLAIN, 12); 87 Font font2 = new Font ("SansSerif", Font.PLAIN, 14); 88 89 MarkerAxisBand a1 = new MarkerAxisBand(null, 1.0, 1.0, 1.0, 1.0, font1); 90 MarkerAxisBand a2 = new MarkerAxisBand(null, 1.0, 1.0, 1.0, 1.0, font1); 91 assertEquals(a1, a2); 92 93 a1 = new MarkerAxisBand(null, 2.0, 1.0, 1.0, 1.0, font1); 94 assertFalse(a1.equals(a2)); 95 a2 = new MarkerAxisBand(null, 2.0, 1.0, 1.0, 1.0, font1); 96 assertTrue(a1.equals(a2)); 97 98 a1 = new MarkerAxisBand(null, 2.0, 3.0, 1.0, 1.0, font1); 99 assertFalse(a1.equals(a2)); 100 a2 = new MarkerAxisBand(null, 2.0, 3.0, 1.0, 1.0, font1); 101 assertTrue(a1.equals(a2)); 102 103 a1 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 1.0, font1); 104 assertFalse(a1.equals(a2)); 105 a2 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 1.0, font1); 106 assertTrue(a1.equals(a2)); 107 108 a1 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 5.0, font1); 109 assertFalse(a1.equals(a2)); 110 a2 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 5.0, font1); 111 assertTrue(a1.equals(a2)); 112 113 a1 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 5.0, font2); 114 assertFalse(a1.equals(a2)); 115 a2 = new MarkerAxisBand(null, 2.0, 3.0, 4.0, 5.0, font2); 116 assertTrue(a1.equals(a2)); 117 } 118 119 122 public void testHashCode() { 123 Font font1 = new Font ("SansSerif", Font.PLAIN, 12); 124 125 MarkerAxisBand a1 = new MarkerAxisBand(null, 1.0, 1.0, 1.0, 1.0, font1); 126 MarkerAxisBand a2 = new MarkerAxisBand(null, 1.0, 1.0, 1.0, 1.0, font1); 127 assertTrue(a1.equals(a2)); 128 int h1 = a1.hashCode(); 129 int h2 = a2.hashCode(); 130 assertEquals(h1, h2); 131 } 132 133 136 public void testSerialization() { 137 138 MarkerAxisBand a1 = new MarkerAxisBand(null, 1.0, 1.0, 1.0, 1.0, null); 139 MarkerAxisBand a2 = null; 140 141 try { 142 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 143 ObjectOutput out = new ObjectOutputStream (buffer); 144 out.writeObject(a1); 145 out.close(); 146 147 ObjectInput in = new ObjectInputStream ( 148 new ByteArrayInputStream (buffer.toByteArray()) 149 ); 150 a2 = (MarkerAxisBand) in.readObject(); 151 in.close(); 152 } 153 catch (Exception e) { 154 System.out.println(e.toString()); 155 } 156 assertEquals(a1, a2); 157 158 } 159 160 } 161 | Popular Tags |