15-4-6

public class XYLineChartTests 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(XYLineChartTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public XYLineChartTests(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.createXYLineChart( "XY Line 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;
public class XYStepChartTests 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(XYStepChartTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public XYStepChartTests(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.createXYStepChart( "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/XYLineChartTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/chart/junit/XYStepChartTests.java
Method name: `` |  | Method name: ``
Number of AST nodes: 0 |  | Number of AST nodes: 0

1

    public class XYLineChartTests extends TestCase {↵

1

    public class XYStepChartTests 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(XYLineChartTests.class);↵

10

            return new TestSuite(XYStepChartTests.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 XYLineChartTests(String name) {↵

17

        public XYStepChartTests(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

            XYPlot plot = (XYPlot) this.chart.getPlot();↵

59

            XYPlot plot = (XYPlot) this.chart.getPlot();↵

60

            plot.setDataset(dataset);↵

60

            plot.setDataset(dataset);↵

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 10: "↵

64

            assertTrue("Expecting the lower bound of the range to be around 10: "↵

65

                       + range.getLowerBound(), range.getLowerBound() <= 10);↵

65

                       + range.getLowerBound(), range.getLowerBound() <= 10);↵

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

            XYPlot plot = (XYPlot) this.chart.getPlot();↵

74

            XYPlot plot = (XYPlot) this.chart.getPlot();↵

75

            XYItemRenderer renderer = plot.getRenderer();↵

75

            XYItemRenderer renderer = plot.getRenderer();↵

76

            StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator();↵

76

            StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator();↵

77

            renderer.setSeriesToolTipGenerator(0, tt);↵

77

            renderer.setSeriesToolTipGenerator(0, tt);↵

78

            XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0);↵

78

            XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0);↵

79

            assertTrue(tt2 == tt);↵

79

            assertTrue(tt2 == tt);↵

80

        }↵

80

        }↵

81

        ↵

81

        ↵

82

        /**↵

82

        /**↵

83

         * 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.↵

84

         *↵

84

         *↵

85

         * @return The chart.↵

85

         * @return The chart.↵

86

         */↵

86

         */↵

87

        private static JFreeChart createChart() {↵

87

        private static JFreeChart createChart() {↵

88

            // create a dataset...↵

88

            // create a dataset...↵

89

            XYSeries series1 = new XYSeries("Series 1");↵

89

            XYSeries series1 = new XYSeries("Series 1");↵

90

            series1.add(1.0, 1.0);↵

90

            series1.add(1.0, 1.0);↵

91

            series1.add(2.0, 2.0);↵

91

            series1.add(2.0, 2.0);↵

92

            series1.add(3.0, 3.0);↵

92

            series1.add(3.0, 3.0);↵

93

            XYDataset dataset = new XYSeriesCollection(series1);↵

93

            XYDataset dataset = new XYSeriesCollection(series1);↵

94

            // create the chart...↵

94

            // create the chart...↵

95

            return ChartFactory.createXYLineChart(↵

95

            return ChartFactory.createXYStepChart(↵

96

                "XY Line Chart",  // chart title↵

96

                "Step Chart",  // chart title↵

97

                "Domain",↵

97

                "Domain",↵

98

                "Range",↵

98

                "Range",↵

99

                dataset,         // data↵

99

                dataset,         // data↵

100

                PlotOrientation.VERTICAL,↵

100

                PlotOrientation.VERTICAL,↵

101

                true,            // include legend↵

101

                true,            // include legend↵

102

                true,            // tooltips↵

102

                true,            // tooltips↵

103

                true             // urls↵

103

                true             // urls↵

104

            );↵

104

            );↵

105

        }↵

105

        }↵

106

        /**↵

106

        /**↵

107

         * A chart change listener.↵

107

         * A chart change listener.↵

108

         *↵

108

         *↵

109

         */↵

109

         */↵

110

        static class LocalListener implements ChartChangeListener {↵

110

        static class LocalListener implements ChartChangeListener {↵

111

            /** A flag. */↵

111

            /** A flag. */↵

112

            private boolean flag = false;↵

112

            private boolean flag = false;↵

113

            /**↵

113

            /**↵

114

             * Event handler.↵

114

             * Event handler.↵

115

             *↵

115

             *↵

116

             * @param event  the event.↵

116

             * @param event  the event.↵

117

             */↵

117

             */↵

118

            public void chartChanged(ChartChangeEvent event) {↵

118

            public void chartChanged(ChartChangeEvent event) {↵

119

                this.flag = true;↵

119

                this.flag = true;↵

120

120

See real code fragment |  | See real code fragment

Summary
Number of common nesting structure subtrees | 0
Number of refactorable cases | 0
Number of non-refactorable cases | 0
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.0
Clones location |
Number of node comparisons | 0