public class BoxAndWhiskerXYToolTipGeneratorTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(BoxAndWhiskerXYToolTipGeneratorTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public BoxAndWhiskerXYToolTipGeneratorTests(String name) { super(name); } /** * A series of tests for the equals() method. */ public void testEquals() { // standard test BoxAndWhiskerXYToolTipGenerator g1 = new BoxAndWhiskerXYToolTipGenerator(); BoxAndWhiskerXYToolTipGenerator g2 = new BoxAndWhiskerXYToolTipGenerator(); assertTrue(g1.equals(g2)); assertTrue(g2.equals(g1)); // tooltip format g1 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0.0")); g2 = new BoxAndWhiskerXYToolTipGenerator("{1} {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0.0")); assertFalse(g1.equals(g2)); g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0.0")); assertTrue(g1.equals(g2)); // date format g1 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0.0")); g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}", new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.0")); assertFalse(g1.equals(g2)); g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0.0")); assertTrue(g1.equals(g2)); // Y format g1 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0.0")); g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0.00")); assertFalse(g1.equals(g2)); g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0.0")); assertTrue(g1.equals(g2)); } /** * Simple check that hashCode is implemented. */ public void testHashCode() { BoxAndWhiskerXYToolTipGenerator g1 = new BoxAndWhiskerXYToolTipGenerator(); BoxAndWhiskerXYToolTipGenerator g2 = new BoxAndWhiskerXYToolTipGenerator(); assertTrue(g1.equals(g2)); assertTrue(g1.hashCode() == g2.hashCode()); } /** * Confirm that cloning works. */ public void testCloning() { BoxAndWhiskerXYToolTipGenerator g1 = new BoxAndWhiskerXYToolTipGenerator(); BoxAndWhiskerXYToolTipGenerator g2 = null; try { g2 = (BoxAndWhiskerXYToolTipGenerator) 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() { BoxAndWhiskerXYToolTipGenerator g1 = new BoxAndWhiskerXYToolTipGenerator(); assertTrue(g1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { BoxAndWhiskerXYToolTipGenerator g1 = new BoxAndWhiskerXYToolTipGenerator(); BoxAndWhiskerXYToolTipGenerator 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 = (BoxAndWhiskerXYToolTipGenerator) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(g1, g2)
public class StandardCategoryToolTipGeneratorTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(StandardCategoryToolTipGeneratorTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public StandardCategoryToolTipGeneratorTests(String name) { super(name); } /** * Tests the equals() method. */ public void testEquals() { StandardCategoryToolTipGenerator g1 = new StandardCategoryToolTipGenerator(); StandardCategoryToolTipGenerator g2 = new StandardCategoryToolTipGenerator(); assertTrue(g1.equals(g2)); assertTrue(g2.equals(g1)); g1 = new StandardCategoryToolTipGenerator("{0}", new DecimalFormat("0.000")); assertFalse(g1.equals(g2)); g2 = new StandardCategoryToolTipGenerator("{0}", new DecimalFormat("0.000")); assertTrue(g1.equals(g2)); g1 = new StandardCategoryToolTipGenerator("{1}", new DecimalFormat("0.000")); assertFalse(g1.equals(g2)); g2 = new StandardCategoryToolTipGenerator("{1}", new DecimalFormat("0.000")); assertTrue(g1.equals(g2)); g1 = new StandardCategoryToolTipGenerator("{2}", new SimpleDateFormat("d-MMM")); assertFalse(g1.equals(g2)); g2 = new StandardCategoryToolTipGenerator("{2}", new SimpleDateFormat("d-MMM")); assertTrue(g1.equals(g2)); } /** * Simple check that hashCode is implemented. */ public void testHashCode() { StandardCategoryToolTipGenerator g1 = new StandardCategoryToolTipGenerator(); StandardCategoryToolTipGenerator g2 = new StandardCategoryToolTipGenerator(); assertTrue(g1.equals(g2)); assertTrue(g1.hashCode() == g2.hashCode()); } /** * Confirm that cloning works. */ public void testCloning() { StandardCategoryToolTipGenerator g1 = new StandardCategoryToolTipGenerator(); StandardCategoryToolTipGenerator g2 = null; try { g2 = (StandardCategoryToolTipGenerator) 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() { StandardCategoryToolTipGenerator g1 = new StandardCategoryToolTipGenerator(); assertTrue(g1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { StandardCategoryToolTipGenerator g1 = new StandardCategoryToolTipGenerator("{2}", DateFormat.getInstance()); StandardCategoryToolTipGenerator 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 = (StandardCategoryToolTipGenerator) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(g1, g2); } /** * A test for bug 1481087. */ public void testEquals1481087() { StandardCategoryToolTipGenerator g1 = new StandardCategoryToolTipGenerator("{0}", new DecimalFormat("0.00")); StandardCategoryItemLabelGenerator g2 = new StandardCategoryItemLabelGenerator("{0}", new DecimalFormat("0.00")); assertFalse(g1.equals(g2))
Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/chart/labels/junit/BoxAndWhiskerXYToolTipGeneratorTests.java File path: /jfreechart-1.0.10/tests/org/jfree/chart/labels/junit/StandardCategoryToolTipGeneratorTests.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class BoxAndWhiskerXYToolTipGeneratorTests extends TestCase {
1
public class StandardCategoryToolTipGeneratorTests 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(BoxAndWhiskerXYToolTipGeneratorTests.class);
8
        return new TestSuite(StandardCategoryToolTipGeneratorTests.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 BoxAndWhiskerXYToolTipGeneratorTests(String name) {
15
    public StandardCategoryToolTipGeneratorTests(String name) {
16
        super(name);
16
        super(name);
17
    }
17
    }
18
    /**
18
    /**
19
     * A series of tests for the equals() method.
19
     * Tests the equals() method.
20
     */
20
     */
21
    public void testEquals() {
21
    public void testEquals() {
22
        // standard test
22
        Standard
23
        BoxAndWhiskerXYToolTipGenerator g1
23
CategoryToolTipGenerator g1
24
                = new BoxAndWhiskerXYToolTipGenerator();
24
                = new StandardCategoryToolTipGenerator();
25
        BoxAndWhiskerXYToolTipGenerator g2
25
        StandardCategoryToolTipGenerator g2
26
                = new BoxAndWhiskerXYToolTipGenerator();
26
                = new StandardCategoryToolTipGenerator();
27
        assertTrue(g1.equals(g2));
27
        assertTrue(g1.equals(g2));
28
        assertTrue(g2.equals(g1));
28
        assertTrue(g2.equals(g1));
29
        // tooltip format
29
        
30
        g1 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
31
                new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
32
        g2 = new BoxAndWhiskerXYToolTipGenerator("{1} {2}",
30
g1 = new StandardCategoryToolTipGenerator("{0}",
33
                new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
31
                new DecimalFormat("0.000"));
34
        assertFalse(g1.equals(g2));
32
        assertFalse(g1.equals(g2));
35
        g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
33
        g2 = new StandardCategoryToolTipGenerator("{0}",
36
                new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
34
                new DecimalFormat("0.000"));
37
        assertTrue(g1.equals(g2));
35
        assertTrue(g1.equals(g2));
38
        // date format
36
        
39
        g1 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
40
                new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
41
        g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
37
g1 = new StandardCategoryToolTipGenerator("{1}",
42
                new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.0"));
38
                new DecimalFormat("0.000"));
43
        assertFalse(g1.equals(g2));
39
        assertFalse(g1.equals(g2));
44
        g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
40
        g2 = new StandardCategoryToolTipGenerator("{1}",
45
                new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
41
                new DecimalFormat("0.000"));
46
        assertTrue(g1.equals(g2));
42
        assertTrue(g1.equals(g2));
47
        // Y format
43
        
48
        g1 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
49
                new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
50
        g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
44
g1 = new StandardCategoryToolTipGenerator("{2}",
51
                new SimpleDateFormat("yyyy"), new DecimalFormat("0.00"));
45
                new SimpleDateFormat("d-MMM"));
52
        assertFalse(g1.equals(g2));
46
        assertFalse(g1.equals(g2));
53
        g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
47
        g2 = new StandardCategoryToolTipGenerator("{2}",
54
                new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
48
                new SimpleDateFormat("d-MMM"));
55
        assertTrue(g1.equals(g2));
49
        assertTrue(g1.equals(g2));
56
    }
50
    }
57
    /**
51
    /**
58
     * Simple check that hashCode is implemented.
52
     * Simple check that hashCode is implemented.
59
     */
53
     */
60
    public void testHashCode() {
54
    public void testHashCode() {
61
        BoxAndWhiskerXYToolTipGenerator g1
55
        StandardCategoryToolTipGenerator g1
62
                = new BoxAndWhiskerXYToolTipGenerator();
56
                = new StandardCategoryToolTipGenerator();
63
        BoxAndWhiskerXYToolTipGenerator g2
57
        StandardCategoryToolTipGenerator g2
64
                = new BoxAndWhiskerXYToolTipGenerator();
58
                = new StandardCategoryToolTipGenerator();
65
        assertTrue(g1.equals(g2));
59
        assertTrue(g1.equals(g2));
66
        assertTrue(g1.hashCode() == g2.hashCode());
60
        assertTrue(g1.hashCode() == g2.hashCode());
67
    }
61
    }
68
    /**
62
    /**
69
     * Confirm that cloning works.
63
     * Confirm that cloning works.
70
     */
64
     */
71
    public void testCloning() {
65
    public void testCloning() {
72
        BoxAndWhiskerXYToolTipGenerator g1
66
        StandardCategoryToolTipGenerator g1
73
               = new BoxAndWhiskerXYToolTipGenerator();
67
                = new StandardCategoryToolTipGenerator();
74
        BoxAndWhiskerXYToolTipGenerator g2 = null;
68
        StandardCategoryToolTipGenerator g2 = null;
75
        try {
69
        try {
76
            g2 = (BoxAndWhiskerXYToolTipGenerator) g1.clone();
70
            g2 = (StandardCategoryToolTipGenerator) g1.clone();
77
        }
71
        }
78
        catch (CloneNotSupportedException e) {
72
        catch (CloneNotSupportedException e) {
79
            e.printStackTrace();
73
            e.printStackTrace();
80
        }
74
        }
81
        assertTrue(g1 != g2);
75
        assertTrue(g1 != g2);
82
        assertTrue(g1.getClass() == g2.getClass());
76
        assertTrue(g1.getClass() == g2.getClass());
83
        assertTrue(g1.equals(g2));
77
        assertTrue(g1.equals(g2));
84
    }
78
    }
85
    /**
79
    /**
86
     * Check to ensure that this class implements PublicCloneable.
80
     * Check to ensure that this class implements PublicCloneable.
87
     */
81
     */
88
    public void testPublicCloneable() {
82
    public void testPublicCloneable() {
89
        BoxAndWhiskerXYToolTipGenerator g1
83
        StandardCategoryToolTipGenerator g1
90
                = new BoxAndWhiskerXYToolTipGenerator();
84
                = new StandardCategoryToolTipGenerator();
91
        assertTrue(g1 instanceof PublicCloneable);
85
        assertTrue(g1 instanceof PublicCloneable);
92
    }
86
    }
93
    /**
87
    /**
94
     * Serialize an instance, restore it, and check for equality.
88
     * Serialize an instance, restore it, and check for equality.
95
     */
89
     */
96
    public void testSerialization() {
90
    public void testSerialization() {
97
        BoxAndWhiskerXYToolTipGenerator g1
91
        StandardCategoryToolTipGenerator g1
98
                = new BoxAndWhiskerXYToolTipGenerator();
92
                = new StandardCategoryToolTipGenerator(
99
        BoxAndWhiskerXY
93
"{2}",
94
                DateFormat.getInstance());
100
ToolTipGenerator g2 = null;
95
        StandardCategoryToolTipGenerator g2 = null;
101
        try {
96
        try {
102
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
97
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
103
            ObjectOutput out = new ObjectOutputStream(buffer);
98
            ObjectOutput out = new ObjectOutputStream(buffer);
104
            out.writeObject(g1);
99
            out.writeObject(g1);
105
            out.close();
100
            out.close();
106
            ObjectInput in = new ObjectInputStream(
101
            ObjectInput in = new ObjectInputStream(
107
                    new ByteArrayInputStream(buffer.toByteArray()));
102
                    new ByteArrayInputStream(buffer.toByteArray()));
108
            g2 = (BoxAndWhiskerXYToolTipGenerator) in.readObject();
103
            g2 = (StandardCategoryToolTipGenerator) in.readObject();
109
            in.close();
104
            in.close();
110
        }
105
        }
111
        catch (Exception e) {
106
        catch (Exception e) {
112
            e.printStackTrace();
107
            e.printStackTrace();
113
        }
108
        }
114
        assertEquals(g1, g2)
109
        assertEquals(g1, g2);
110
    }
111
    /**
112
     * A test for bug 1481087.
113
     */
114
    public void testEquals1481087() {
115
        StandardCategoryToolTipGenerator g1
116
                = new StandardCategoryToolTipGenerator("{0}",
117
                new DecimalFormat("0.00"));
118
        StandardCategoryItemLabelGenerator g2
119
                = new StandardCategoryItemLabelGenerator("{0}",
120
                new DecimalFormat("0.00"));
121
        assertFalse(g1.equals(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