1 42 43 package org.jfree.data.xy.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.data.xy.XIntervalSeries; 57 import org.jfree.data.xy.XIntervalSeriesCollection; 58 59 62 public class XIntervalSeriesCollectionTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(XIntervalSeriesCollectionTests.class); 71 } 72 73 78 public XIntervalSeriesCollectionTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 XIntervalSeriesCollection c1 = new XIntervalSeriesCollection(); 87 XIntervalSeriesCollection c2 = new XIntervalSeriesCollection(); 88 assertEquals(c1, c2); 89 90 XIntervalSeries s1 = new XIntervalSeries("Series"); 92 s1.add(1.0, 1.1, 1.2, 1.3); 93 c1.addSeries(s1); 94 assertFalse(c1.equals(c2)); 95 XIntervalSeries s2 = new XIntervalSeries("Series"); 96 s2.add(1.0, 1.1, 1.2, 1.3); 97 c2.addSeries(s2); 98 assertTrue(c1.equals(c2)); 99 100 c1.addSeries(new XIntervalSeries("Empty Series")); 102 assertFalse(c1.equals(c2)); 103 c2.addSeries(new XIntervalSeries("Empty Series")); 104 assertTrue(c1.equals(c2)); 105 } 106 107 110 public void testCloning() { 111 XIntervalSeriesCollection c1 = new XIntervalSeriesCollection(); 112 XIntervalSeries s1 = new XIntervalSeries("Series"); 113 s1.add(1.0, 1.1, 1.2, 1.3); 114 XIntervalSeriesCollection c2 = null; 115 try { 116 c2 = (XIntervalSeriesCollection) c1.clone(); 117 } 118 catch (CloneNotSupportedException e) { 119 e.printStackTrace(); 120 } 121 assertTrue(c1 != c2); 122 assertTrue(c1.getClass() == c2.getClass()); 123 assertTrue(c1.equals(c2)); 124 } 125 126 129 public void testSerialization() { 130 XIntervalSeriesCollection c1 = new XIntervalSeriesCollection(); 131 XIntervalSeries s1 = new XIntervalSeries("Series"); 132 s1.add(1.0, 1.1, 1.2, 1.3); 133 XIntervalSeriesCollection c2 = null; 134 135 try { 136 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 137 ObjectOutput out = new ObjectOutputStream (buffer); 138 out.writeObject(c1); 139 out.close(); 140 141 ObjectInput in = new ObjectInputStream ( 142 new ByteArrayInputStream (buffer.toByteArray())); 143 c2 = (XIntervalSeriesCollection) in.readObject(); 144 in.close(); 145 } 146 catch (Exception e) { 147 e.printStackTrace(); 148 } 149 assertEquals(c1, c2); 150 } 151 152 156 public void test1170825() { 157 XIntervalSeries s1 = new XIntervalSeries("Series1"); 158 XIntervalSeriesCollection dataset = new XIntervalSeriesCollection(); 159 dataset.addSeries(s1); 160 try { 161 dataset.getSeries(1); 162 } 163 catch (IllegalArgumentException e) { 164 } 166 catch (IndexOutOfBoundsException e) { 167 assertTrue(false); } 169 } 170 171 } 172 | Popular Tags |