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.YIntervalSeries; 56 import org.jfree.data.xy.YIntervalSeriesCollection; 57 58 61 public class YIntervalSeriesCollectionTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(YIntervalSeriesCollectionTests.class); 70 } 71 72 77 public YIntervalSeriesCollectionTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 YIntervalSeriesCollection c1 = new YIntervalSeriesCollection(); 86 YIntervalSeriesCollection c2 = new YIntervalSeriesCollection(); 87 assertEquals(c1, c2); 88 89 YIntervalSeries s1 = new YIntervalSeries("Series"); 91 s1.add(1.0, 1.1, 1.2, 1.3); 92 c1.addSeries(s1); 93 assertFalse(c1.equals(c2)); 94 YIntervalSeries s2 = new YIntervalSeries("Series"); 95 s2.add(1.0, 1.1, 1.2, 1.3); 96 c2.addSeries(s2); 97 assertTrue(c1.equals(c2)); 98 99 c1.addSeries(new YIntervalSeries("Empty Series")); 101 assertFalse(c1.equals(c2)); 102 c2.addSeries(new YIntervalSeries("Empty Series")); 103 assertTrue(c1.equals(c2)); 104 } 105 106 109 public void testCloning() { 110 YIntervalSeriesCollection c1 = new YIntervalSeriesCollection(); 111 YIntervalSeries s1 = new YIntervalSeries("Series"); 112 s1.add(1.0, 1.1, 1.2, 1.3); 113 YIntervalSeriesCollection c2 = null; 114 try { 115 c2 = (YIntervalSeriesCollection) 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 YIntervalSeriesCollection c1 = new YIntervalSeriesCollection(); 130 YIntervalSeries s1 = new YIntervalSeries("Series"); 131 s1.add(1.0, 1.1, 1.2, 1.3); 132 YIntervalSeriesCollection 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 = (YIntervalSeriesCollection) 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 YIntervalSeries s1 = new YIntervalSeries("Series1"); 157 YIntervalSeriesCollection dataset = new YIntervalSeriesCollection(); 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 |