public class StandardDialFrameTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(StandardDialFrameTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public StandardDialFrameTests(String name) { super(name); } /** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { StandardDialFrame f1 = new StandardDialFrame(); StandardDialFrame f2 = new StandardDialFrame(); assertTrue(f1.equals(f2)); // radius f1.setRadius(0.2); assertFalse(f1.equals(f2)); f2.setRadius(0.2); assertTrue(f1.equals(f2)); // backgroundPaint f1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.yellow)); assertFalse(f1.equals(f2)); f2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.yellow)); assertTrue(f1.equals(f2)); // foregroundPaint f1.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.green)); assertFalse(f1.equals(f2)); f2.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.green)); assertTrue(f1.equals(f2)); // stroke f1.setStroke(new BasicStroke(2.4f)); assertFalse(f1.equals(f2)); f2.setStroke(new BasicStroke(2.4f)); assertTrue(f1.equals(f2)); // check an inherited attribute f1.setVisible(false); assertFalse(f1.equals(f2)); f2.setVisible(false); assertTrue(f1.equals(f2)); } /** * Two objects that are equal are required to return the same hashCode. */ public void testHashCode() { StandardDialFrame f1 = new StandardDialFrame(); StandardDialFrame f2 = new StandardDialFrame(); assertTrue(f1.equals(f2)); int h1 = f1.hashCode(); int h2 = f2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ public void testCloning() { StandardDialFrame f1 = new StandardDialFrame(); StandardDialFrame f2 = null; try { f2 = (StandardDialFrame) f1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(f1 != f2); assertTrue(f1.getClass() == f2.getClass()); assertTrue(f1.equals(f2)); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); f1.addChangeListener(l1); assertTrue(f1.hasListener(l1)); assertFalse(f2.hasListener(l1)); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { StandardDialFrame f1 = new StandardDialFrame(); StandardDialFrame f2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(f1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); f2 = (StandardDialFrame) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(f1, f2)
public class RingPlotTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(RingPlotTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public RingPlotTests(String name) { super(name); } /** * Some checks for the equals() method. */ public void testEquals() { RingPlot plot1 = new RingPlot(null); RingPlot plot2 = new RingPlot(null); assertTrue(plot1.equals(plot2)); assertTrue(plot2.equals(plot1)); // separatorsVisible plot1.setSeparatorsVisible(false); assertFalse(plot1.equals(plot2)); plot2.setSeparatorsVisible(false); assertTrue(plot1.equals(plot2)); // separatorStroke Stroke s = new BasicStroke(1.1f); plot1.setSeparatorStroke(s); assertFalse(plot1.equals(plot2)); plot2.setSeparatorStroke(s); assertTrue(plot1.equals(plot2)); // separatorPaint plot1.setSeparatorPaint(new GradientPaint(1.0f, 2.0f, Color.red, 2.0f, 1.0f, Color.blue)); assertFalse(plot1.equals(plot2)); plot2.setSeparatorPaint(new GradientPaint(1.0f, 2.0f, Color.red, 2.0f, 1.0f, Color.blue)); assertTrue(plot1.equals(plot2)); // innerSeparatorExtension plot1.setInnerSeparatorExtension(0.01); assertFalse(plot1.equals(plot2)); plot2.setInnerSeparatorExtension(0.01); assertTrue(plot1.equals(plot2)); // outerSeparatorExtension plot1.setOuterSeparatorExtension(0.02); assertFalse(plot1.equals(plot2)); plot2.setOuterSeparatorExtension(0.02); assertTrue(plot1.equals(plot2)); // sectionDepth plot1.setSectionDepth(0.12); assertFalse(plot1.equals(plot2)); plot2.setSectionDepth(0.12); assertTrue(plot1.equals(plot2)); } /** * Confirm that cloning works. */ public void testCloning() { RingPlot p1 = new RingPlot(null); GradientPaint gp = new GradientPaint(1.0f, 2.0f, Color.yellow, 3.0f, 4.0f, Color.red); p1.setSeparatorPaint(gp); RingPlot p2 = null; try { p2 = (RingPlot) p1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(p1 != p2); assertTrue(p1.getClass() == p2.getClass()); assertTrue(p1.equals(p2)); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { RingPlot p1 = new RingPlot(null); GradientPaint gp = new GradientPaint(1.0f, 2.0f, Color.yellow, 3.0f, 4.0f, Color.red); p1.setSeparatorPaint(gp); RingPlot p2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(p1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); p2 = (RingPlot) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(p1, p2)
Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/chart/plot/dial/junit/StandardDialFrameTests.java File path: /jfreechart-1.0.10/tests/org/jfree/chart/plot/junit/RingPlotTests.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class StandardDialFrameTests extends TestCase {
1
public class RingPlotTests 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(StandardDialFrameTests.class);
8
        return new TestSuite(RingPlotTests.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 StandardDialFrameTests(String name) {
15
    public RingPlotTests(String name) {
16
        super(name);
16
        super(name);
17
    }
17
    }
18
    /**
18
    /**
19
     * Confirm that the equals method can distinguish all the required fields.
19
     * Some checks for the equals() method.
20
     */
20
     */
21
    public void testEquals() {
21
    public void testEquals() {
22
        StandardDialFrame f1 = new StandardDialFrame();
22
        
23
        StandardDialFrame f2 = new StandardDialFrame(
23
        RingPlot plot1 = new RingPlot(null);
24
        RingPlot plot2 = new RingPlot(null);
24
);
25
        assertTrue(plot1.equals(plot2));
25
        assertTrue(f1.equals(f2));
26
        assertTrue(plot2.equals(
26
        // radius
27
plot1));
28
                
29
        // separatorsVisible
27
        f1.setRadius(0.2);
30
        plot1.setSeparatorsVisible(false);
28
        assertFalse(f1.equals(f2));
31
        assertFalse(plot1.equals(plot2));
29
        f2.setRadius(0.2);
32
        plot2.setSeparatorsVisible(false);
30
        assertTrue(f1.equals(f2));
33
        assertTrue(plot1.equals(plot2));
31
        
34
        
32
        // backgroundPaint
35
        // 
33
        f1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f,
34
                4.0f, Color.yellow)
36
separatorStroke
37
        Stroke s = new BasicStroke(1.1f);
35
);
38
        plot1.setSeparatorStroke(s);
36
        assertFalse(f1.equals(f2));
39
        assertFalse(plot1.equals(plot2));
37
        f2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f,
40
        plot2.set
38
                4.0f, Color.yellow));
41
SeparatorStroke(s);
39
        assertTrue(f1.equals(f2));
42
        assertTrue(plot1.equals(plot2));
40
        
41
        // foregroundPaint
43
        // separatorPaint
42
        f1.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f,
44
        plot1.setSeparatorPaint(new GradientPaint(1.0f, 2.0f, Color.red, 
43
                4.0f, Color.green));
45
                2.0f, 1.0f, Color.blue));
44
        assertFalse(f1.equals(f2));
46
        assertFalse(plot1.equals(plot2));
45
        f2.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f,
47
        plot2.setSeparatorPaint(new GradientPaint(1.0f, 2.0f, Color.red, 
46
                4.0f, Color.green));
48
                2.0f, 1.0f, Color.blue));
47
        assertTrue(f1.equals(f2));
49
        assertTrue(plot1.equals(plot2));
48
        
50
        
49
        // stroke
51
        // innerSeparatorExtension
50
        f1.setStroke(new BasicStroke(2.4f));
52
        plot1.setInnerSeparatorExtension(0.01);
51
        assertFalse(f1.equals(f2));
53
        assertFalse(plot1.equals(plot2));
52
        f2.setStroke(new BasicStroke(2.4f));
54
        plot2.setInnerSeparatorExtension(0.01);
53
        assertTrue(f1.equals(f2));
55
        assertTrue(plot1.equals(plot2));
54
        
56
        
55
        // check an inherited attribute
57
        // outerSeparatorExtension
56
        f1.setVisible(false);
58
        plot1.setOuterSeparatorExtension(0.02);
57
        assertFalse(f1.equals(f2));
59
        assertFalse(plot1.equals(plot2));
58
        f2.setVisible(false);
60
        plot2.setOuterSeparatorExtension(0.02);
59
        assertTrue(f1.equals(f2));
61
        assertTrue(plot1.equals(plot2));
60
    }
62
    
61
    /**
63
    /
62
     * Two objects that are equal are required to return the same hashCode. 
64
/ sectionDepth
63
     */
65
     
64
    public void testHashCode() {
65
        StandardDialFrame f1 = new StandardDialFrame();
66
        StandardDialFrame f2 = new StandardDialFrame(
66
   plot1.setSectionDepth(0.12);
67
        assertFalse(plot1.equals(plot2));
67
);
68
        plot2.setSectionDepth(0.12);
68
        assertTrue(f1.equals(f2));
69
        assertTrue(plot1.equals(
69
        int h1 = f1.hashCode();
70
        int h2 = f2.hashCode();
71
        assertEquals(h1, h2);
70
plot2));
71
        
72
    }
72
    }
