1 43 44 package org.jfree.data.xy.junit; 45 46 import java.io.ByteArrayInputStream ; 47 import java.io.ByteArrayOutputStream ; 48 import java.io.ObjectInput ; 49 import java.io.ObjectInputStream ; 50 import java.io.ObjectOutput ; 51 import java.io.ObjectOutputStream ; 52 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.data.xy.IntervalXYDelegate; 58 import org.jfree.data.xy.XYSeries; 59 import org.jfree.data.xy.XYSeriesCollection; 60 61 64 public class IntervalXYDelegateTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(IntervalXYDelegateTests.class); 73 } 74 75 80 public IntervalXYDelegateTests(String name) { 81 super(name); 82 } 83 84 87 public void testEquals() { 88 XYSeries s1 = new XYSeries("Series"); 89 s1.add(1.2, 3.4); 90 XYSeriesCollection c1 = new XYSeriesCollection(); 91 c1.addSeries(s1); 92 IntervalXYDelegate d1 = new IntervalXYDelegate(c1); 93 94 XYSeries s2 = new XYSeries("Series"); 95 XYSeriesCollection c2 = new XYSeriesCollection(); 96 s2.add(1.2, 3.4); 97 c2.addSeries(s2); 98 IntervalXYDelegate d2 = new IntervalXYDelegate(c2); 99 100 assertTrue(d1.equals(d2)); 101 assertTrue(d2.equals(d1)); 102 103 d1.setAutoWidth(false); 104 assertFalse(d1.equals(d2)); 105 d2.setAutoWidth(false); 106 assertTrue(d1.equals(d2)); 107 108 d1.setIntervalPositionFactor(0.123); 109 assertFalse(d1.equals(d2)); 110 d2.setIntervalPositionFactor(0.123); 111 assertTrue(d1.equals(d2)); 112 113 d1.setFixedIntervalWidth(1.23); 114 assertFalse(d1.equals(d2)); 115 d2.setFixedIntervalWidth(1.23); 116 assertTrue(d1.equals(d2)); 117 } 118 119 122 public void testCloning() { 123 XYSeries s1 = new XYSeries("Series"); 124 s1.add(1.2, 3.4); 125 XYSeriesCollection c1 = new XYSeriesCollection(); 126 c1.addSeries(s1); 127 IntervalXYDelegate d1 = new IntervalXYDelegate(c1); 128 129 IntervalXYDelegate d2 = null; 130 try { 131 d2 = (IntervalXYDelegate) d1.clone(); 132 } 133 catch (CloneNotSupportedException e) { 134 System.err.println("Failed to clone."); 135 } 136 assertTrue(d1 != d2); 137 assertTrue(d1.getClass() == d2.getClass()); 138 assertTrue(d1.equals(d2)); 139 } 140 141 144 public void testSerialization() { 145 XYSeries s1 = new XYSeries("Series"); 146 s1.add(1.2, 3.4); 147 XYSeriesCollection c1 = new XYSeriesCollection(); 148 c1.addSeries(s1); 149 IntervalXYDelegate d1 = new IntervalXYDelegate(c1); 150 IntervalXYDelegate d2 = null; 151 try { 152 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 153 ObjectOutput out = new ObjectOutputStream (buffer); 154 out.writeObject(d1); 155 out.close(); 156 157 ObjectInput in = new ObjectInputStream ( 158 new ByteArrayInputStream (buffer.toByteArray()) 159 ); 160 d2 = (IntervalXYDelegate) in.readObject(); 161 in.close(); 162 } 163 catch (Exception e) { 164 System.out.println(e.toString()); 165 } 166 assertEquals(d1, d2); 167 168 } 169 170 } 171 | Popular Tags |