1 37 38 package org.jfree.chart.junit; 39 40 import java.io.ByteArrayInputStream ; 41 import java.io.ByteArrayOutputStream ; 42 import java.io.ObjectInput ; 43 import java.io.ObjectInputStream ; 44 import java.io.ObjectOutput ; 45 import java.io.ObjectOutputStream ; 46 47 import junit.framework.Test; 48 import junit.framework.TestCase; 49 import junit.framework.TestSuite; 50 51 import org.jfree.chart.Spacer; 52 53 58 public class SpacerTests extends TestCase { 59 60 65 public static Test suite() { 66 return new TestSuite(SpacerTests.class); 67 } 68 69 74 public SpacerTests(String name) { 75 super(name); 76 } 77 78 81 public void testEquals() { 82 83 Spacer s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05); 84 Spacer s2 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05); 85 assertTrue(s1.equals(s2)); 86 87 s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05); 88 s2 = new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05); 89 assertFalse(s1.equals(s2)); 90 91 s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05); 92 s2 = new Spacer(Spacer.ABSOLUTE, 0.06, 0.05, 0.05, 0.05); 93 assertFalse(s1.equals(s2)); 94 95 s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05); 96 s2 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.06, 0.05, 0.05); 97 assertFalse(s1.equals(s2)); 98 99 s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05); 100 s2 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.06, 0.05); 101 assertFalse(s1.equals(s2)); 102 103 s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05); 104 s2 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.06); 105 assertFalse(s1.equals(s2)); 106 107 } 108 109 112 public void testSerialization() { 113 114 Spacer s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05); 115 Spacer s2 = null; 116 117 try { 118 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 119 ObjectOutput out = new ObjectOutputStream (buffer); 120 out.writeObject(s1); 121 out.close(); 122 123 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 124 s2 = (Spacer) in.readObject(); 125 in.close(); 126 } 127 catch (Exception e) { 128 System.out.println(e.toString()); 129 } 130 boolean b = s1.equals(s2); 131 assertTrue(b); 132 133 } 134 135 } 136 | Popular Tags |