183-5-7

StandardCategorySeriesLabelGenerator generator = new StandardCategorySeriesLabelGenerator("Series {0}"); BarRenderer r1 = new BarRenderer(); r1.setLegendItemToolTipGenerator(generator); BarRenderer r2 = null; try { r2 = (BarRenderer) r1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(r1 != r2); assertTrue(r1.getClass() == r2.getClass()); assertTrue(r1.equals(r2)); // check that the generator has been cloned assertTrue(r1.getLegendItemToolTipGenerator() != r2.getLegendItemToolTipGenerator());
CustomPieURLGenerator generator = new CustomPieURLGenerator(); PiePlot p1 = new PiePlot(); p1.setURLGenerator(generator); PiePlot p2 = null; try { p2 = (PiePlot) p1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(p1 != p2); assertTrue(p1.getClass() == p2.getClass()); assertTrue(p1.equals(p2)); // check that the URL generator has been cloned assertTrue(p1.getURLGenerator() != p2.getURLGenerator());

Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/chart/renderer/category/junit/AbstractCategoryItemRendererTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/chart/plot/junit/PiePlotTests.java
Method name: `void testCloning_LegendItemToolTipGenerator()` |  | Method name: `void testCloning_URLGenerator()`
Number of AST nodes: 10 |  | Number of AST nodes: 10

1

    StandardCategorySeriesLabelGenerator generator ↵

2

                    = new StandardCategorySeriesLabelGenerator("Series {0}");↵

3

            BarRenderer r1 = new BarRenderer↵

1

    CustomPieURLGenerator generator = new CustomPieURLGenerator();↵

4

    ();↵

2

            PiePlot p1 = new PiePlot();↵

5

            r1.setLegendItemToolTipGenerator(generator);↵

3

            p1.setURLGenerator(generator);↵

6

            BarRenderer r2 = null;↵

4

            PiePlot p2 = null;↵

7

            try {↵

5

            try {↵

8

                r2 = (BarRenderer) r1.clone();↵

6

                p2 = (PiePlot) p1.clone();↵

9

            }↵

7

            }↵

10

            catch (CloneNotSupportedException e) {↵

8

            catch (CloneNotSupportedException e) {↵

11

                e.printStackTrace();↵

9

                e.printStackTrace();↵

12

            }↵

10

            }↵

13

            assertTrue(r1 != r2);↵

11

            assertTrue(p1 != p2);↵

14

            assertTrue(r1.getClass() == r2.getClass());↵

12

            assertTrue(p1.getClass() == p2.getClass());↵

15

            assertTrue(r1.equals(r2));↵

13

            assertTrue(p1.equals(p2));↵

16

            ↵

14

            ↵

17

            // check that the generator has been cloned↵

15

            // check that the URL generator has been cloned↵

18

            assertTrue(r1.getLegendItemToolTipGenerator() ↵

16

            assertTrue(p1.get↵

19

                    != r2.getLegendItemToolTipGenerator());

17

    URLGenerator() != p2.getURLGenerator());

See real code fragment |  | See real code fragment

Summary
Number of common nesting structure subtrees | 1
Number of refactorable cases | 0
Number of non-refactorable cases | 1
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.1
Clones location | Clones are in different classes having the same super class
Number of node comparisons | 68

1. {Non-refactorable}

   Mapping Summary
   Number of mapped statements | 3
   Number of unmapped statements in the first code fragment | 7
   Number of unmapped statements in the second code fragment | 7
   Time elapsed for statement mapping (ms) | 3.6
   Clone type | Type 2

   Mapped Statements
   ID | Statement |  | ID | Statement
   --- | --- | --- | --- | ---

   1

       CustomPieURLGenerator generator = new CustomPieURLGenerator();

   1

       StandardCategorySeriesLabelGenerator generator = new StandardCategorySeriesLabelGenerator("Series {0}");

   2

       PiePlot p1 = new PiePlot();

   2

       BarRenderer r1 = new BarRenderer();

   3

       p1.setURLGenerator(generator);

   3

       r1.setLegendItemToolTipGenerator(generator);

   4

       PiePlot p2 = null;

   4

       BarRenderer r2 = null;

   5

       try

   5

       try

   6 | p2 = (PiePlot)p1.clone();

   Preondition Violations
   Unmatched statement p2=(PiePlot)p1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted

   6

       p2 = (PiePlot)p1.clone();

   6

       r2 = (BarRenderer)r1.clone();

   6 | r2 = (BarRenderer)r1.clone();

   Preondition Violations
   Unmatched statement r2=(BarRenderer)r1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted

   7

       assertTrue(p1 != p2);

   7

       assertTrue(r1 != r2);

   7 | assertTrue(r1 != r2);
   9 | assertTrue(p1.equals(p2));

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   r1 != r2 | p1.equals(p2) | TYPE_COMPATIBLE_REPLACEMENT

   9

       assertTrue(p1.equals(p2));

   8

       assertTrue(r1.getClass() == r2.getClass());

   9

       assertTrue(r1.equals(r2));

   9 | assertTrue(r1.equals(r2));
   8 | assertTrue(p1.getClass() == p2.getClass());

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   r1.equals(r2) | p1.getClass() == p2.getClass() | TYPE_COMPATIBLE_REPLACEMENT

   8

       assertTrue(p1.getClass() == p2.getClass());

   10

       assertTrue(p1.getURLGenerator() != p2.getURLGenerator());

   10

       assertTrue(r1.getLegendItemToolTipGenerator() != r2.getLegendItemToolTipGenerator());

   Precondition Violations (2)
   Row | Violation
   --- | ---
   1 | Unmatched statement p2=(PiePlot)p1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
   2 | Unmatched statement r2=(BarRenderer)r1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted