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