public final void testAttributes() { TarFileSet f = (TarFileSet)getInstance(); //check that dir and src are incompatible f.setSrc(new File("example.tar")); try { f.setDir(new File("examples")); fail("can add dir to " + f.getDataTypeName() + " when a src is already present"); } catch (BuildException be) { assertEquals("Cannot set both dir and src attributes",be.getMessage()); } f = (TarFileSet)getInstance(); //check that dir and src are incompatible f.setDir(new File("examples")); try { f.setSrc(new File("example.tar")); fail("can add src to " + f.getDataTypeName() + " when a dir is already present"); } catch (BuildException be) { assertEquals("Cannot set both dir and src attributes",be.getMessage()); } //check that fullpath and prefix are incompatible f = (TarFileSet)getInstance(); f.setSrc(new File("example.tar")); f.setPrefix("/examples"); try { f.setFullpath("/doc/manual/index.html"); fail("Can add fullpath to " + f.getDataTypeName() + " when a prefix is already present"); } catch (BuildException be) { assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); } f = (TarFileSet)getInstance(); f.setSrc(new File("example.tar")); f.setFullpath("/doc/manual/index.html"); try { f.setPrefix("/examples"); fail("Can add prefix to " + f.getDataTypeName() + " when a fullpath is already present"); } catch (BuildException be) { assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); } // check that reference tarfilesets cannot have specific attributes f = (TarFileSet)getInstance(); f.setRefid(new Reference("test")); try { f.setSrc(new File("example.tar")); fail("Can add src to " + f.getDataTypeName() + " when a refid is already present"); } catch (BuildException be) { assertEquals("You must not specify more than one " + "attribute when using refid", be.getMessage()); } // check that a reference tarfileset gets the same attributes as the original f = (TarFileSet)getInstance(); f.setSrc(new File("example.tar")); f.setPrefix("/examples"); f.setFileMode("600"); f.setDirMode("530"); getProject().addReference("test",f); TarFileSet zid=(TarFileSet)getInstance(); zid.setRefid(new Reference("test")); assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject()))); assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject())); assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject()));
public final void testAttributes() { ZipFileSet f = (ZipFileSet)getInstance(); //check that dir and src are incompatible f.setSrc(new File("example.zip")); try { f.setDir(new File("examples")); fail("can add dir to " + f.getDataTypeName() + " when a src is already present"); } catch (BuildException be) { assertEquals("Cannot set both dir and src attributes",be.getMessage()); } f = (ZipFileSet)getInstance(); //check that dir and src are incompatible f.setDir(new File("examples")); try { f.setSrc(new File("example.zip")); fail("can add src to " + f.getDataTypeName() + " when a dir is already present"); } catch (BuildException be) { assertEquals("Cannot set both dir and src attributes",be.getMessage()); } //check that fullpath and prefix are incompatible f = (ZipFileSet)getInstance(); f.setSrc(new File("example.zip")); f.setPrefix("/examples"); try { f.setFullpath("/doc/manual/index.html"); fail("Can add fullpath to " + f.getDataTypeName() + " when a prefix is already present"); } catch (BuildException be) { assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); } f = (ZipFileSet)getInstance(); f.setSrc(new File("example.zip")); f.setFullpath("/doc/manual/index.html"); try { f.setPrefix("/examples"); fail("Can add prefix to " + f.getDataTypeName() + " when a fullpath is already present"); } catch (BuildException be) { assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); } // check that reference zipfilesets cannot have specific attributes f = (ZipFileSet)getInstance(); f.setRefid(new Reference("test")); try { f.setSrc(new File("example.zip")); fail("Can add src to " + f.getDataTypeName() + " when a refid is already present"); } catch (BuildException be) { assertEquals("You must not specify more than one " + "attribute when using refid", be.getMessage()); } // check that a reference zipfileset gets the same attributes as the original f = (ZipFileSet)getInstance(); f.setSrc(new File("example.zip")); f.setPrefix("/examples"); f.setFileMode("600"); f.setDirMode("530"); getProject().addReference("test",f); ZipFileSet zid=(ZipFileSet)getInstance(); zid.setRefid(new Reference("test")); assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject()))); assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject())); assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject()));
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java File path: /apache-ant-1.7.0/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public final void testAttributes() {
1
public final void testAttributes() {
2
        TarFileSet f = (TarFileSet)getInstance();
2
        ZipFileSet f = (ZipFileSet)getInstance();
3
        //check that dir and src are incompatible
3
        //check that dir and src are incompatible
4
        f.setSrc(new File("example.tar"));
4
        f.setSrc(new File("example.zip"));
5
        try {
5
        try {
6
            f.setDir(new File("examples"));
6
            f.setDir(new File("examples"));
7
            fail("can add dir to "
7
            fail("can add dir to "
8
                    + f.getDataTypeName()
8
                    + f.getDataTypeName()
9
                    + " when a src is already present");
9
                    + " when a src is already present");
10
        } catch (BuildException be) {
10
        } catch (BuildException be) {
11
            assertEquals("Cannot set both dir and src attributes",be.getMessage());
11
            assertEquals("Cannot set both dir and src attributes",be.getMessage());
12
        }
12
        }
13
        f = (TarFileSet)getInstance();
13
        f = (ZipFileSet)getInstance();
14
        //check that dir and src are incompatible
14
        //check that dir and src are incompatible
15
        f.setDir(new File("examples"));
15
        f.setDir(new File("examples"));
16
        try {
16
        try {
17
            f.setSrc(new File("example.tar"));
17
            f.setSrc(new File("example.zip"));
18
            fail("can add src to "
18
            fail("can add src to "
19
                    + f.getDataTypeName()
19
                    + f.getDataTypeName()
20
                    + " when a dir is already present");
20
                    + " when a dir is already present");
21
        } catch (BuildException be) {
21
        } catch (BuildException be) {
22
            assertEquals("Cannot set both dir and src attributes",be.getMessage());
22
            assertEquals("Cannot set both dir and src attributes",be.getMessage());
23
        }
23
        }
24
        //check that fullpath and prefix are incompatible
24
        //check that fullpath and prefix are incompatible
25
        f = (TarFileSet)getInstance();
25
        f = (ZipFileSet)getInstance();
26
        f.setSrc(new File("example.tar"));
26
        f.setSrc(new File("example.zip"));
27
        f.setPrefix("/examples");
27
        f.setPrefix("/examples");
28
        try {
28
        try {
29
            f.setFullpath("/doc/manual/index.html");
29
            f.setFullpath("/doc/manual/index.html");
30
            fail("Can add fullpath to "
30
            fail("Can add fullpath to "
31
                    + f.getDataTypeName()
31
                    + f.getDataTypeName()
32
                    + " when a prefix is already present");
32
                    + " when a prefix is already present");
33
        } catch (BuildException be) {
33
        } catch (BuildException be) {
34
            assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());
34
            assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());
35
        }
35
        }
36
        f = (TarFileSet)getInstance();
36
        f = (ZipFileSet)getInstance();
37
        f.setSrc(new File("example.tar"));
37
        f.setSrc(new File("example.zip"));
38
        f.setFullpath("/doc/manual/index.html");
38
        f.setFullpath("/doc/manual/index.html");
39
        try {
39
        try {
40
            f.setPrefix("/examples");
40
            f.setPrefix("/examples");
41
            fail("Can add prefix to "
41
            fail("Can add prefix to "
42
                    + f.getDataTypeName()
42
                    + f.getDataTypeName()
43
                    + " when a fullpath is already present");
43
                    + " when a fullpath is already present");
44
        } catch (BuildException be) {
44
        } catch (BuildException be) {
45
            assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());
45
            assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());
46
        }
46
        }
