27-1-2

public class HighLowItemLabelGeneratorTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(HighLowItemLabelGeneratorTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public HighLowItemLabelGeneratorTests(String name) { super(name); } /** * Tests that the equals method can distinguish all fields. */ public void testEquals() { HighLowItemLabelGenerator g1 = new HighLowItemLabelGenerator(); HighLowItemLabelGenerator g2 = new HighLowItemLabelGenerator(); assertTrue(g1.equals(g2)); assertTrue(g2.equals(g1)); g1 = new HighLowItemLabelGenerator(new SimpleDateFormat("d-MMM-yyyy"), NumberFormat.getInstance()); assertFalse(g1.equals(g2)); g2 = new HighLowItemLabelGenerator(new SimpleDateFormat("d-MMM-yyyy"), NumberFormat.getInstance()); assertTrue(g1.equals(g2)); g1 = new HighLowItemLabelGenerator(new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.000")); assertFalse(g1.equals(g2)); g2 = new HighLowItemLabelGenerator(new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.000")); assertTrue(g1.equals(g2)); } /** * Simple check that hashCode is implemented. */ public void testHashCode() { HighLowItemLabelGenerator g1 = new HighLowItemLabelGenerator(); HighLowItemLabelGenerator g2 = new HighLowItemLabelGenerator(); assertTrue(g1.equals(g2)); assertTrue(g1.hashCode() == g2.hashCode()); } /** * Confirm that cloning works. */ public void testCloning() { HighLowItemLabelGenerator g1 = new HighLowItemLabelGenerator(); HighLowItemLabelGenerator g2 = null; try { g2 = (HighLowItemLabelGenerator) g1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(g1 != g2); assertTrue(g1.getClass() == g2.getClass()); assertTrue(g1.equals(g2)); } /** * Check to ensure that this class implements PublicCloneable. */ public void testPublicCloneable() { HighLowItemLabelGenerator g1 = new HighLowItemLabelGenerator(); assertTrue(g1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { HighLowItemLabelGenerator g1 = new HighLowItemLabelGenerator(); HighLowItemLabelGenerator g2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(g1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); g2 = (HighLowItemLabelGenerator) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(g1, g2);
public class IntervalCategoryLabelGeneratorTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(IntervalCategoryLabelGeneratorTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public IntervalCategoryLabelGeneratorTests(String name) { super(name); } /** * Tests the equals() method. */ public void testEquals() { IntervalCategoryItemLabelGenerator g1 = new IntervalCategoryItemLabelGenerator(); IntervalCategoryItemLabelGenerator g2 = new IntervalCategoryItemLabelGenerator(); assertTrue(g1.equals(g2)); assertTrue(g2.equals(g1)); g1 = new IntervalCategoryItemLabelGenerator("{3} - {4}", new DecimalFormat("0.000")); assertFalse(g1.equals(g2)); g2 = new IntervalCategoryItemLabelGenerator("{3} - {4}", new DecimalFormat("0.000")); assertTrue(g1.equals(g2)); g1 = new IntervalCategoryItemLabelGenerator("{3} - {4}", new SimpleDateFormat("d-MMM")); assertFalse(g1.equals(g2)); g2 = new IntervalCategoryItemLabelGenerator("{3} - {4}", new SimpleDateFormat("d-MMM")); assertTrue(g1.equals(g2)); } /** * Simple check that hashCode is implemented. */ public void testHashCode() { IntervalCategoryItemLabelGenerator g1 = new IntervalCategoryItemLabelGenerator(); IntervalCategoryItemLabelGenerator g2 = new IntervalCategoryItemLabelGenerator(); assertTrue(g1.equals(g2)); assertTrue(g1.hashCode() == g2.hashCode()); } /** * Confirm that cloning works. */ public void testCloning() { IntervalCategoryItemLabelGenerator g1 = new IntervalCategoryItemLabelGenerator(); IntervalCategoryItemLabelGenerator g2 = null; try { g2 = (IntervalCategoryItemLabelGenerator) g1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(g1 != g2); assertTrue(g1.getClass() == g2.getClass()); assertTrue(g1.equals(g2)); } /** * Check to ensure that this class implements PublicCloneable. */ public void testPublicCloneable() { IntervalCategoryItemLabelGenerator g1 = new IntervalCategoryItemLabelGenerator(); assertTrue(g1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { IntervalCategoryItemLabelGenerator g1 = new IntervalCategoryItemLabelGenerator("{3} - {4}", DateFormat.getInstance()); IntervalCategoryItemLabelGenerator g2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(g1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); g2 = (IntervalCategoryItemLabelGenerator) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(g1, g2);

Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/chart/labels/junit/HighLowItemLabelGeneratorTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/chart/labels/junit/IntervalCategoryLabelGeneratorTests.java
Method name: `` |  | Method name: ``
Number of AST nodes: 0 |  | Number of AST nodes: 0

1

    public class HighLowItemLabelGeneratorTests extends TestCase {↵

1

    public class IntervalCategoryLabelGeneratorTests 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(HighLowItemLabelGeneratorTests.class);↵

8

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

15

        public IntervalCategoryLabelGeneratorTests(String name) {↵

16

            super(name);↵

16

            super(name);↵

17

        }↵

17

        }↵

18

        /**↵

18

        /**↵

19

         * Tests that the equals method can distinguish all fields.↵

19

         * Tests the equals() method.↵

20

         */↵

20

         */↵

21

        public void testEquals() {↵

21

        public void testEquals() {↵

22

            HighLowItemLabelGenerator g1 = new HighLow↵

22

            IntervalCategoryItemLabelGenerator g1↵

23

    ItemLabelGenerator();↵

23

                    = new IntervalCategoryItemLabelGenerator();↵

24

            HighLowItemLabelGenerator g2 = new HighLow↵

24

            IntervalCategoryItemLabelGenerator g2↵

25

    ItemLabelGenerator();↵

25

                    = new IntervalCategoryItemLabelGenerator();↵

26

            assertTrue(g1.equals(g2));↵

26

            assertTrue(g1.equals(g2));↵

27

            assertTrue(g2.equals(g1));↵

27

            assertTrue(g2.equals(g1));↵

28

            g1 = new HighLowItemLabelGenerator(new SimpleDateFormat("d-MMM-yyyy"),↵

28

            g1 = new IntervalCategoryItemLabelGenerator("{3} - {4}",↵

29

                    NumberFormat.getInstance());↵

29

                    new DecimalFormat("0.000"));↵

30

            assertFalse(g1.equals(g2));↵

30

            assertFalse(g1.equals(g2));↵

31

            g2 = new HighLowItemLabelGenerator(new SimpleDateFormat("d-MMM-yyyy"),↵

31

            g2 = new IntervalCategoryItemLabelGenerator("{3} - {4}",↵

32

                    NumberFormat.getInstance());↵

32

                    new DecimalFormat("0.000"));↵

33

            assertTrue(g1.equals(g2));↵

33

            assertTrue(g1.equals(g2));↵

34

            g1 = new HighLowItemLabelGenerator(new SimpleDateFormat("d-MMM-yyyy"),↵

34

            g1 = new IntervalCategoryItemLabelGenerator("{3} - {4}",↵

35

                    new DecimalFormat("0.000"));↵

35

                    new SimpleDateFormat("d-MMM"));↵

36

            assertFalse(g1.equals(g2));↵

36

            assertFalse(g1.equals(g2));↵

37

            g2 = new HighLowItemLabelGenerator(new SimpleDateFormat("d-MMM-yyyy"),↵

37

            g2 = new IntervalCategoryItemLabelGenerator("{3} - {4}",↵

38

                    new DecimalFormat("0.000"));↵

38

                    new SimpleDateFormat("d-MMM"));↵

39

            assertTrue(g1.equals(g2));↵

39

            assertTrue(g1.equals(g2));↵

40

        }↵

40

        }↵

41

        /**↵

41

        /**↵

42

         * Simple check that hashCode is implemented.↵

42

         * Simple check that hashCode is implemented.↵

43

         */↵

43

         */↵

44

        public void testHashCode() {↵

44

        public void testHashCode() {↵

45

            HighLowItemLabelGenerator g1 = new HighLow↵

45

            IntervalCategoryItemLabelGenerator g1↵

46

    ItemLabelGenerator();↵

46

                    = new IntervalCategoryItemLabelGenerator();↵

47

            HighLowItemLabelGenerator g2 = new HighLow↵

47

            IntervalCategoryItemLabelGenerator g2↵

48

    ItemLabelGenerator();↵

48

                    = new IntervalCategoryItemLabelGenerator();↵

49

            assertTrue(g1.equals(g2));↵

49

            assertTrue(g1.equals(g2));↵

50

            assertTrue(g1.hashCode() == g2.hashCode());↵

50

            assertTrue(g1.hashCode() == g2.hashCode());↵

51

        }↵

51

        }↵

52

        /**↵

52

        /**↵

53

         * Confirm that cloning works.↵

53

         * Confirm that cloning works.↵

54

         */↵

54

         */↵

55

        public void testCloning() {↵

55

        public void testCloning() {↵

56

            HighLowItemLabelGenerator g1 = new HighLow↵

56

            IntervalCategoryItemLabelGenerator g1↵

57

    ItemLabelGenerator();↵

57

                    = new IntervalCategoryItemLabelGenerator();↵

58

            HighLowItemLabelGenerator g2 = null;↵

58

            IntervalCategoryItemLabelGenerator g2 = null;↵

59

            try {↵

59

            try {↵

60

                g2 = (HighLowItemLabelGenerator) g1.clone();↵

60

                g2 = (IntervalCategoryItemLabelGenerator) g1.clone();↵

61

            }↵

61

            }↵

62

            catch (CloneNotSupportedException e) {↵

62

            catch (CloneNotSupportedException e) {↵

63

                e.printStackTrace();↵

63

                e.printStackTrace();↵

64

            }↵

64

            }↵

65

            assertTrue(g1 != g2);↵

65

            assertTrue(g1 != g2);↵

66

            assertTrue(g1.getClass() == g2.getClass());↵

66

            assertTrue(g1.getClass() == g2.getClass());↵

67

            assertTrue(g1.equals(g2));↵

67

            assertTrue(g1.equals(g2));↵

68

        }↵

68

        }↵

69

        /**↵

69

        /**↵

70

         * Check to ensure that this class implements PublicCloneable.↵

70

         * Check to ensure that this class implements PublicCloneable.↵

71

         */↵

71

         */↵

72

        public void testPublicCloneable() {↵

72

        public void testPublicCloneable() {↵

73

            HighLowItemLabelGenerator g1 = new HighLow↵

73

            IntervalCategoryItemLabelGenerator g1↵

74

    ItemLabelGenerator();↵

74

                    = new IntervalCategoryItemLabelGenerator();↵

75

            assertTrue(g1 instanceof PublicCloneable);↵

75

            assertTrue(g1 instanceof PublicCloneable);↵

76

        }↵

76

        }↵

77

        /**↵

77

        /**↵

78

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

78

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

79

         */↵

79

         */↵

80

        public void testSerialization() {↵

80

        public void testSerialization() {↵

81

            HighLowItemLabelGenerator g1 = new HighLowItemLabelGenerator();↵

81

            IntervalCategoryItemLabelGenerator g1↵

82

            HighLow↵

82

                    = new IntervalCategoryItemLabelGenerator("{3} - {4}",↵

83

                    DateFormat.getInstance());↵

83

    ItemLabelGenerator g2 = null;↵

84

            IntervalCategoryItemLabelGenerator g2 = null;↵

84

            try {↵

85

            try {↵

85

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

86

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

86

                ObjectOutput out = new ObjectOutputStream(buffer);↵

87

                ObjectOutput out = new ObjectOutputStream(buffer);↵

87

                out.writeObject(g1);↵

88

                out.writeObject(g1);↵

88

                out.close();↵

89

                out.close();↵

89

                ObjectInput in = new ObjectInputStream(↵

90

                ObjectInput in = new ObjectInputStream(↵

90

                        new ByteArrayInputStream(buffer.toByteArray()));↵

91

                        new ByteArrayInputStream(buffer.toByteArray()));↵

91

                g2 = (HighLowItemLabelGenerator) in.readObject();↵

92

                g2 = (IntervalCategoryItemLabelGenerator) in.readObject();↵

92

                in.close();↵

93

                in.close();↵

93

            }↵

94

            }↵

94

            catch (Exception e) {↵

95

            catch (Exception e) {↵

95

                e.printStackTrace();↵

96

                e.printStackTrace();↵

96

            }↵

97

            }↵

97

            assertEquals(g1, g2);

98

            assertEquals(g1, g2);

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