1 42 43 package org.jfree.chart.axis.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.chart.axis.AxisLocation; 57 58 61 public class AxisLocationTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(AxisLocationTests.class); 70 } 71 72 77 public AxisLocationTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 assertEquals(AxisLocation.TOP_OR_RIGHT, AxisLocation.TOP_OR_RIGHT); 86 assertEquals( 87 AxisLocation.BOTTOM_OR_RIGHT, AxisLocation.BOTTOM_OR_RIGHT 88 ); 89 assertEquals(AxisLocation.TOP_OR_LEFT, AxisLocation.TOP_OR_LEFT); 90 assertEquals(AxisLocation.BOTTOM_OR_LEFT, AxisLocation.BOTTOM_OR_LEFT); 91 } 92 93 96 public void testHashCode() { 97 AxisLocation a1 = AxisLocation.TOP_OR_RIGHT; 98 AxisLocation a2 = AxisLocation.TOP_OR_RIGHT; 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 AxisLocation location1 = AxisLocation.BOTTOM_OR_RIGHT; 110 AxisLocation location2 = null; 111 try { 112 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 113 ObjectOutput out = new ObjectOutputStream (buffer); 114 out.writeObject(location1); 115 out.close(); 116 117 ObjectInput in = new ObjectInputStream ( 118 new ByteArrayInputStream (buffer.toByteArray()) 119 ); 120 location2 = (AxisLocation) in.readObject(); 121 in.close(); 122 } 123 catch (Exception e) { 124 System.out.println(e.toString()); 125 } 126 assertEquals(location1, location2); 127 boolean same = location1 == location2; 128 assertEquals(true, same); 129 } 130 131 } 132 | Popular Tags |