20-1-2

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);
public class StandardCategorySeriesLabelGeneratorTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(StandardCategorySeriesLabelGeneratorTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public StandardCategorySeriesLabelGeneratorTests(String name) { super(name); } /** * Some checks for the generalLabel() method. */ public void testGenerateLabel() { StandardCategorySeriesLabelGenerator g = new StandardCategorySeriesLabelGenerator("{0}"); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, "R0", "C0"); dataset.addValue(2.0, "R0", "C1"); dataset.addValue(3.0, "R1", "C0"); dataset.addValue(null, "R1", "C1"); String s = g.generateLabel(dataset, 0); assertEquals("R0", s); } /** * Some checks for the equals() method. */ public void testEquals() { StandardCategorySeriesLabelGenerator g1 = new StandardCategorySeriesLabelGenerator(); StandardCategorySeriesLabelGenerator g2 = new StandardCategorySeriesLabelGenerator(); assertTrue(g1.equals(g2)); assertTrue(g2.equals(g1)); g1 = new StandardCategorySeriesLabelGenerator("{1}"); assertFalse(g1.equals(g2)); g2 = new StandardCategorySeriesLabelGenerator("{1}"); assertTrue(g1.equals(g2)); } /** * Simple check that hashCode is implemented. */ public void testHashCode() { StandardCategorySeriesLabelGenerator g1 = new StandardCategorySeriesLabelGenerator(); StandardCategorySeriesLabelGenerator g2 = new StandardCategorySeriesLabelGenerator(); assertTrue(g1.equals(g2)); assertTrue(g1.hashCode() == g2.hashCode()); } /** * Confirm that cloning works. */ public void testCloning() { StandardCategorySeriesLabelGenerator g1 = new StandardCategorySeriesLabelGenerator("{1}"); StandardCategorySeriesLabelGenerator g2 = null; try { g2 = (StandardCategorySeriesLabelGenerator) 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() { StandardCategorySeriesLabelGenerator g1 = new StandardCategorySeriesLabelGenerator("{1}"); assertTrue(g1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { StandardCategorySeriesLabelGenerator g1 = new StandardCategorySeriesLabelGenerator("{2}"); StandardCategorySeriesLabelGenerator 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 = (StandardCategorySeriesLabelGenerator) 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/IntervalCategoryLabelGeneratorTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/chart/labels/junit/StandardCategorySeriesLabelGeneratorTests.java
Method name: `` |  | Method name: ``
Number of AST nodes: 0 |  | Number of AST nodes: 0

1

    public class IntervalCategoryLabelGeneratorTests extends TestCase {↵

1

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

8

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

15

        public StandardCategorySeriesLabelGeneratorTests(String name) {↵

16

            super(name);↵

16

            super(name);↵

17

        }↵

17

        }↵

18

        /**↵

18

        /**↵

19

         * Tests the equals() method.↵

19

         * Some checks for the generalLabel() method.↵

20

         */↵

20

         */↵

21

        public void testEquals() {↵

21

        public void testGenerateLabel() {↵

22

            IntervalCategoryItemLabelGenerator g1↵

22

            StandardCategorySeriesLabelGenerator g↵

23

                    = new IntervalCategoryItemLabelGenerator();↵

23

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

24

            IntervalCategoryItemLabelGenerator g2↵

24

            ↵

25

                    = new IntervalCategoryItemLabelGenerator();↵

26

            assertTrue(g1.equals(g2));↵

27

            assertTrue(g2.equals(g1));↵

25

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();↵

26

            dataset.addValue(1.0, "R0", "C0");↵

27

            dataset.addValue(2.0, "R0", "C1");↵

28

            dataset.addValue(3.0, "R1", "C0");↵

29

            dataset.addValue(null, "R1", "C1");↵

30

            String s = g.generateLabel(dataset, 0);↵

31

            assertEquals("R0", s);↵

32

        }↵

33

        /**↵

34

         * Some checks for the equals() method.↵

28

            g1 = new Interval↵

35

         */↵

36

        public void testEquals() {↵

29

    CategoryItemLabelGenerator("{3} - {4}",↵

37

            StandardCategorySeriesLabelGenerator g1↵

30

                    new DecimalFormat("0.000"));↵

38

                    = new ↵

31

            assertFalse(g1.equals(g2));↵

39

    StandardCategorySeriesLabelGenerator();↵

40

            StandardCategorySeriesLabelGenerator g2↵

32

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

41

                    = new StandardCategorySeriesLabelGenerator(↵

33

                    new DecimalFormat("0.000"↵

42

    );↵

34

    ));↵

43

            assertTrue(g1.equals(g2));↵

35

            assertTrue(g1.equals(g2));↵

44

            assertTrue(g2.equals(g1));↵

36

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

45

            g1 = new StandardCategorySeriesLabelGenerator("{↵

37

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

46

    1}");↵

38

            assertFalse(g1.equals(g2));↵

47

            assertFalse(g1.equals(g2));↵

39

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

48

            g2 = new StandardCategorySeriesLabelGenerator("{↵

40

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

49

    1}");↵

41

            assertTrue(g1.equals(g2));↵

50

            assertTrue(g1.equals(g2));↵

42

        }↵

51

        }↵

43

        /**↵

52

        /**↵

44

         * Simple check that hashCode is implemented.↵

53

         * Simple check that hashCode is implemented.↵

45

         */↵

54

         */↵

46

        public void testHashCode() {↵

55

        public void testHashCode() {↵

47

            IntervalCategoryItemLabelGenerator g1↵

56

            StandardCategorySeriesLabelGenerator g1↵

48

                    = new IntervalCategoryItemLabelGenerator();↵

57

                    = new StandardCategorySeriesLabelGenerator();↵

49

            IntervalCategoryItemLabelGenerator g2↵

58

            StandardCategorySeriesLabelGenerator g2↵

50

                    = new IntervalCategoryItemLabelGenerator();↵

59

                    = new StandardCategorySeriesLabelGenerator();↵

51

            assertTrue(g1.equals(g2));↵

60

            assertTrue(g1.equals(g2));↵

52

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

61

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

53

        }↵

62

        }↵

54

        /**↵

63

        /**↵

55

         * Confirm that cloning works.↵

64

         * Confirm that cloning works.↵

56

         */↵

65

         */↵

57

        public void testCloning() {↵

66

        public void testCloning() {↵

58

            IntervalCategoryItemLabelGenerator g1↵

67

            StandardCategorySeriesLabelGenerator g1↵

59

                    = new IntervalCategoryItemLabelGenerator();↵

68

                    = new StandardCategorySeriesLabelGenerator("{1}");↵

60

            IntervalCategoryItemLabelGenerator g2 = null;↵

69

            StandardCategorySeriesLabelGenerator g2 = null;↵

61

            try {↵

70

            try {↵

62

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

71

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

63

            }↵

72

            }↵

64

            catch (CloneNotSupportedException e) {↵

73

            catch (CloneNotSupportedException e) {↵

65

                e.printStackTrace();↵

74

                e.printStackTrace();↵

66

            }↵

75

            }↵

67

            assertTrue(g1 != g2);↵

76

            assertTrue(g1 != g2);↵

68

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

77

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

69

            assertTrue(g1.equals(g2));↵

78

            assertTrue(g1.equals(g2));↵

70

        }↵

79

        }↵

71

        /**↵

80

        /**↵

72

         * Check to ensure that this class implements PublicCloneable.↵

81

         * Check to ensure that this class implements PublicCloneable.↵

73

         */↵

82

         */↵

74

        public void testPublicCloneable() {↵

83

        public void testPublicCloneable() {↵

75

            IntervalCategoryItemLabelGenerator g1↵

84

            StandardCategorySeriesLabelGenerator g1↵

76

                    = new IntervalCategoryItemLabelGenerator();↵

85

                    = new StandardCategorySeriesLabelGenerator("{1}");↵

77

            assertTrue(g1 instanceof PublicCloneable);↵

86

            assertTrue(g1 instanceof PublicCloneable);↵

78

        }↵

87

        }↵

79

        /**↵

88

        /**↵

80

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

89

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

81

         */↵

90

         */↵

82

        public void testSerialization() {↵

91

        public void testSerialization() {↵

83

            IntervalCategoryItemLabelGenerator g1↵

92

            StandardCategorySeriesLabelGenerator g1↵

84

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

93

                    = new StandardCategorySeriesLabelGenerator("{↵

85

                    DateFormat.getInstance());↵

86

            Interval↵

94

    2}");↵

87

    CategoryItemLabelGenerator g2 = null;↵

95

            StandardCategorySeriesLabelGenerator g2 = null;↵

88

            try {↵

96

            try {↵

89

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

97

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

90

                ObjectOutput out = new ObjectOutputStream(buffer);↵

98

                ObjectOutput out = new ObjectOutputStream(buffer);↵

91

                out.writeObject(g1);↵

99

                out.writeObject(g1);↵

92

                out.close();↵

100

                out.close();↵

93

                ObjectInput in = new ObjectInputStream(↵

101

                ObjectInput in = new ObjectInputStream(↵

94

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

102

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

95

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

103

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

96

                in.close();↵

104

                in.close();↵

97

            }↵

105

            }↵

98

            catch (Exception e) {↵

106

            catch (Exception e) {↵

99

                e.printStackTrace();↵

107

                e.printStackTrace();↵

100

            }↵

108

            }↵

101

            assertEquals(g1, g2);

109

            assertEquals(g1, g2);↵

110

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