47-1-2

public class VectorTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(VectorTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public VectorTests(String name) { super(name); } /** * Test that the equals() method distinguishes all fields. */ public void testEquals() { // default instances Vector v1 = new Vector(1.0, 2.0); Vector v2 = new Vector(1.0, 2.0); assertTrue(v1.equals(v2)); assertTrue(v2.equals(v1)); v1 = new Vector(1.1, 2.0); assertFalse(v1.equals(v2)); v2 = new Vector(1.1, 2.0); assertTrue(v1.equals(v2)); v1 = new Vector(1.1, 2.2); assertFalse(v1.equals(v2)); v2 = new Vector(1.1, 2.2); assertTrue(v1.equals(v2)); } /** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { Vector v1 = new Vector(1.0, 2.0); Vector v2 = new Vector(1.0, 2.0); assertTrue(v1.equals(v2)); int h1 = v1.hashCode(); int h2 = v2.hashCode(); assertEquals(h1, h2); } /** * Immutable class is not cloneable. */ public void testCloning() { Vector v1 = new Vector(1.0, 2.0); assertFalse(v1 instanceof Cloneable); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { Vector v1 = new Vector(1.0, 2.0); Vector v2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(v1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); v2 = (Vector) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(v1, v2);
public class XYCoordinateTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(XYCoordinateTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public XYCoordinateTests(String name) { super(name); } /** * Test that the equals() method distinguishes all fields. */ public void testEquals() { // default instances XYCoordinate v1 = new XYCoordinate(1.0, 2.0); XYCoordinate v2 = new XYCoordinate(1.0, 2.0); assertTrue(v1.equals(v2)); assertTrue(v2.equals(v1)); v1 = new XYCoordinate(1.1, 2.0); assertFalse(v1.equals(v2)); v2 = new XYCoordinate(1.1, 2.0); assertTrue(v1.equals(v2)); v1 = new XYCoordinate(1.1, 2.2); assertFalse(v1.equals(v2)); v2 = new XYCoordinate(1.1, 2.2); assertTrue(v1.equals(v2)); } /** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { XYCoordinate v1 = new XYCoordinate(1.0, 2.0); XYCoordinate v2 = new XYCoordinate(1.0, 2.0); assertTrue(v1.equals(v2)); int h1 = v1.hashCode(); int h2 = v2.hashCode(); assertEquals(h1, h2); } /** * Immutable class is not cloneable. */ public void testCloning() { XYCoordinate v1 = new XYCoordinate(1.0, 2.0); assertFalse(v1 instanceof Cloneable); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { XYCoordinate v1 = new XYCoordinate(1.0, 2.0); XYCoordinate v2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(v1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); v2 = (XYCoordinate) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(v1, v2);

Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/data/xy/junit/VectorTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/data/xy/junit/XYCoordinateTests.java
Method name: `` |  | Method name: ``
Number of AST nodes: 0 |  | Number of AST nodes: 0

1

    public class VectorTests extends TestCase {↵

1

    public class XYCoordinateTests 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(VectorTests.class);↵

8

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

15

        public XYCoordinateTests(String name) {↵

16

            super(name);↵

16

            super(name);↵

17

        }↵

17

        }↵

18

        /**↵

18

        /**↵

19

         * Test that the equals() method distinguishes all fields.↵

19

         * Test that the equals() method distinguishes all fields.↵

20

         */↵

20

         */↵

21

        public void testEquals() {        ↵

21

        public void testEquals() {        ↵

22

            // default instances↵

22

            // default instances↵

23

            Vector v1 = new Vector(1.0, 2.0);↵

23

            XYCoordinate v1 = new XYCoordinate(1.0, 2.0);↵

24

            Vector v2 = new Vector(1.0, 2.0);↵

24

            XYCoordinate v2 = new XYCoordinate(1.0, 2.0);↵

25

            assertTrue(v1.equals(v2));↵

25

            assertTrue(v1.equals(v2));↵

26

            assertTrue(v2.equals(v1));↵

26

            assertTrue(v2.equals(v1));↵

27

            v1 = new Vector(1.1, 2.0);↵

27

            v1 = new XYCoordinate(1.1, 2.0);↵

28

            assertFalse(v1.equals(v2));↵

28

            assertFalse(v1.equals(v2));↵

29

            v2 = new Vector(1.1, 2.0);↵

29

            v2 = new XYCoordinate(1.1, 2.0);↵

30

            assertTrue(v1.equals(v2));↵

30

            assertTrue(v1.equals(v2));↵

31

            ↵

31

            ↵

32

            v1 = new Vector(1.1, 2.2);↵

32

            v1 = new XYCoordinate(1.1, 2.2);↵

33

            assertFalse(v1.equals(v2));↵

33

            assertFalse(v1.equals(v2));↵

34

            v2 = new Vector(1.1, 2.2);↵

34

            v2 = new XYCoordinate(1.1, 2.2);↵

35

            assertTrue(v1.equals(v2));↵

35

            assertTrue(v1.equals(v2));↵

36

        }↵

36

        }↵

37

        /**↵

37

        /**↵

38

         * Two objects that are equal are required to return the same hashCode. ↵

38

         * Two objects that are equal are required to return the same hashCode. ↵

39

         */↵

39

         */↵

40

        public void testHashcode() {↵

40

        public void testHashcode() {↵

41

            Vector v1 = new Vector(1.0, 2.0);↵

41

            XYCoordinate v1 = new XYCoordinate(1.0, 2.0);↵

42

            Vector v2 = new Vector(1.0, 2.0);↵

42

            XYCoordinate v2 = new XYCoordinate(1.0, 2.0);↵

43

            assertTrue(v1.equals(v2));↵

43

            assertTrue(v1.equals(v2));↵

44

            int h1 = v1.hashCode();↵

44

            int h1 = v1.hashCode();↵

45

            int h2 = v2.hashCode();↵

45

            int h2 = v2.hashCode();↵

46

            assertEquals(h1, h2);↵

46

            assertEquals(h1, h2);↵

47

        }↵

47

        }↵

48

        ↵

48

        ↵

49

        /**↵

49

        /**↵

50

         * Immutable class is not cloneable.↵

50

         * Immutable class is not cloneable.↵

51

         */↵

51

         */↵

52

        public void testCloning() {↵

52

        public void testCloning() {↵

53

            Vector v1 = new Vector(1.0, 2.0);↵

53

            XYCoordinate v1 = new XYCoordinate(1.0, 2.0);↵

54

            assertFalse(v1 instanceof Cloneable);↵

54

            assertFalse(v1 instanceof Cloneable);↵

55

        }↵

55

        }↵

56

        /**↵

56

        /**↵

57

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

57

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

58

         */↵

58

         */↵

59

        public void testSerialization() {↵

59

        public void testSerialization() {↵

60

            Vector v1 = new Vector(1.0, 2.0);↵

60

            XYCoordinate v1 = new XYCoordinate(1.0, 2.0);↵

61

            Vector v2 = null;↵

61

            XYCoordinate v2 = null;↵

62

            try {↵

62

            try {↵

63

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

63

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

64

                ObjectOutput out = new ObjectOutputStream(buffer);↵

64

                ObjectOutput out = new ObjectOutputStream(buffer);↵

65

                out.writeObject(v1);↵

65

                out.writeObject(v1);↵

66

                out.close();↵

66

                out.close();↵

67

                ObjectInput in = new ObjectInputStream(↵

67

                ObjectInput in = new ObjectInputStream(↵

68

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

68

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

69

                v2 = (Vector) in.readObject();↵

69

                v2 = (XYCoordinate) in.readObject();↵

70

                in.close();↵

70

                in.close();↵

71

            }↵

71

            }↵

72

            catch (Exception e) {↵

72

            catch (Exception e) {↵

73

                e.printStackTrace();↵

73

                e.printStackTrace();↵

74

            }↵

74

            }↵

75

            assertEquals(v1, v2);↵

75

            assertEquals(v1, v2);↵

76

76

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