39-1-2

public class StackedBarRendererTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(StackedBarRendererTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public StackedBarRendererTests(String name) { super(name); } /** * Check that the equals() method distinguishes all fields. */ public void testEquals() { StackedBarRenderer r1 = new StackedBarRenderer(); StackedBarRenderer r2 = new StackedBarRenderer(); assertTrue(r1.equals(r2)); assertTrue(r2.equals(r1)); r1.setRenderAsPercentages(true); assertFalse(r1.equals(r2)); r2.setRenderAsPercentages(true); assertTrue(r1.equals(r2)); } /** * Two objects that are equal are required to return the same hashCode. */ public void testHashCode() { StackedBarRenderer r1 = new StackedBarRenderer(); StackedBarRenderer r2 = new StackedBarRenderer(); assertTrue(r1.equals(r2)); int h1 = r1.hashCode(); int h2 = r2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ public void testCloning() { StackedBarRenderer r1 = new StackedBarRenderer(); StackedBarRenderer r2 = null; try { r2 = (StackedBarRenderer) r1.clone(); } catch (CloneNotSupportedException e) { System.err.println("Failed to clone."); } assertTrue(r1 != r2); assertTrue(r1.getClass() == r2.getClass()); assertTrue(r1.equals(r2)); } /** * Check that this class implements PublicCloneable. */ public void testPublicCloneable() { StackedBarRenderer r1 = new StackedBarRenderer(); assertTrue(r1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { StackedBarRenderer r1 = new StackedBarRenderer(); StackedBarRenderer r2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(r1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); r2 = (StackedBarRenderer) in.readObject(); in.close(); } catch (Exception e) { System.out.println(e.toString()); } assertEquals(r1, r2);
public class VectorRendererTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(VectorRendererTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public VectorRendererTests(String name) { super(name); } /** * Test that the equals() method distinguishes all fields. */ public void testEquals() { // default instances VectorRenderer r1 = new VectorRenderer(); VectorRenderer r2 = new VectorRenderer(); assertTrue(r1.equals(r2)); assertTrue(r2.equals(r1)); // check that super class fields are being looked at... r1.setSeriesFillPaint(0, Color.green); assertFalse(r1.equals(r2)); r2.setSeriesFillPaint(0, Color.green); assertTrue(r1.equals(r2)); } /** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { VectorRenderer r1 = new VectorRenderer(); VectorRenderer r2 = new VectorRenderer(); assertTrue(r1.equals(r2)); int h1 = r1.hashCode(); int h2 = r2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ public void testCloning() { VectorRenderer r1 = new VectorRenderer(); VectorRenderer r2 = null; try { r2 = (VectorRenderer) r1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(r1 != r2); assertTrue(r1.getClass() == r2.getClass()); assertTrue(r1.equals(r2)); } /** * Verify that this class implements {@link PublicCloneable}. */ public void testPublicCloneable() { VectorRenderer r1 = new VectorRenderer(); assertTrue(r1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { VectorRenderer r1 = new VectorRenderer(); VectorRenderer r2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(r1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); r2 = (VectorRenderer) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(r1, r2);

Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/chart/renderer/category/junit/StackedBarRendererTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/chart/renderer/xy/junit/VectorRendererTests.java
Method name: `` |  | Method name: ``
Number of AST nodes: 0 |  | Number of AST nodes: 0

1

    public class StackedBarRendererTests extends TestCase {↵

1

    public class VectorRendererTests extends TestCase {↵

2

        /**↵

2

        /**↵

3

         * Returns the tests as a test suite.↵

3

         * Returns the tests as a test suite.↵

4

         *↵

4

         *↵

5

         * @return The test suite.↵

5

         * @return The test suite.↵

6

         */↵

6

         */↵

7

        public static Test suite() {↵

7

        public static Test suite() {↵

8

            return new TestSuite(StackedBarRendererTests.class);↵

8

            return new TestSuite(VectorRendererTests.class);↵

9

        }↵

9

        }↵

10

        /**↵

10

        /**↵

11

         * Constructs a new set of tests.↵

11

         * Constructs a new set of tests.↵

12

         *↵

12

         *↵

13

         * @param name  the name of the tests.↵

13

         * @param name  the name of the tests.↵

14

         */↵

14

         */↵

15

        public StackedBarRendererTests(String name) {↵

15

        public VectorRendererTests(String name) {↵

16

            super(name);↵

16

            super(name);↵

17

        }↵

17

        }↵

18

        /**↵

18

        /**↵

19

         * Check that the equals() method distinguishes all fields.↵

19

         * Test that the equals() method distinguishes all fields.↵

20

         */↵

20

         */↵

21

        public void testEquals() {↵

21

        public void testEquals() {↵

22

            StackedBa↵

22

            // default instances↵

23

    rRenderer r1 = new StackedBarRenderer();↵

23

            VectorRenderer r1 = new VectorRenderer();↵

24

            StackedBarRenderer r2 = new StackedBarRenderer();↵

24

            VectorRenderer r2 = new VectorRenderer();↵

25

            assertTrue(r1.equals(r2));↵

25

            assertTrue(r1.equals(r2));↵

26

            assertTrue(r2.equals(r1));↵

26

            assertTrue(r2.equals(r1));↵

27

            r1.setRenderAsPercentages(true↵

27

            // check that super class fields are being looked at...↵

28

    );↵

28

            r1.setSeriesFillPaint(0, Color.green);↵

29

            assertFalse(r1.equals(r2));↵

29

            assertFalse(r1.equals(r2));↵

30

            r2.setRenderAsPercentages(true);↵

30

            r2.setSeriesFillPaint(0, Color.green);↵

31

            assertTrue(r1.equals(r2));↵

31

            assertTrue(r1.equals(r2));↵

32

        }↵

32

        }↵

33

        /**↵

33

        /**↵

34

         * Two objects that are equal are required to return the same hashCode.↵

34

         * Two objects that are equal are required to return the same hashCode.↵

35

         */↵

35

         */↵

36

        public void testHashCode() {↵

36

        public void testHashcode() {↵

37

            StackedBarRenderer r1 = new StackedBarRenderer();↵

37

            VectorRenderer r1 = new VectorRenderer();↵

38

            StackedBarRenderer r2 = new StackedBarRenderer();↵

38

            VectorRenderer r2 = new VectorRenderer();↵

39

            assertTrue(r1.equals(r2));↵

39

            assertTrue(r1.equals(r2));↵

40

            int h1 = r1.hashCode();↵

40

            int h1 = r1.hashCode();↵

41

            int h2 = r2.hashCode();↵

41

            int h2 = r2.hashCode();↵

42

            assertEquals(h1, h2);↵

42

            assertEquals(h1, h2);↵

43

        }↵

43

        }↵

44

        /**↵

44

        /**↵

45

         * Confirm that cloning works.↵

45

         * Confirm that cloning works.↵

46

         */↵

46

         */↵

47

        public void testCloning() {↵

47

        public void testCloning() {↵

48

            StackedBarRenderer r1 = new StackedBarRenderer();↵

48

            VectorRenderer r1 = new VectorRenderer();↵

49

            StackedBarRenderer r2 = null;↵

49

            VectorRenderer r2 = null;↵

50

            try {↵

50

            try {↵

51

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

51

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

52

            }↵

52

            }↵

53

            catch (CloneNotSupportedException e) {↵

53

            catch (CloneNotSupportedException e) {↵

54

                System.err.println("Failed to clone.");↵

54

                e.printStackTrace();↵

55

            }↵

55

            }↵

56

            assertTrue(r1 != r2);↵

56

            assertTrue(r1 != r2);↵

57

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

57

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

58

            assertTrue(r1.equals(r2));↵

58

            assertTrue(r1.equals(r2));↵

59

        }↵

59

        }↵

60

        /**↵

60

        /**↵

61

         * Check that this class implements PublicCloneable.↵

61

         * Verify that this class implements {@link PublicCloneable}.↵

62

         */↵

62

         */↵

63

        public void testPublicCloneable() {↵

63

        public void testPublicCloneable() {↵

64

            StackedBarRenderer r1 = new StackedBarRenderer();↵

64

            VectorRenderer r1 = new VectorRenderer();↵

65

            assertTrue(r1 instanceof PublicCloneable);↵

65

            assertTrue(r1 instanceof PublicCloneable);↵

66

        }↵

66

        }↵

67

        /**↵

67

        /**↵

68

         * Serialize an instance, restore it, and check for equality.↵

68

         * Serialize an instance, restore it, and check for equality.↵

69

         */↵

69

         */↵

70

        public void testSerialization() {↵

70

        public void testSerialization() {↵

71

            StackedBarRenderer r1 = new StackedBarRenderer();↵

71

            VectorRenderer r1 = new VectorRenderer();↵

72

            StackedBarRenderer r2 = null;↵

72

            VectorRenderer r2 = null;↵

73

            try {↵

73

            try {↵

74

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

74

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

75

                ObjectOutput out = new ObjectOutputStream(buffer);↵

75

                ObjectOutput out = new ObjectOutputStream(buffer);↵

76

                out.writeObject(r1);↵

76

                out.writeObject(r1);↵

77

                out.close();↵

77

                out.close();↵

78

                ObjectInput in = new ObjectInputStream(↵

78

                ObjectInput in = new ObjectInputStream(↵

79

                    new ByteArrayInputStream(buffer.toByteArray())↵

79

                        new ByteArrayInputStream(buffer.toByteArray())↵

80

                );↵

80

    );↵

81

                r2 = (StackedBarRenderer) in.readObject();↵

81

                r2 = (VectorRenderer) in.readObject();↵

82

                in.close();↵

82

                in.close();↵

83

            }↵

83

            }↵

84

            catch (Exception e) {↵

84

            catch (Exception e) {↵

85

                System.out.println(e.toString());↵

85

                e.printStackTrace();↵

86

            }↵

86

            }↵

87

            assertEquals(r1, r2);

87

            assertEquals(r1, r2);↵

88

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