public class BarChartTests 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(BarChartTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public BarChartTests(String name) { super(name); } /** * Common test setup. */ protected void setUp() { this.chart = createBarChart(); } /** * 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; } assertTrue(success); } /** * Replaces the chart's dataset and then checks that the new dataset is OK. */ public void testReplaceDataset() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-30), new Integer(-20)}, {new Integer(-10), new Integer(10)}, {new Integer(20), new Integer(30)}}; CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); plot.setDataset(newData); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30); 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() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertTrue(tt2 == tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertTrue(url2 == url1); } /** * Create a bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createBarChart() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); // create the chart... return ChartFactory.createBarChart( "Bar Chart", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, // include legend true, true ); } /** * 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 LineChart3DTests 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(LineChart3DTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public LineChart3DTests(String name) { super(name); } /** * Common test setup. */ protected void setUp() { this.chart = createLineChart3D(); } /** * 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; } assertTrue(success); } /** * Replaces the chart's dataset and then checks that the new dataset is OK. */ public void testReplaceDataset() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-30), new Integer(-20)}, {new Integer(-10), new Integer(10)}, {new Integer(20), new Integer(30)}}; CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); plot.setDataset(newData); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30); 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() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertTrue(tt2 == tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertTrue(url2 == url1); } /** * Create a line chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createLineChart3D() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); // create the chart... return ChartFactory.createLineChart3D( "Line Chart", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, // include legend true, true ); } /** * 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/BarChartTests.java File path: /jfreechart-1.0.10/tests/org/jfree/chart/junit/LineChart3DTests.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class BarChartTests extends TestCase {
1
public class LineChart3DTests 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(BarChartTests.class);
10
        return new TestSuite(LineChart3DTests.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 BarChartTests(String name) {
17
    public LineChart3DTests(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 = createBarChart();
24
        this.chart = createLineChart3D();
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
        }
43
        }
44
        assertTrue(success);
44
        assertTrue(success);
45
    }
45
    }
46
    /**
46
    /**
47
     * Replaces the chart's dataset and then checks that the new dataset is OK.
47
     * Replaces the chart's dataset and then checks that the new dataset is OK.
48
     */
48
     */
49
    public void testReplaceDataset() {
49
    public void testReplaceDataset() {
50
        // create a dataset...
50
        // create a dataset...
51
        Number[][] data = new Integer[][]
51
        Number[][] data = new Integer[][]
52
            {{new Integer(-30), new Integer(-20)},
52
            {{new Integer(-30), new Integer(-20)},
53
             {new Integer(-10), new Integer(10)},
53
             {new Integer(-10), new Integer(10)},
54
             {new Integer(20), new Integer(30)}};
54
             {new Integer(20), new Integer(30)}};
55
        CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", 
55
        CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", 
56
                "C", data);
56
                "C", data);
57
        LocalListener l = new LocalListener();
57
        LocalListener l = new LocalListener();
58
        this.chart.addChangeListener(l);
58
        this.chart.addChangeListener(l);
59
        CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
59
        CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
60
        plot.setDataset(newData);
60
        plot.setDataset(newData);
61
        assertEquals(true, l.flag);
61
        assertEquals(true, l.flag);
62
        ValueAxis axis = plot.getRangeAxis();
62
        ValueAxis axis = plot.getRangeAxis();
63
        Range range = axis.getRange();
63
        Range range = axis.getRange();
64
        assertTrue("Expecting the lower bound of the range to be around -30: "
64
        assertTrue("Expecting the lower bound of the range to be around -30: "
65
                   + range.getLowerBound(), range.getLowerBound() <= -30);
65
                   + range.getLowerBound(), range.getLowerBound() <= -30);
66
        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: "
67
                   + range.getUpperBound(), range.getUpperBound() >= 30);
67
                   + range.getUpperBound(), range.getUpperBound() >= 30);
68
    }
68
    }
69
    /**
69
    /**
70
     * 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
71
     * default generator.
71
     * default generator.
72
     */
72
     */
