/** * Some basic checks for the clone() method. * * @throws CloneNotSupportedException */ @Test public void testCloning() throws CloneNotSupportedException { PiePlot p1 = new PiePlot(); PiePlot p2 = (PiePlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); }
/** * Check cloning of the legendLabelURLGenerator field. * * @throws CloneNotSupportedException */ @Test public void testCloning_LegendLabelURLGenerator() throws CloneNotSupportedException { CustomPieURLGenerator generator = new CustomPieURLGenerator(); PiePlot p1 = new PiePlot(); p1.setLegendLabelURLGenerator(generator); PiePlot p2 = (PiePlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // check that the URL generator has been cloned assertNotSame(p1.getLegendLabelURLGenerator(), p2.getLegendLabelURLGenerator()); }
/** * Check cloning of the legendLabelToolTipGenerator field. * * @throws CloneNotSupportedException */ @Test public void testCloning_LegendLabelToolTipGenerator() throws CloneNotSupportedException { StandardPieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator(); PiePlot p1 = new PiePlot(); p1.setLegendLabelToolTipGenerator(generator); PiePlot p2 = (PiePlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // change the generator and make sure it only affects p1 generator.getNumberFormat().setMinimumFractionDigits(2); assertFalse(p1.equals(p2)); }
/** * Check cloning of the legendItemShape field. * * @throws CloneNotSupportedException */ @Test public void testCloning_LegendItemShape() throws CloneNotSupportedException { Rectangle shape = new Rectangle(-4, -4, 8, 8); PiePlot p1 = new PiePlot(); p1.setLegendItemShape(shape); PiePlot p2 = (PiePlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // change the shape and make sure it only affects p1 shape.setRect(1.0, 2.0, 3.0, 4.0); assertFalse(p1.equals(p2)); }