1 42 43 package org.jfree.chart.plot.junit; 44 45 import java.awt.BasicStroke ; 46 import java.awt.Color ; 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectInputStream ; 51 import java.io.ObjectOutput ; 52 import java.io.ObjectOutputStream ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.chart.plot.MeterInterval; 59 import org.jfree.data.Range; 60 61 64 public class MeterIntervalTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(MeterIntervalTests.class); 73 } 74 75 80 public MeterIntervalTests(String name) { 81 super(name); 82 } 83 84 87 public void testEquals() { 88 89 MeterInterval m1 = new MeterInterval( 90 "Label 1", new Range(1.2, 3.4), Color.red, new BasicStroke (1.0f), 91 Color.blue 92 ); 93 MeterInterval m2 = new MeterInterval( 94 "Label 1", new Range(1.2, 3.4), Color.red, new BasicStroke (1.0f), 95 Color.blue 96 ); 97 assertTrue(m1.equals(m2)); 98 assertTrue(m2.equals(m1)); 99 100 m1 = new MeterInterval( 101 "Label 2", new Range(1.2, 3.4), Color.red, new BasicStroke (1.0f), 102 Color.blue 103 ); 104 assertFalse(m1.equals(m2)); 105 m2 = new MeterInterval( 106 "Label 2", new Range(1.2, 3.4), Color.red, new BasicStroke (1.0f), 107 Color.blue 108 ); 109 assertTrue(m1.equals(m2)); 110 111 } 112 113 116 public void testCloning() { 117 MeterInterval m1 = new MeterInterval("X", new Range(1.0, 2.0)); 118 assertFalse(m1 instanceof Cloneable ); 119 } 120 121 124 public void testSerialization() { 125 126 MeterInterval m1 = new MeterInterval("X", new Range(1.0, 2.0)); 127 MeterInterval m2 = null; 128 try { 129 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 130 ObjectOutput out = new ObjectOutputStream (buffer); 131 out.writeObject(m1); 132 out.close(); 133 134 ObjectInput in = new ObjectInputStream ( 135 new ByteArrayInputStream (buffer.toByteArray()) 136 ); 137 m2 = (MeterInterval) in.readObject(); 138 in.close(); 139 } 140 catch (Exception e) { 141 System.out.println(e.toString()); 142 } 143 boolean b = m1.equals(m2); 144 assertTrue(b); 145 146 } 147 148 } 149 | Popular Tags |