1 37 38 package org.jfree.chart.junit; 39 40 import java.awt.Color ; 41 import java.awt.Font ; 42 import java.io.ByteArrayInputStream ; 43 import java.io.ByteArrayOutputStream ; 44 import java.io.ObjectInput ; 45 import java.io.ObjectInputStream ; 46 import java.io.ObjectOutput ; 47 import java.io.ObjectOutputStream ; 48 49 import junit.framework.Test; 50 import junit.framework.TestCase; 51 import junit.framework.TestSuite; 52 53 import org.jfree.chart.Marker; 54 import org.jfree.chart.Spacer; 55 56 61 public class MarkerTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(MarkerTests.class); 70 } 71 72 77 public MarkerTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 86 Marker m1 = new Marker(45.0); 87 Marker m2 = new Marker(45.0); 88 assertTrue(m1.equals(m2)); 89 90 m1.setLabel("New Label"); 91 assertFalse(m1.equals(m2)); 92 m2.setLabel("New Label"); 93 assertTrue(m1.equals(m2)); 94 95 m1.setLabelFont(new Font ("SansSerif", Font.PLAIN, 10)); 96 assertFalse(m1.equals(m2)); 97 m2.setLabelFont(new Font ("SansSerif", Font.PLAIN, 10)); 98 assertTrue(m1.equals(m2)); 99 100 m1.setLabelPaint(Color.red); 101 assertFalse(m1.equals(m2)); 102 m2.setLabelPaint(Color.red); 103 assertTrue(m1.equals(m2)); 104 105 } 106 107 110 public void testSerialization() { 111 112 Spacer s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05); 113 Spacer s2 = null; 114 115 try { 116 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 117 ObjectOutput out = new ObjectOutputStream (buffer); 118 out.writeObject(s1); 119 out.close(); 120 121 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 122 s2 = (Spacer) in.readObject(); 123 in.close(); 124 } 125 catch (Exception e) { 126 System.out.println(e.toString()); 127 } 128 boolean b = s1.equals(s2); 129 assertTrue(b); 130 131 } 132 133 } 134 | Popular Tags |