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