73
    /**
73
    /**
74
     * Confirm that cloning works.
74
     * Confirm that cloning works.
75
     */
75
     */
76
    public void testCloning() {
76
    public void testCloning() {
77
        StandardDialFrame f1 = new StandardDialFrame();
77
        
78
        StandardDialFrame f
78
RingPlot p1 = new RingPlot(null);
79
        GradientPaint gp = new GradientPaint(1.0f, 2.0f, Color.yellow,
80
                3.0f, 4.0f, Color.red);
81
        p1.setSeparatorPaint(gp);
79
2 = null;
82
        RingPlot p2 = null;
80
        try {
83
        try {
81
            f2 = (StandardDialFrame) f1.clone();
84
            p2 = (RingPlot) p1.clone();
82
        }
85
        }
83
        catch (CloneNotSupportedException e) {
86
        catch (CloneNotSupportedException e) {
84
            e.printStackTrace();
87
            e.printStackTrace();
85
        }
88
        }
86
        assertTrue(f1 != f2);
89
        assertTrue(p1 != p2);
87
        assertTrue(f1.getClass() == f2.getClass());
90
        assertTrue(p1.getClass() == p2.getClass());
88
        assertTrue(f1.equals(f2));
91
        assertTrue(p1.equals(
89
        
90
        // check that the listener lists are independent
91
        MyDialLayerChangeListener l1 = new MyDialLayerChangeListener();
92
        f1.addChangeListener(l1);
93
        assertTrue(f1.hasListener(l1));
94
        assertFalse(f2.hasListener(l1));
92
p2));
95
    }
93
    }
