1 42 43 package org.jfree.data.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.data.RangeType; 57 58 61 public class RangeTypeTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(RangeTypeTests.class); 70 } 71 72 77 public RangeTypeTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 assertEquals(RangeType.FULL, RangeType.FULL); 86 assertEquals(RangeType.NEGATIVE, RangeType.NEGATIVE); 87 assertEquals(RangeType.POSITIVE, RangeType.POSITIVE); 88 assertFalse(RangeType.FULL.equals(RangeType.NEGATIVE)); 89 assertFalse(RangeType.FULL.equals(RangeType.POSITIVE)); 90 assertFalse(RangeType.FULL.equals(null)); 91 assertFalse(RangeType.NEGATIVE.equals(RangeType.FULL)); 92 assertFalse(RangeType.NEGATIVE.equals(RangeType.POSITIVE)); 93 assertFalse(RangeType.NEGATIVE.equals(null)); 94 assertFalse(RangeType.POSITIVE.equals(RangeType.NEGATIVE)); 95 assertFalse(RangeType.POSITIVE.equals(RangeType.FULL)); 96 assertFalse(RangeType.POSITIVE.equals(null)); 97 } 98 99 102 public void testHashCode() { 103 RangeType r1 = RangeType.FULL; 104 RangeType r2 = RangeType.FULL; 105 assertTrue(r1.equals(r2)); 106 int h1 = r1.hashCode(); 107 int h2 = r2.hashCode(); 108 assertEquals(h1, h2); 109 } 110 111 114 public void testSerialization() { 115 RangeType r1 = RangeType.FULL; 116 RangeType r2 = null; 117 try { 118 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 119 ObjectOutput out = new ObjectOutputStream (buffer); 120 out.writeObject(r1); 121 out.close(); 122 123 ObjectInput in = new ObjectInputStream ( 124 new ByteArrayInputStream (buffer.toByteArray()) 125 ); 126 r2 = (RangeType) in.readObject(); 127 in.close(); 128 } 129 catch (Exception e) { 130 System.out.println(e.toString()); 131 } 132 assertEquals(r1, r2); 133 boolean same = r1 == r2; 134 assertEquals(true, same); 135 } 136 137 } 138 | Popular Tags |