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