96
    /**
94
    /**
97
     * Serialize an instance, restore it, and check for equality.
95
     * Serialize an instance, restore it, and check for equality.
98
     */
96
     */
99
    public void testSerialization() {
97
    public void testSerialization() {
100
        StandardDialFrame f1 = new StandardDialFrame();
98
        
101
        StandardDialFrame f
99
RingPlot p1 = new RingPlot(null);
100
        GradientPaint gp = new GradientPaint(1.0f, 2.0f, Color.yellow,
101
                3.0f, 4.0f, Color.red);
102
        p1.setSeparatorPaint(gp);
102
2 = null;
103
        RingPlot p2 = null;
103
        try {
104
        try {
104
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
105
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
105
            ObjectOutput out = new ObjectOutputStream(buffer);
106
            ObjectOutput out = new ObjectOutputStream(buffer);
106
            out.writeObject(f1);
107
            out.writeObject(p1);
107
            out.close();
108
            out.close();
108
            ObjectInput in = new ObjectInputStream(
109
            ObjectInput in = new ObjectInputStream(
109
                    new ByteArrayInputStream(buffer.toByteArray()));
110
                    new ByteArrayInputStream(buffer.toByteArray()));
110
            f2 = (StandardDialFrame) in.readObject();
111
            p2 = (RingPlot) in.readObject();
111
            in.close();
112
            in.close();
112
        }
113
        }
113
        catch (Exception e) {
114
        catch (Exception e) {
114
            e.printStackTrace();
115
            e.printStackTrace();
115
        }
116
        }
116
        assertEquals(f1, f2)
117
        assertEquals(p1, p2)
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