123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- /* ===========================================================
- * JFreeChart : a free chart library for the Java(tm) platform
- * ===========================================================
- *
- * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors.
- *
- * Project Info: http://www.jfree.org/jfreechart/index.html
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- * USA.
- *
- * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.]
- *
- * ---------------------------
- * ChartRenderingInfoTest.java
- * ---------------------------
- * (C) Copyright 2004-2013, by Object Refinery Limited and Contributors.
- *
- * Original Author: David Gilbert (for Object Refinery Limited);
- * Contributor(s): -;
- *
- * Changes
- * -------
- * 19-Mar-2004 : Version 1 (DG);
- * 30-Nov-2005 : Updated for removed field in ChartRenderingInfo (DG);
- *
- */
- package org.jfree.chart;
- import java.awt.Rectangle;
- import java.awt.geom.Rectangle2D;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertFalse;
- import static org.junit.Assert.assertNotSame;
- import static org.junit.Assert.assertSame;
- import org.jfree.chart.entity.ChartEntity;
- import org.jfree.chart.entity.StandardEntityCollection;
- import org.junit.Test;
- /**
- * Tests for the {@link ChartRenderingInfo} class.
- */
- public class ChartRenderingInfoTest {
- /**
- * Confirm that the equals method can distinguish all the required fields.
- */
- @Test
- public void testEquals() {
- ChartRenderingInfo i1 = new ChartRenderingInfo();
- ChartRenderingInfo i2 = new ChartRenderingInfo();
- assertEquals(i1, i2);
- i1.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
- assertFalse(i1.equals(i2));
- i2.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
- assertEquals(i1, i2);
- i1.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4));
- assertFalse(i1.equals(i2));
- i2.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4));
- assertEquals(i1, i2);
- StandardEntityCollection e1 = new StandardEntityCollection();
- e1.add(new ChartEntity(new Rectangle(1, 2, 3, 4)));
- i1.setEntityCollection(e1);
- assertFalse(i1.equals(i2));
- StandardEntityCollection e2 = new StandardEntityCollection();
- e2.add(new ChartEntity(new Rectangle(1, 2, 3, 4)));
- i2.setEntityCollection(e2);
- }
- /**
- * Confirm that cloning works.
- */
- @Test
- public void testCloning() throws CloneNotSupportedException {
- ChartRenderingInfo i1 = new ChartRenderingInfo();
- ChartRenderingInfo i2 = (ChartRenderingInfo) i1.clone();
- assertNotSame(i1, i2);
- assertSame(i1.getClass(), i2.getClass());
- assertEquals(i1, i2);
- // check independence
- i1.getChartArea().setRect(4.0, 3.0, 2.0, 1.0);
- assertFalse(i1.equals(i2));
- i2.getChartArea().setRect(4.0, 3.0, 2.0, 1.0);
- assertEquals(i1, i2);
- i1.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2,
- 1)));
- assertFalse(i1.equals(i2));
- i2.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2,
- 1)));
- assertEquals(i1, i2);
- }
- /**
- * Serialize an instance, restore it, and check for equality.
- */
- @Test
- public void testSerialization() {
- ChartRenderingInfo i1 = new ChartRenderingInfo();
- i1.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
- ChartRenderingInfo i2 = (ChartRenderingInfo) TestUtilities.serialised(i1);
- assertEquals(i1, i2);
- }
- /**
- * Serialize an instance, restore it, and check for equality.
- */
- @Test
- public void testSerialization2() {
- ChartRenderingInfo i1 = new ChartRenderingInfo();
- i1.getPlotInfo().setDataArea(new Rectangle2D.Double(1.0, 2.0, 3.0,
- 4.0));
- ChartRenderingInfo i2 = (ChartRenderingInfo) TestUtilities.serialised(i1);
- assertEquals(i1, i2);
- assertEquals(i2, i2.getPlotInfo().getOwner());
- }
- }
|