1 42 43 package org.jfree.util.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.util.UnitType; 57 58 61 public class UnitTypeTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(UnitTypeTests.class); 70 } 71 72 77 public UnitTypeTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 assertTrue(UnitType.ABSOLUTE.equals(UnitType.ABSOLUTE)); 86 assertTrue(UnitType.RELATIVE.equals(UnitType.RELATIVE)); 87 assertFalse(UnitType.ABSOLUTE.equals(UnitType.RELATIVE)); 88 assertFalse(UnitType.RELATIVE.equals(UnitType.ABSOLUTE)); 89 assertFalse(UnitType.ABSOLUTE.equals(null)); 90 assertFalse(UnitType.RELATIVE.equals(null)); 91 } 92 93 96 public void testSerialization() { 97 98 UnitType t1 = UnitType.ABSOLUTE; 99 UnitType t2 = null; 100 101 try { 102 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 103 ObjectOutput out = new ObjectOutputStream (buffer); 104 out.writeObject(t1); 105 out.close(); 106 107 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 108 t2 = (UnitType) in.readObject(); 109 in.close(); 110 } 111 catch (Exception e) { 112 System.out.println(e.toString()); 113 } 114 assertTrue(t1 == t2); 115 116 } 117 118 } 119 | Popular Tags |