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)
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);
27
);
31
        assertEquals("R0", s);
28
    
32
    }
29
    assertTrue(g2.equals(g1));
33
    
34
/**
35
     * Some checks for the equals() method.
30
        g1 = new Interval
36
     */
37
    public void testEquals() {
31
CategoryItemLabelGenerator("{3} - {4}",
38
        StandardCategorySeriesLabelGenerator g1
32
                new DecimalFormat("0.000"));
39
                = new 
33
        assertFalse(g1.equals(g2));
40
StandardCategorySeriesLabelGenerator();
41
        StandardCategorySeriesLabelGenerator g2
34
        g2 = new IntervalCategoryItemLabelGenerator("{3} - {4}",
42
                = new StandardCategorySeriesLabelGenerator(
35
                new DecimalFormat("0.000"
43
);
36
));
44
        assertTrue(g1.equals(g2));
37
        assertTrue(g1.equals(g2));
45
        assertTrue(g2.equals(g1));
38
        g1 = new IntervalCategoryItemLabelGenerator("{3} - {4}",
46
        g1 = new StandardCategorySeriesLabelGenerator("{
39
                new SimpleDateFormat("d-MMM"));
47
1}");
40
        assertFalse(g1.equals(g2));
48
        assertFalse(g1.equals(g2));
41
        g2 = new IntervalCategoryItemLabelGenerator("{3} - {4}",
49
        g2 = new StandardCategorySeriesLabelGenerator("{
42
                new SimpleDateFormat("d-MMM"));
50
1}");
43
        assertTrue(g1.equals(g2));
51
        assertTrue(g1.equals(g2));
44
    }
52
    }
45
    /**
53
    /**
46
     * Simple check that hashCode is implemented.
54
     * Simple check that hashCode is implemented.
47
     */
55
     */
48
    public void testHashCode() {
56
    public void testHashCode() {
49
        IntervalCategoryItemLabelGenerator g1
57
        StandardCategorySeriesLabelGenerator g1
50
                = new IntervalCategoryItemLabelGenerator();
58
                = new StandardCategorySeriesLabelGenerator();
51
        IntervalCategoryItemLabelGenerator g2
59
        StandardCategorySeriesLabelGenerator g2
52
                = new IntervalCategoryItemLabelGenerator();
60
                = new StandardCategorySeriesLabelGenerator();
53
        assertTrue(g1.equals(g2));
61
        assertTrue(g1.equals(g2));
54
        assertTrue(g1.hashCode() == g2.hashCode());
62
        assertTrue(g1.hashCode() == g2.hashCode());
55
    }
63
    }
56
    /**
64
    /**
57
     * Confirm that cloning works.
65
     * Confirm that cloning works.
58
     */
66
     */
59
    public void testCloning() {
67
    public void testCloning() {
60
        IntervalCategoryItemLabelGenerator g1
68
        StandardCategorySeriesLabelGenerator g1
61
                = new IntervalCategoryItemLabelGenerator();
69
                = new StandardCategorySeriesLabelGenerator("{1}");
62
        IntervalCategoryItemLabelGenerator g2 = null;
70
        StandardCategorySeriesLabelGenerator g2 = null;
63
        try {
71
        try {
64
            g2 = (IntervalCategoryItemLabelGenerator) g1.clone();
72
            g2 = (StandardCategorySeriesLabelGenerator) g1.clone();
65
        }
73
        }
66
        catch (CloneNotSupportedException e) {
74
        catch (CloneNotSupportedException e) {
67
            e.printStackTrace();
75
            e.printStackTrace();
68
        }
76
        }
69
        assertTrue(g1 != g2);
77
        assertTrue(g1 != g2);
70
        assertTrue(g1.getClass() == g2.getClass());
78
        assertTrue(g1.getClass() == g2.getClass());
71
        assertTrue(g1.equals(g2));
79
        assertTrue(g1.equals(g2));
72
    }
80
    }
73
    /**
81
    /**
74
     * Check to ensure that this class implements PublicCloneable.
82
     * Check to ensure that this class implements PublicCloneable.
75
     */
83
     */
76
    public void testPublicCloneable() {
84
    public void testPublicCloneable() {
77
        IntervalCategoryItemLabelGenerator g1
85
        StandardCategorySeriesLabelGenerator g1
78
                = new IntervalCategoryItemLabelGenerator();
86
                = new StandardCategorySeriesLabelGenerator("{1}");
79
        assertTrue(g1 instanceof PublicCloneable);
87
        assertTrue(g1 instanceof PublicCloneable);
80
    }
88
    }
81
    /**
89
    /**
82
     * Serialize an instance, restore it, and check for equality.
90
     * Serialize an instance, restore it, and check for equality.
83
     */
91
     */
84
    public void testSerialization() {
92
    public void testSerialization() {
85
        IntervalCategoryItemLabelGenerator g1
93
        StandardCategorySeriesLabelGenerator g1
86
                = new IntervalCategoryItemLabelGenerator("{3} - {4}",
94
                = new StandardCategorySeriesLabelGenerator("{
87
                DateFormat.getInstance());
88
        Interval
95
2}");
89
CategoryItemLabelGenerator g2 = null;
96
        StandardCategorySeriesLabelGenerator g2 = null;
90
        try {
97
        try {
91
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
98
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
92
            ObjectOutput out = new ObjectOutputStream(buffer);
99
            ObjectOutput out = new ObjectOutputStream(buffer);
93
            out.writeObject(g1);
100
            out.writeObject(g1);
94
            out.close();
101
            out.close();
95
            ObjectInput in = new ObjectInputStream(
102
            ObjectInput in = new ObjectInputStream(
96
                    new ByteArrayInputStream(buffer.toByteArray()));
103
                    new ByteArrayInputStream(buffer.toByteArray()));
97
            g2 = (IntervalCategoryItemLabelGenerator) in.readObject();
104
            g2 = (StandardCategorySeriesLabelGenerator) in.readObject();
98
            in.close();
105
            in.close();
99
        }
106
        }
100
        catch (Exception e) {
107
        catch (Exception e) {
101
            e.printStackTrace();
108
            e.printStackTrace();
102
        }
109
        }
103
        assertEquals(g1, g2)
110
        assertEquals(g1, g2)
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0