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