public class XIntervalSeriesCollectionTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(XIntervalSeriesCollectionTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public XIntervalSeriesCollectionTests(String name) { super(name); } /** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { XIntervalSeriesCollection c1 = new XIntervalSeriesCollection(); XIntervalSeriesCollection c2 = new XIntervalSeriesCollection(); assertEquals(c1, c2); // add a series XIntervalSeries s1 = new XIntervalSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3); c1.addSeries(s1); assertFalse(c1.equals(c2)); XIntervalSeries s2 = new XIntervalSeries("Series"); s2.add(1.0, 1.1, 1.2, 1.3); c2.addSeries(s2); assertTrue(c1.equals(c2)); // add an empty series c1.addSeries(new XIntervalSeries("Empty Series")); assertFalse(c1.equals(c2)); c2.addSeries(new XIntervalSeries("Empty Series")); assertTrue(c1.equals(c2)); } /** * Confirm that cloning works. */ public void testCloning() { XIntervalSeriesCollection c1 = new XIntervalSeriesCollection(); XIntervalSeries s1 = new XIntervalSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3); c1.addSeries(s1); XIntervalSeriesCollection c2 = null; try { c2 = (XIntervalSeriesCollection) c1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(c1 != c2); assertTrue(c1.getClass() == c2.getClass()); assertTrue(c1.equals(c2)); // check independence s1.setDescription("XYZ"); assertFalse(c1.equals(c2)); } /** * Verify that this class implements {@link PublicCloneable}. */ public void testPublicCloneable() { XIntervalSeriesCollection c1 = new XIntervalSeriesCollection(); assertTrue(c1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { XIntervalSeriesCollection c1 = new XIntervalSeriesCollection(); XIntervalSeries s1 = new XIntervalSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3); XIntervalSeriesCollection c2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); c2 = (XIntervalSeriesCollection) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(c1, c2); } /** * Some basic checks for the removeSeries() method. */ public void testRemoveSeries() { XIntervalSeriesCollection c = new XIntervalSeriesCollection(); XIntervalSeries s1 = new XIntervalSeries("s1"); c.addSeries(s1); c.removeSeries(0); assertEquals(0, c.getSeriesCount()); c.addSeries(s1); boolean pass = false; try { c.removeSeries(-1); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); pass = false; try { c.removeSeries(1); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); } /** * A test for bug report 1170825 (originally affected XYSeriesCollection, * this test is just copied over). */ public void test1170825() { XIntervalSeries s1 = new XIntervalSeries("Series1"); XIntervalSeriesCollection dataset = new XIntervalSeriesCollection(); dataset.addSeries(s1); try { /* XYSeries s = */ dataset.getSeries(1); } catch (IllegalArgumentException e) { // correct outcome } catch (IndexOutOfBoundsException e) { assertTrue(false); // wrong outcom
public class YIntervalSeriesCollectionTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(YIntervalSeriesCollectionTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public YIntervalSeriesCollectionTests(String name) { super(name); } /** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { YIntervalSeriesCollection c1 = new YIntervalSeriesCollection(); YIntervalSeriesCollection c2 = new YIntervalSeriesCollection(); assertEquals(c1, c2); // add a series YIntervalSeries s1 = new YIntervalSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3); c1.addSeries(s1); assertFalse(c1.equals(c2)); YIntervalSeries s2 = new YIntervalSeries("Series"); s2.add(1.0, 1.1, 1.2, 1.3); c2.addSeries(s2); assertTrue(c1.equals(c2)); // add an empty series c1.addSeries(new YIntervalSeries("Empty Series")); assertFalse(c1.equals(c2)); c2.addSeries(new YIntervalSeries("Empty Series")); assertTrue(c1.equals(c2)); } /** * Confirm that cloning works. */ public void testCloning() { YIntervalSeriesCollection c1 = new YIntervalSeriesCollection(); YIntervalSeries s1 = new YIntervalSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3); c1.addSeries(s1); YIntervalSeriesCollection c2 = null; try { c2 = (YIntervalSeriesCollection) c1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(c1 != c2); assertTrue(c1.getClass() == c2.getClass()); assertTrue(c1.equals(c2)); // check independence s1.setDescription("XYZ"); assertFalse(c1.equals(c2)); } /** * Verify that this class implements {@link PublicCloneable}. */ public void testPublicCloneable() { YIntervalSeriesCollection c1 = new YIntervalSeriesCollection(); assertTrue(c1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { YIntervalSeriesCollection c1 = new YIntervalSeriesCollection(); YIntervalSeries s1 = new YIntervalSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3); YIntervalSeriesCollection c2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); c2 = (YIntervalSeriesCollection) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(c1, c2); } /** * Some basic checks for the removeSeries() method. */ public void testRemoveSeries() { YIntervalSeriesCollection c = new YIntervalSeriesCollection(); YIntervalSeries s1 = new YIntervalSeries("s1"); c.addSeries(s1); c.removeSeries(0); assertEquals(0, c.getSeriesCount()); c.addSeries(s1); boolean pass = false; try { c.removeSeries(-1); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); pass = false; try { c.removeSeries(1); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); } /** * A test for bug report 1170825 (originally affected XYSeriesCollection, * this test is just copied over). */ public void test1170825() { YIntervalSeries s1 = new YIntervalSeries("Series1"); YIntervalSeriesCollection dataset = new YIntervalSeriesCollection(); dataset.addSeries(s1); try { /* XYSeries s = */ dataset.getSeries(1); } catch (IllegalArgumentException e) { // correct outcome } catch (IndexOutOfBoundsException e) { assertTrue(false); // wrong outcom
Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/data/xy/junit/XIntervalSeriesCollectionTests.java File path: /jfreechart-1.0.10/tests/org/jfree/data/xy/junit/YIntervalSeriesCollectionTests.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class XIntervalSeriesCollectionTests extends TestCase {
1
public class YIntervalSeriesCollectionTests 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(XIntervalSeriesCollectionTests.class);
8
        return new TestSuite(YIntervalSeriesCollectionTests.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 XIntervalSeriesCollectionTests(String name) {
15
    public YIntervalSeriesCollectionTests(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
     * Confirm that the equals method can distinguish all the required fields.
20
     */
20
     */
21
    public void testEquals() {
21
    public void testEquals() {
22
        XIntervalSeriesCollection c1 = new XIntervalSeriesCollection();
22
        YIntervalSeriesCollection c1 = new YIntervalSeriesCollection();
23
        XIntervalSeriesCollection c2 = new XIntervalSeriesCollection();
23
        YIntervalSeriesCollection c2 = new YIntervalSeriesCollection();
24
        assertEquals(c1, c2);
24
        assertEquals(c1, c2);
25
        // add a series
25
        // add a series
26
        XIntervalSeries s1 = new XIntervalSeries("Series");
26
        YIntervalSeries s1 = new YIntervalSeries("Series");
27
        s1.add(1.0, 1.1, 1.2, 1.3);
27
        s1.add(1.0, 1.1, 1.2, 1.3);
28
        c1.addSeries(s1);
28
        c1.addSeries(s1);
29
        assertFalse(c1.equals(c2));
29
        assertFalse(c1.equals(c2));
30
        XIntervalSeries s2 = new XIntervalSeries("Series");
30
        YIntervalSeries s2 = new YIntervalSeries("Series");
31
        s2.add(1.0, 1.1, 1.2, 1.3);
31
        s2.add(1.0, 1.1, 1.2, 1.3);
32
        c2.addSeries(s2);
32
        c2.addSeries(s2);
33
        assertTrue(c1.equals(c2));
33
        assertTrue(c1.equals(c2));
34
        // add an empty series
34
        // add an empty series
35
        c1.addSeries(new XIntervalSeries("Empty Series"));
35
        c1.addSeries(new YIntervalSeries("Empty Series"));
36
        assertFalse(c1.equals(c2));
36
        assertFalse(c1.equals(c2));
37
        c2.addSeries(new XIntervalSeries("Empty Series"));
37
        c2.addSeries(new YIntervalSeries("Empty Series"));
38
        assertTrue(c1.equals(c2));
38
        assertTrue(c1.equals(c2));
39
    }
39
    }
40
    /**
40
    /**
41
     * Confirm that cloning works.
41
     * Confirm that cloning works.
42
     */
42
     */
43
    public void testCloning() {
43
    public void testCloning() {
44
        XIntervalSeriesCollection c1 = new XIntervalSeriesCollection();
44
        YIntervalSeriesCollection c1 = new YIntervalSeriesCollection();
45
        XIntervalSeries s1 = new XIntervalSeries("Series");
45
        YIntervalSeries s1 = new YIntervalSeries("Series");
46
        s1.add(1.0, 1.1, 1.2, 1.3);
46
        s1.add(1.0, 1.1, 1.2, 1.3);
47
        c1.addSeries(s1);
47
        c1.addSeries(s1);
48
        XIntervalSeriesCollection c2 = null;
48
        YIntervalSeriesCollection c2 = null;
49
        try {
49
        try {
50
            c2 = (XIntervalSeriesCollection) c1.clone();
50
            c2 = (YIntervalSeriesCollection) c1.clone();
51
        }
51
        }
52
        catch (CloneNotSupportedException e) {
52
        catch (CloneNotSupportedException e) {
53
            e.printStackTrace();
53
            e.printStackTrace();
54
        }
54
        }
55
        assertTrue(c1 != c2);
55
        assertTrue(c1 != c2);
56
        assertTrue(c1.getClass() == c2.getClass());
56
        assertTrue(c1.getClass() == c2.getClass());
57
        assertTrue(c1.equals(c2));
57
        assertTrue(c1.equals(c2));
58
        // check independence
58
        // check independence
59
        s1.setDescription("XYZ");
59
        s1.setDescription("XYZ");
60
        assertFalse(c1.equals(c2));
60
        assertFalse(c1.equals(c2));
61
    }
61
    }
62
    /**
62
    /**
63
     * Verify that this class implements {@link PublicCloneable}.
63
     * Verify that this class implements {@link PublicCloneable}.
64
     */
64
     */
65
    public void testPublicCloneable() {
65
    public void testPublicCloneable() {
66
        XIntervalSeriesCollection c1 = new XIntervalSeriesCollection();
66
        YIntervalSeriesCollection c1 = new YIntervalSeriesCollection();
67
        assertTrue(c1 instanceof PublicCloneable);
67
        assertTrue(c1 instanceof PublicCloneable);
68
    }
68
    }
69
    /**
69
    /**
70
     * Serialize an instance, restore it, and check for equality.
70
     * Serialize an instance, restore it, and check for equality.
71
     */
71
     */
72
    public void testSerialization() {
72
    public void testSerialization() {
73
        XIntervalSeriesCollection c1 = new XIntervalSeriesCollection();
73
        YIntervalSeriesCollection c1 = new YIntervalSeriesCollection();
74
        XIntervalSeries s1 = new XIntervalSeries("Series");
74
        YIntervalSeries s1 = new YIntervalSeries("Series");
75
        s1.add(1.0, 1.1, 1.2, 1.3);
75
        s1.add(1.0, 1.1, 1.2, 1.3);
76
        XIntervalSeriesCollection c2 = null;
76
        YIntervalSeriesCollection c2 = null;
77
        try {
77
        try {
78
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
78
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
79
            ObjectOutput out = new ObjectOutputStream(buffer);
79
            ObjectOutput out = new ObjectOutputStream(buffer);
80
            out.writeObject(c1);
80
            out.writeObject(c1);
81
            out.close();
81
            out.close();
82
            ObjectInput in = new ObjectInputStream(
82
            ObjectInput in = new ObjectInputStream(
83
                    new ByteArrayInputStream(buffer.toByteArray()));
83
                    new ByteArrayInputStream(buffer.toByteArray()));
84
            c2 = (XIntervalSeriesCollection) in.readObject();
84
            c2 = (YIntervalSeriesCollection) in.readObject();
85
            in.close();
85
            in.close();
86
        }
86
        }
87
        catch (Exception e) {
87
        catch (Exception e) {
88
            e.printStackTrace();
88
            e.printStackTrace();
89
        }
89
        }
90
        assertEquals(c1, c2);
90
        assertEquals(c1, c2);
91
    }
91
    }
92
    /**
92
    /**
93
     * Some basic checks for the removeSeries() method.
93
     * Some basic checks for the removeSeries() method.
94
     */
94
     */
95
    public void testRemoveSeries() {
95
    public void testRemoveSeries() {
96
        XIntervalSeriesCollection c = new XIntervalSeriesCollection();
96
        YIntervalSeriesCollection c = new YIntervalSeriesCollection();
97
        XIntervalSeries s1 = new XIntervalSeries("s1");
97
        YIntervalSeries s1 = new YIntervalSeries("s1");
98
        c.addSeries(s1);
98
        c.addSeries(s1);
99
        c.removeSeries(0);
99
        c.removeSeries(0);
100
        assertEquals(0, c.getSeriesCount());
100
        assertEquals(0, c.getSeriesCount());
101
        c.addSeries(s1);
101
        c.addSeries(s1);
102
        boolean pass = false;
102
        boolean pass = false;
103
        try {
103
        try {
104
            c.removeSeries(-1);
104
            c.removeSeries(-1);
105
        }
105
        }
106
        catch (IllegalArgumentException e) {
106
        catch (IllegalArgumentException e) {
107
            pass = true;
107
            pass = true;
108
        }
108
        }
109
        assertTrue(pass);
109
        assertTrue(pass);
110
        pass = false;
110
        pass = false;
111
        try {
111
        try {
112
            c.removeSeries(1);
112
            c.removeSeries(1);
113
        }
113
        }
114
        catch (IllegalArgumentException e) {
114
        catch (IllegalArgumentException e) {
115
            pass = true;
115
            pass = true;
116
        }
116
        }
117
        assertTrue(pass);
117
        assertTrue(pass);
118
    }
118
    }
119
    /**
119
    /**
120
     * A test for bug report 1170825 (originally affected XYSeriesCollection,
120
     * A test for bug report 1170825 (originally affected XYSeriesCollection,
121
     * this test is just copied over).
121
     * this test is just copied over).
122
     */
122
     */
123
    public void test1170825() {
123
    public void test1170825() {
124
        XIntervalSeries s1 = new XIntervalSeries("Series1");
124
        YIntervalSeries s1 = new YIntervalSeries("Series1");
125
        XIntervalSeriesCollection dataset = new XIntervalSeriesCollection();
125
        YIntervalSeriesCollection dataset = new YIntervalSeriesCollection();
126
        dataset.addSeries(s1);
126
        dataset.addSeries(s1);
127
        try {
127
        try {
128
            /* XYSeries s = */ dataset.getSeries(1);
128
            /* XYSeries s = */ dataset.getSeries(1);
129
        }
129
        }
130
        catch (IllegalArgumentException e) {
130
        catch (IllegalArgumentException e) {
131
            // correct outcome
131
            // correct outcome
132
        }
132
        }
133
        catch (IndexOutOfBoundsException e) {
133
        catch (IndexOutOfBoundsException e) {
134
            assertTrue(false);  // wrong outcom
134
            assertTrue(false);  // wrong outcom
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