@Test public void testSetKey() { TimeSeries s1 = new TimeSeries("S"); s1.setKey("S1"); assertEquals("S1", s1.getKey()); TimeSeriesCollection c = new TimeSeriesCollection(); c.addSeries(s1); TimeSeries s2 = new TimeSeries("S2"); c.addSeries(s2); // now we should be allowed to change s1's key to anything but "S2" s1.setKey("OK"); assertEquals("OK", s1.getKey()); try { s1.setKey("S2"); fail("Expect an exception here."); } catch (IllegalArgumentException e) { // OK } // after s1 is removed from the collection, we should be able to set // the key to anything we want... c.removeSeries(s1); s1.setKey("S2"); // check that removing by index also works s1.setKey("S1"); c.addSeries(s1); c.removeSeries(1); s1.setKey("S2"); }
/** Check that cloning works. */ @Test public void testClone() throws CloneNotSupportedException { TimeSeries series = new TimeSeries("Test Series"); RegularTimePeriod jan1st2002 = new Day(1, MonthConstants.JANUARY, 2002); series.add(jan1st2002, new Integer(42)); TimeSeries clone; clone = (TimeSeries) series.clone(); clone.setKey("Clone Series"); clone.update(jan1st2002, new Integer(10)); int seriesValue = series.getValue(jan1st2002).intValue(); int cloneValue = clone.getValue(jan1st2002).intValue(); assertEquals(42, seriesValue); assertEquals(10, cloneValue); assertEquals("Test Series", series.getKey()); assertEquals("Clone Series", clone.getKey()); }