73
    public void testSetSeriesToolTipGenerator() {
73
    public void testSetSeriesToolTipGenerator() {
74
        CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
74
        CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
75
        CategoryItemRenderer renderer = plot.getRenderer();
75
        CategoryItemRenderer renderer = plot.getRenderer();
76
        StandardCategoryToolTipGenerator tt
76
        StandardCategoryToolTipGenerator tt
77
                = new StandardCategoryToolTipGenerator();
77
                = new StandardCategoryToolTipGenerator();
78
        renderer.setSeriesToolTipGenerator(0, tt);
78
        renderer.setSeriesToolTipGenerator(0, tt);
79
        CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0);
79
        CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0);
80
        assertTrue(tt2 == tt);
80
        assertTrue(tt2 == tt);
81
    }
81
    }
82
    
82
    
83
    /**
83
    /**
84
     * Check that setting a URL generator for a series does override the
84
     * Check that setting a URL generator for a series does override the
85
     * default generator.
85
     * default generator.
86
     */
86
     */
87
    public void testSetSeriesURLGenerator() {
87
    public void testSetSeriesURLGenerator() {
88
        CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
88
        CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
89
        CategoryItemRenderer renderer = plot.getRenderer();
89
        CategoryItemRenderer renderer = plot.getRenderer();
90
        StandardCategoryURLGenerator url1
90
        StandardCategoryURLGenerator url1
91
                = new StandardCategoryURLGenerator();
91
                = new StandardCategoryURLGenerator();
92
        renderer.setSeriesItemURLGenerator(0, url1);
92
        renderer.setSeriesItemURLGenerator(0, url1);
93
        CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0);
93
        CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0);
94
        assertTrue(url2 == url1);
94
        assertTrue(url2 == url1);
95
    }
95
    }
96
    
96
    
97
    /**
97
    /**
98
     * Create a bar chart with sample data in the range -3 to +3.
98
     * Create a line chart with sample data in the range -3 to +3.
99
     *
99
     *
100
     * @return The chart.
100
     * @return The chart.
101
     */
101
     */
102
    private static JFreeChart createBarChart() {
102
    private static JFreeChart createLineChart3D() {
103
        // create a dataset...
103
        // create a dataset...
104
        Number[][] data = new Integer[][]
104
        Number[][] data = new Integer[][]
105
            {{new Integer(-3), new Integer(-2)},
105
            {{new Integer(-3), new Integer(-2)},
106
             {new Integer(-1), new Integer(1)},
106
             {new Integer(-1), new Integer(1)},
107
             {new Integer(2), new Integer(3)}};
107
             {new Integer(2), new Integer(3)}};
108
        CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", 
108
        CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", 
109
                "C", data);
109
                "C", data);
110
        // create the chart...
110
        // create the chart...
111
        return ChartFactory.createBarChart(
111
        return ChartFactory.createLineChart3D(
112
            "Bar Chart",
112
            "Line Chart",
113
            "Domain", "Range",
113
            "Domain", "Range",
114
            dataset,
114
            dataset,
115
            PlotOrientation.HORIZONTAL,
115
            PlotOrientation.HORIZONTAL,
116
            true,     // include legend
116
            true,     // include legend
117
            true,
117
            true,
118
            true
118
            true
119
        );
119
        );
120
    }
120
    }
121
    /**
121
    /**
122
     * A chart change listener.
122
     * A chart change listener.
123
     *
123
     *
124
     */
124
     */
125
    static class LocalListener implements ChartChangeListener {
125
    static class LocalListener implements ChartChangeListener {
126
        /** A flag. */
126
        /** A flag. */
127
        private boolean flag = false;
127
        private boolean flag = false;
128
        /**
128
        /**
129
         * Event handler.
129
         * Event handler.
130
         *
130
         *
131
         * @param event  the event.
131
         * @param event  the event.
132
         */
132
         */
133
        public void chartChanged(ChartChangeEvent event) {
133
        public void chartChanged(ChartChangeEvent event) {
134
            this.flag = true
134
            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