10-1-2

public class AreaChartTests 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(AreaChartTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public AreaChartTests(String name) { super(name); } /** * Common test setup. */ protected void setUp() { this.chart = createAreaChart(); } /** * 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); } /** * 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() { 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); } /** * Create an area chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createAreaChart() { 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); return ChartFactory.createAreaChart("Area Chart", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, 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 BarChart3DTests extends TestCase { /** The chart. */ private JFreeChart chart; /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(BarChart3DTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public BarChart3DTests(String name) { super(name); } /** * Common test setup. */ protected void setUp() { this.chart = createBarChart3D(); } /** * 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 dataset and checks that the data range is as expected. */ 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 horizontal bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createBarChart3D() { // 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.createBarChart3D("Bar Chart 3D", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, 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/AreaChartTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/chart/junit/BarChart3DTests.java
Method name: `` |  | Method name: ``
Number of AST nodes: 0 |  | Number of AST nodes: 0

1

    public class AreaChartTests extends TestCase {↵

1

    public class BarChart3DTests extends TestCase {↵

2

        /** A chart. */↵

2

        /** The 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(AreaChartTests.class);↵

10

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

17

        public BarChart3DTests(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 = createAreaChart();↵

24

            this.chart = create↵

25

        }↵

26

        /**↵

27

         * Check that setting a tool tip generator for a series does override the↵

28

         * default generator.↵

29

         */↵

30

        public void testSetSeriesToolTipGenerator() {↵

31

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

32

            CategoryItemRenderer renderer = plot.getRenderer();↵

33

            StandardCategoryToolTipGenerator tt↵

34

                    = new StandardCategoryToolTipGenerator();↵

35

            renderer.setSeriesToolTipGenerator(0, tt);↵

36

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

37

            assertTrue(tt2 == tt);↵

38

        }↵

39

        ↵

40

        /**↵

41

         * Check that setting a URL generator for a series does override the↵

42

         * default generator.↵

43

         */↵

44

        public void testSetSeriesURLGenerator() {↵

45

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

46

            CategoryItemRenderer renderer = plot.getRenderer();↵

47

            StandardCategoryURLGenerator url1↵

48

                    = new StandardCategoryURLGenerator();↵

49

            renderer.setSeriesItemURLGenerator(0, url1);↵

50

            CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0);↵

51

            assertTrue(url2 == url1);↵

52

        }↵

53

        ↵

25

    BarChart3D();↵

26

        }↵

54

        /**↵

27

        /**↵

55

         * Draws the chart with a null info object to make sure that no exceptions ↵

28

         * Draws the chart with a null info object to make sure that no exceptions ↵

56

         * are thrown (a problem that was occurring at one point).↵

29

         * are thrown (a problem that was occurring at one point).↵

57

         */↵

30

         */↵

58

        public void testDrawWithNullInfo() {↵

31

        public void testDrawWithNullInfo() {↵

59

            boolean success = false;↵

32

            boolean success = false;↵

60

            try {↵

33

            try {↵

61

                BufferedImage image = new BufferedImage(200 , 100, ↵

34

                BufferedImage image = new BufferedImage(200 , 100, ↵

62

                        BufferedImage.TYPE_INT_RGB);↵

35

                        BufferedImage.TYPE_INT_RGB);↵

63

                Graphics2D g2 = image.createGraphics();↵

36

                Graphics2D g2 = image.createGraphics();↵

64

                this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, ↵

37

                this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, ↵

65

                        null);↵

38

                        null);↵

66

                g2.dispose();↵

39

                g2.dispose();↵

67

                success = true;↵

40

                success = true;↵

68

            }↵

41

            }↵

69

            catch (Exception e) {↵

42

            catch (Exception e) {↵

70

                success = false;↵

43

                success = false;↵

71

            }↵

44

            }↵

72

            assertTrue(success);↵

45

            assertTrue(success);↵

73

        }↵

46

        }↵

74

        /**↵

47

        /**↵

75

         * Replaces the chart's dataset and then checks that the new dataset is OK.↵

48

         * Replaces the dataset and checks that the data range is as expected.↵

76

         */↵

49

         */↵

77

        public void testReplaceDataset() {↵

50

        public void testReplaceDataset() {↵

51

            // create a dataset...↵

78

            Number[][] data = new Integer[][]↵

52

            Number[][] data = new Integer[][]↵

79

                {{new Integer(-30), new Integer(-20)},↵

53

                {{new Integer(-30), new Integer(-20)},↵

80

                 {new Integer(-10), new Integer(10)},↵

54

                 {new Integer(-10), new Integer(10)},↵

81

                 {new Integer(20), new Integer(30)}};↵

55

                 {new Integer(20), new Integer(30)}};↵

82

            CategoryDataset newData = DatasetUtilities.createCategoryDataset(↵

56

            CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", ↵

83

                    "S", "C", data);↵

57

                    "C", data);↵

84

            LocalListener l = new LocalListener();↵

58

            LocalListener l = new LocalListener();↵

85

            this.chart.addChangeListener(l);↵

59

            this.chart.addChangeListener(l);↵

86

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

60

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

87

            plot.setDataset(newData);↵

61

            plot.setDataset(newData);↵

88

            assertEquals(true, l.flag);↵

62

            assertEquals(true, l.flag);↵

89

            ValueAxis axis = plot.getRangeAxis();↵

63

            ValueAxis axis = plot.getRangeAxis();↵

90

            Range range = axis.getRange();↵

64

            Range range = axis.getRange();↵

91

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

65

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

92

                       + range.getLowerBound(), range.getLowerBound() <= -30);↵

66

                    + range.getLowerBound(), range.getLowerBound() <= -30);↵

