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.CategoryAnchor; 58 59 62 public class CategoryAnchorTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(CategoryAnchorTests.class); 71 } 72 73 78 public CategoryAnchorTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 assertEquals(CategoryAnchor.START, CategoryAnchor.START); 87 assertEquals(CategoryAnchor.MIDDLE, CategoryAnchor.MIDDLE); 88 assertEquals(CategoryAnchor.END, CategoryAnchor.END); 89 assertFalse(CategoryAnchor.START.equals(CategoryAnchor.END)); 90 assertFalse(CategoryAnchor.MIDDLE.equals(CategoryAnchor.END)); 91 } 92 93 96 public void testHashCode() { 97 CategoryAnchor a1 = CategoryAnchor.START; 98 CategoryAnchor a2 = CategoryAnchor.START; 99 assertTrue(a1.equals(a2)); 100 int h1 = a1.hashCode(); 101 int h2 = a2.hashCode(); 102 assertEquals(h1, h2); 103 } 104 105 108 public void testSerialization() { 109 CategoryAnchor a1 = CategoryAnchor.MIDDLE; 110 CategoryAnchor a2 = null; 111 112 try { 113 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 114 ObjectOutput out = new ObjectOutputStream (buffer); 115 out.writeObject(a1); 116 out.close(); 117 118 ObjectInput in = new ObjectInputStream ( 119 new ByteArrayInputStream (buffer.toByteArray()) 120 ); 121 a2 = (CategoryAnchor) in.readObject(); 122 in.close(); 123 } 124 catch (Exception e) { 125 System.out.println(e.toString()); 126 } 127 assertEquals(a1, a2); 128 assertTrue(a1 == a2); 129 } 130 131 } 132 | Popular Tags |