1 42 43 package org.jfree.data.time.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.time.Day; 57 import org.jfree.data.time.TimePeriodAnchor; 58 import org.jfree.data.time.TimePeriodValues; 59 import org.jfree.data.time.TimePeriodValuesCollection; 60 61 64 public class TimePeriodValuesCollectionTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(TimePeriodValuesCollectionTests.class); 73 } 74 75 80 public TimePeriodValuesCollectionTests(String name) { 81 super(name); 82 } 83 84 87 protected void setUp() { 88 } 90 91 95 public void test1161340() { 96 TimePeriodValuesCollection dataset = new TimePeriodValuesCollection(); 97 TimePeriodValues v1 = new TimePeriodValues("V1"); 98 v1.add(new Day(11, 3, 2005), 1.2); 99 v1.add(new Day(12, 3, 2005), 3.4); 100 dataset.addSeries(v1); 101 assertEquals(1, dataset.getSeriesCount()); 102 dataset.removeSeries(v1); 103 assertEquals(0, dataset.getSeriesCount()); 104 105 TimePeriodValues v2 = new TimePeriodValues("V2"); 106 v1.add(new Day(5, 3, 2005), 1.2); 107 v1.add(new Day(6, 3, 2005), 3.4); 108 dataset.addSeries(v2); 109 assertEquals(1, dataset.getSeriesCount()); 110 } 111 112 115 public void testEquals() { 116 117 TimePeriodValuesCollection c1 = new TimePeriodValuesCollection(); 118 TimePeriodValuesCollection c2 = new TimePeriodValuesCollection(); 119 assertTrue(c1.equals(c2)); 120 121 c1.setDomainIsPointsInTime(!c1.getDomainIsPointsInTime()); 122 assertFalse(c1.equals(c2)); 123 c2.setDomainIsPointsInTime(c1.getDomainIsPointsInTime()); 124 assertTrue(c1.equals(c2)); 125 126 c1.setXPosition(TimePeriodAnchor.END); 127 assertFalse(c1.equals(c2)); 128 c2.setXPosition(TimePeriodAnchor.END); 129 assertTrue(c1.equals(c2)); 130 131 TimePeriodValues v1 = new TimePeriodValues("Test"); 132 TimePeriodValues v2 = new TimePeriodValues("Test"); 133 134 c1.addSeries(v1); 135 assertFalse(c1.equals(c2)); 136 c2.addSeries(v2); 137 assertTrue(c1.equals(c2)); 138 } 139 140 143 public void testSerialization() { 144 145 TimePeriodValuesCollection c1 = new TimePeriodValuesCollection(); 146 TimePeriodValuesCollection c2 = null; 147 148 try { 149 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 150 ObjectOutput out = new ObjectOutputStream (buffer); 151 out.writeObject(c1); 152 out.close(); 153 154 ObjectInput in = new ObjectInputStream ( 155 new ByteArrayInputStream (buffer.toByteArray()) 156 ); 157 c2 = (TimePeriodValuesCollection) in.readObject(); 158 in.close(); 159 } 160 catch (Exception e) { 161 System.out.println(e.toString()); 162 } 163 assertEquals(c1, c2); 164 165 } 166 167 } 168 | Popular Tags |