1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/* ===========================================================
* 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.]
*
* -------------
* PlotTest.java
* -------------
* (C) Copyright 2005-2013, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* Changes
* -------
* 06-Jun-2005 : Version 1 (DG);
* 30-Jun-2006 : Extended equals() test to cover new field (DG);
* 11-May-2007 : Another new field in testEquals() (DG);
*
*/
package org.jfree.chart.plot;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Stroke;
import org.jfree.chart.JFreeChart;
import org.jfree.ui.Align;
import org.jfree.ui.RectangleInsets;
import org.junit.Test;
/**
* Some tests for the {@link Plot} class.
*/
public class PlotTest {
/**
* Check that the equals() method can distinguish all fields (note that
* the dataset is NOT considered in the equals() method).
*/
@Test
public void testEquals() {
PiePlot plot1 = new PiePlot();
PiePlot plot2 = new PiePlot();
assertTrue(plot1.equals(plot2));
assertTrue(plot2.equals(plot1));
// noDataMessage
plot1.setNoDataMessage("No data XYZ");
assertFalse(plot1.equals(plot2));
plot2.setNoDataMessage("No data XYZ");
assertTrue(plot1.equals(plot2));
// noDataMessageFont
plot1.setNoDataMessageFont(new Font("SansSerif", Font.PLAIN, 13));
assertFalse(plot1.equals(plot2));
plot2.setNoDataMessageFont(new Font("SansSerif", Font.PLAIN, 13));
assertTrue(plot1.equals(plot2));
// noDataMessagePaint
plot1.setNoDataMessagePaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.blue));
assertFalse(plot1.equals(plot2));
plot2.setNoDataMessagePaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.blue));
assertTrue(plot1.equals(plot2));
// insets
plot1.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
assertFalse(plot1.equals(plot2));
plot2.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
assertTrue(plot1.equals(plot2));
// outlineVisible
plot1.setOutlineVisible(false);
assertFalse(plot1.equals(plot2));
plot2.setOutlineVisible(false);
assertTrue(plot1.equals(plot2));
// outlineStroke
BasicStroke s = new BasicStroke(1.23f);
plot1.setOutlineStroke(s);
assertFalse(plot1.equals(plot2));
plot2.setOutlineStroke(s);
assertTrue(plot1.equals(plot2));
// outlinePaint
plot1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.yellow,
3.0f, 4.0f, Color.green));
assertFalse(plot1.equals(plot2));
plot2.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.yellow,
3.0f, 4.0f, Color.green));
assertTrue(plot1.equals(plot2));
// backgroundPaint
plot1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.cyan,
3.0f, 4.0f, Color.green));
assertFalse(plot1.equals(plot2));
plot2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.cyan,
3.0f, 4.0f, Color.green));
assertTrue(plot1.equals(plot2));
// backgroundImage
plot1.setBackgroundImage(JFreeChart.INFO.getLogo());
assertFalse(plot1.equals(plot2));
plot2.setBackgroundImage(JFreeChart.INFO.getLogo());
assertTrue(plot1.equals(plot2));
// backgroundImageAlignment
plot1.setBackgroundImageAlignment(Align.BOTTOM_RIGHT);
assertFalse(plot1.equals(plot2));
plot2.setBackgroundImageAlignment(Align.BOTTOM_RIGHT);
assertTrue(plot1.equals(plot2));
// backgroundImageAlpha
plot1.setBackgroundImageAlpha(0.77f);
assertFalse(plot1.equals(plot2));
plot2.setBackgroundImageAlpha(0.77f);
assertTrue(plot1.equals(plot2));
// foregroundAlpha
plot1.setForegroundAlpha(0.99f);
assertFalse(plot1.equals(plot2));
plot2.setForegroundAlpha(0.99f);
assertTrue(plot1.equals(plot2));
// backgroundAlpha
plot1.setBackgroundAlpha(0.99f);
assertFalse(plot1.equals(plot2));
plot2.setBackgroundAlpha(0.99f);
assertTrue(plot1.equals(plot2));
// drawingSupplier
plot1.setDrawingSupplier(new DefaultDrawingSupplier(
new Paint[] {Color.blue}, new Paint[] {Color.red},
new Stroke[] {new BasicStroke(1.1f)},
new Stroke[] {new BasicStroke(9.9f)},
new Shape[] {new Rectangle(1, 2, 3, 4)}));
assertFalse(plot1.equals(plot2));
plot2.setDrawingSupplier(new DefaultDrawingSupplier(
new Paint[] {Color.blue}, new Paint[] {Color.red},
new Stroke[] {new BasicStroke(1.1f)},
new Stroke[] {new BasicStroke(9.9f)},
new Shape[] {new Rectangle(1, 2, 3, 4)}));
assertTrue(plot1.equals(plot2));
}
}
|