93

            assertTrue("Expecting the upper bound of the range to be around 30: "↵

67

            assertTrue("Expecting the upper bound of the range to be around 30: "↵

94

                       + range.getUpperBound(), range.getUpperBound() >= 30);↵

68

                    + range.getUpperBound(), range.getUpperBound() >= 30);↵

95

        }↵

69

        }↵

96

        /**↵

70

        /**↵

97

         * Create an area↵

71

         * Check that setting a tool tip generator for a series does override the↵

72

         * default generator.↵

73

         */↵

74

        public void testSetSeriesToolTipGenerator() {↵

75

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

76

            CategoryItemRenderer renderer = plot.getRenderer();↵

77

            StandardCategoryToolTipGenerator tt↵

78

                    = new StandardCategoryToolTipGenerator();↵

79

            renderer.setSeriesToolTipGenerator(0, tt);↵

80

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

81

            assertTrue(tt2 == tt);↵

82

        }↵

83

        ↵

84

        /**↵

85

         * Check that setting a URL generator for a series does override the↵

86

         * default generator.↵

87

         */↵

88

        public void testSetSeriesURLGenerator() {↵

89

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

90

            CategoryItemRenderer renderer = plot.getRenderer();↵

91

            StandardCategoryURLGenerator url1↵

92

                    = new StandardCategoryURLGenerator();↵

93

            renderer.setSeriesItemURLGenerator(0, url1);↵

94

            CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0);↵

95

            assertTrue(url2 == url1);↵

96

        }↵

97

        ↵

98

        /**↵

98

     chart with sample data in the range -3 to +3.↵

99

         * Create a horizontal bar chart with sample data in the range -3 to +3.↵

99

         *↵

100

         *↵

100

         * @return The chart.↵

101

         * @return The chart.↵

101

         */↵

102

         */↵

102

        private static JFreeChart createAreaChart() {↵

103

        private static JFreeChart createBarChart3D() {↵

104

            // create a dataset...↵

103

            Number[][] data = new Integer[][]↵

105

            Number[][] data = new Integer[][]↵

104

                {{new Integer(-3), new Integer(-2)},↵

106

                {{new Integer(-3), new Integer(-2)},↵

105

                 {new Integer(-1), new Integer(1)},↵

107

                 {new Integer(-1), new Integer(1)},↵

106

                 {new Integer(2), new Integer(3)}};↵

108

                 {new Integer(2), new Integer(3)}};↵

107

            CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", ↵

109

            CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", ↵

108

                    "C", data);↵

110

                    "C", data);↵

111

            // create the chart...↵

109

            return ChartFactory.createAreaChart("Area Chart", "Domain", "Range",↵

112

            return ChartFactory.createBarChart3D("Bar Chart 3D", "Domain", "Range",↵

110

                    dataset, PlotOrientation.HORIZONTAL, true, true, true);↵

113

                    dataset, PlotOrientation.HORIZONTAL, true, true, true);↵

111

        }↵

114

        }↵

112

        /**↵

115

        /**↵

113

         * A chart change listener.↵

116

         * A chart change listener.↵

117

         *↵

114

         */↵

118

         */↵

115

        static class LocalListener implements ChartChangeListener {↵

119

        static class LocalListener implements ChartChangeListener {↵

116

            /** A flag. */↵

120

            /** A flag. */↵

117

            private boolean flag = false;↵

121

            private boolean flag = false;↵

118

            /**↵

122

            /**↵

119

             * Event handler.↵

123

             * Event handler.↵

120

             *↵

124

             *↵

121

             * @param event  the event.↵

125

             * @param event  the event.↵

122

             */↵

126

             */↵

123

            public void chartChanged(ChartChangeEvent event) {↵

127

            public void chartChanged(ChartChangeEvent event) {↵

124

                this.flag = true;↵

128

                this.flag = true;↵

125

129

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