public class XYBarChartTests extends TestCase { /** A chart. */ private JFreeChart chart; /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(XYBarChartTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public XYBarChartTests(String name) { super(name); } /** * Common test setup. */ protected void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ public void testDrawWithNullInfo() { boolean success = false; try { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); success = true; } catch (Exception e) { success = false; e.printStackTrace(); } assertTrue(success); } /** * Replaces the dataset and checks that it has changed as expected. */ public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ public void testSetSeriesToolTipGenerator() { XYPlot plot = (XYPlot) this.chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertTrue(tt2 == tt); } /** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); IntervalXYDataset dataset = new XYBarDataset(new XYSeriesCollection( series1), 1.0); // create the chart... return ChartFactory.createXYBarChart( "XY Bar Chart", // chart title "Domain", false, "Range", dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips true // urls ); } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag = false; /** * Event handler. * * @param event the event. */ public void chartChanged(ChartChangeEvent event) { this.flag = true
public class XYStepAreaChartTests extends TestCase { /** A chart. */ private JFreeChart chart; /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(XYStepAreaChartTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public XYStepAreaChartTests(String name) { super(name); } /** * Common test setup. */ protected void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ public void testDrawWithNullInfo() { boolean success = false; try { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); success = true; } catch (Exception e) { success = false; e.printStackTrace(); } assertTrue(success); } /** * Replaces the dataset and checks that it has changed as expected. */ public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ public void testSetSeriesToolTipGenerator() { XYPlot plot = (XYPlot) this.chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertTrue(tt2 == tt); } /** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); // create the chart... return ChartFactory.createXYStepAreaChart( "Step Chart", // chart title "Domain", "Range", dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips true // urls ); } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag = false; /** * Event handler. * * @param event the event. */ public void chartChanged(ChartChangeEvent event) { this.flag = true
Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/chart/junit/XYBarChartTests.java File path: /jfreechart-1.0.10/tests/org/jfree/chart/junit/XYStepAreaChartTests.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class XYBarChartTests extends TestCase {
1
public class XYStepAreaChartTests extends TestCase {
2
    /** A chart. */
2
    /** A chart. */
3
    private JFreeChart chart;
3
    private JFreeChart chart;
4
    /**
4
    /**
5
     * Returns the tests as a test suite.
5
     * Returns the tests as a test suite.
6
     *
6
     *
7
     * @return The test suite.
7
     * @return The test suite.
8
     */
8
     */
9
    public static Test suite() {
9
    public static Test suite() {
10
        return new TestSuite(XYBarChartTests.class);
10
        return new TestSuite(XYStepAreaChartTests.class);
11
    }
11
    }
12
    /**
12
    /**
13
     * Constructs a new set of tests.
13
     * Constructs a new set of tests.
14
     *
14
     *
15
     * @param name  the name of the tests.
15
     * @param name  the name of the tests.
16
     */
16
     */
17
    public XYBarChartTests(String name) {
17
    public XYStepAreaChartTests(String name) {
18
        super(name);
18
        super(name);
19
    }
19
    }
20
    /**
20
    /**
21
     * Common test setup.
21
     * Common test setup.
22
     */
22
     */
23
    protected void setUp() {
23
    protected void setUp() {
24
        this.chart = createChart();
24
        this.chart = createChart();
25
    }
25
    }
26
    /**
26
    /**
27
     * Draws the chart with a null info object to make sure that no exceptions 
27
     * Draws the chart with a null info object to make sure that no exceptions 
28
     * are thrown (a problem that was occurring at one point).
28
     * are thrown (a problem that was occurring at one point).
29
     */
29
     */
30
    public void testDrawWithNullInfo() {
30
    public void testDrawWithNullInfo() {
31
        boolean success = false;
31
        boolean success = false;
32
        try {
32
        try {
33
            BufferedImage image = new BufferedImage(200 , 100, 
33
            BufferedImage image = new BufferedImage(200 , 100, 
34
                    BufferedImage.TYPE_INT_RGB);
34
                    BufferedImage.TYPE_INT_RGB);
35
            Graphics2D g2 = image.createGraphics();
35
            Graphics2D g2 = image.createGraphics();
36
            this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, 
36
            this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, 
37
                    null);
37
                    null);
38
            g2.dispose();
38
            g2.dispose();
39
            success = true;
39
            success = true;
40
        }
40
        }
41
        catch (Exception e) {
41
        catch (Exception e) {
42
          success = false;
42
          success = false;
43
          e.printStackTrace();
43
          e.printStackTrace();
44
        }
44
        }
45
        assertTrue(success);
45
        assertTrue(success);
46
    }
46
    }
47
    /**
47
    /**
48
     * Replaces the dataset and checks that it has changed as expected.
48
     * Replaces the dataset and checks that it has changed as expected.
49
     */
49
     */
50
    public void testReplaceDataset() {
50
    public void testReplaceDataset() {
51
        // create a dataset...
51
        // create a dataset...
52
        XYSeries series1 = new XYSeries("Series 1");
52
        XYSeries series1 = new XYSeries("Series 1");
53
        series1.add(10.0, 10.0);
53
        series1.add(10.0, 10.0);
54
        series1.add(20.0, 20.0);
54
        series1.add(20.0, 20.0);
55
        series1.add(30.0, 30.0);
55
        series1.add(30.0, 30.0);
56
        XYDataset dataset = new XYSeriesCollection(series1);
56
        XYDataset dataset = new XYSeriesCollection(series1);
57
        LocalListener l = new LocalListener();
57
        LocalListener l = new LocalListener();
58
        this.chart.addChangeListener(l);
58
        this.chart.addChangeListener(l);
59
        
60
        XYPlot plot = (XYPlot) this.chart.getPlot();
59
        XYPlot plot = (XYPlot) this.chart.getPlot();
61
        plot.setDataset(dataset);
60
        plot.setDataset(dataset);
62
        assertEquals(true, l.flag);
61
        assertEquals(true, l.flag);
63
        ValueAxis axis = plot.getRangeAxis();
62
        ValueAxis axis = plot.getRangeAxis();
64
        Range range = axis.getRange();
63
        Range range = axis.getRange();
65
        assertTrue("Expecting the lower bound of the range to be around 10: "
64
        assertTrue("Expecting the lower bound of the range to be around 10: "
66
                   + range.getLowerBound(), range.getLowerBound() <= 10);
65
                   + range.getLowerBound(), range.getLowerBound() <= 10);
67
        assertTrue("Expecting the upper bound of the range to be around 30: "
66
        assertTrue("Expecting the upper bound of the range to be around 30: "
68
                   + range.getUpperBound(), range.getUpperBound() >= 30);
67
                   + range.getUpperBound(), range.getUpperBound() >= 30);
69
    }
68
    }
70
    /**
69
    /**
71
     * Check that setting a tool tip generator for a series does override the
70
     * Check that setting a tool tip generator for a series does override the
72
     * default generator.
71
     * default generator.
73
     */
72
     */
74
    public void testSetSeriesToolTipGenerator() {
73
    public void testSetSeriesToolTipGenerator() {
75
        XYPlot plot = (XYPlot) this.chart.getPlot();
74
        XYPlot plot = (XYPlot) this.chart.getPlot();
76
        XYItemRenderer renderer = plot.getRenderer();
75
        XYItemRenderer renderer = plot.getRenderer();
77
        StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator();
76
        StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator();
78
        renderer.setSeriesToolTipGenerator(0, tt);
77
        renderer.setSeriesToolTipGenerator(0, tt);
79
        XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0);
78
        XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0);
80
        assertTrue(tt2 == tt);
79
        assertTrue(tt2 == tt);
81
    }
80
    }
82
    
81
    
83
    /**
82
    /**
84
     * Create a horizontal bar chart with sample data in the range -3 to +3.
83
     * Create a horizontal bar chart with sample data in the range -3 to +3.
85
     *
84
     *
86
     * @return The chart.
85
     * @return The chart.
87
     */
86
     */
88
    private static JFreeChart createChart() {
87
    private static JFreeChart createChart() {
89
        // create a dataset...
88
        // create a dataset...
90
        XYSeries series1 = new XYSeries("Series 1");
89
        XYSeries series1 = new XYSeries("Series 1");
91
        series1.add(1.0, 1.0);
90
        series1.add(1.0, 1.0);
92
        series1.add(2.0, 2.0);
91
        series1.add(2.0, 2.0);
93
        series1.add(3.0, 3.0);
92
        series1.add(3.0, 3.0);
94
        IntervalXYDataset dataset = new XYBarDataset(new XYSeriesCollection(
93
        XYDataset dataset = new XY
95
                series1), 1.0);
94
SeriesCollection(series1);
96
 
97
        // create the chart...
95
        // create the chart...
98
        return ChartFactory.createXYBarChart(
96
        return ChartFactory.createXYStepAreaChart(
99
            "XY Bar Chart",  // chart title
97
            "Step Chart",  // chart title
100
            "Domain", false,
98
            "Domain",
101
            "Range",
99
            "Range",
102
            dataset,         // data
100
            dataset,         // data
103
            PlotOrientation.VERTICAL,
101
            PlotOrientation.VERTICAL,
104
            true,            // include legend
102
            true,            // include legend
105
            true,            // tooltips
103
            true,            // tooltips
106
            true             // urls
104
            true            // urls
107
        );
105
        );
108
    }
106
    }
109
    /**
107
    /**
110
     * A chart change listener.
108
     * A chart change listener.
111
     *
109
     *
112
     */
110
     */
113
    static class LocalListener implements ChartChangeListener {
111
    static class LocalListener implements ChartChangeListener {
114
        /** A flag. */
112
        /** A flag. */
115
        private boolean flag = false;
113
        private boolean flag = false;
116
        /**
114
        /**
117
         * Event handler.
115
         * Event handler.
118
         *
116
         *
119
         * @param event  the event.
117
         * @param event  the event.
120
         */
118
         */
121
        public void chartChanged(ChartChangeEvent event) {
119
        public void chartChanged(ChartChangeEvent event) {
122
            this.flag = true
120
            this.flag = true
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0