47
        // check that reference tarfilesets cannot have specific attributes
47
        // check that reference zipfilesets cannot have specific attributes
48
        f = (TarFileSet)getInstance();
48
        f = (ZipFileSet)getInstance();
49
        f.setRefid(new Reference("test"));
49
        f.setRefid(new Reference("test"));
50
        try {
50
        try {
51
            f.setSrc(new File("example.tar"));
51
            f.setSrc(new File("example.zip"));
52
            fail("Can add src to "
52
            fail("Can add src to "
53
                    + f.getDataTypeName()
53
                    + f.getDataTypeName()
54
                    + " when a refid is already present");
54
                    + " when a refid is already present");
55
        } catch (BuildException be) {
55
        } catch (BuildException be) {
56
            assertEquals("You must not specify more than one "
56
            assertEquals("You must not specify more than one "
57
            + "attribute when using refid", be.getMessage());
57
            + "attribute when using refid", be.getMessage());
58
        }
58
        }
59
        // check that a reference tarfileset gets the same attributes as the original
59
        // check that a reference zipfileset gets the same attributes as the original
60
        f = (TarFileSet)getInstance();
60
        f = (ZipFileSet)getInstance();
61
        f.setSrc(new File("example.tar"));
61
        f.setSrc(new File("example.zip"));
62
        f.setPrefix("/examples");
62
        f.setPrefix("/examples");
63
        f.setFileMode("600");
63
        f.setFileMode("600");
64
        f.setDirMode("530");
64
        f.setDirMode("530");
65
        getProject().addReference("test",f);
65
        getProject().addReference("test",f);
66
        TarFileSet zid=(TarFileSet)getInstance();
66
        ZipFileSet zid=(ZipFileSet)getInstance();
67
        zid.setRefid(new Reference("test"));
67
        zid.setRefid(new Reference("test"));
68
        assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject())));
68
        assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject())));
69
        assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject())));
69
        assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject())));
70
        assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject()));
70
        assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject()));
71
        assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject()));
71
        assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject()));
72
      
72
      
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