Search in sources :

Example 6 with PathSet

use of org.apache.maven.plugins.war.util.PathSet in project maven-plugins by apache.

the class PathSetTest method testPathsSetBasic.

/* -------------- Operations tests ------------------*/
/**
     * Test method for:
     * <ul>
     * <li>org.apache.maven.plugin.war.PathSet.PathSet()</li>
     * <li>org.apache.maven.plugin.war.PathSet.size()</li>
     * <li>org.apache.maven.plugin.war.PathSet.add()</li>
     * <li>org.apache.maven.plugin.war.PathSet.addAll()</li>
     * <li>org.apache.maven.plugin.war.PathSet.iterate()</li>
     * <li>org.apache.maven.plugin.war.PathSet.contains()</li>
     * <li>org.apache.maven.plugin.war.PathSet.addPrefix(String)</li>
     * </ul>
     */
public void testPathsSetBasic() {
    PathSet ps = new PathSet();
    assertEquals("Unexpected PathSet size", ps.size(), 0);
    Iterator<String> iter = ps.iterator();
    assertNotNull("Iterator is null", iter);
    assertFalse("Can iterate on empty set", iter.hasNext());
    ps.add("abc");
    assertEquals("Unexpected PathSet size", ps.size(), 1);
    ps.add("abc");
    assertEquals("Unexpected PathSet size", ps.size(), 1);
    ps.add("xyz/abc");
    assertEquals("Unexpected PathSet size", ps.size(), 2);
    ps.add("///abc");
    assertEquals("Unexpected PathSet size", ps.size(), 2);
    ps.add("///xyz\\abc");
    assertEquals("Unexpected PathSet size", ps.size(), 2);
    ps.addAll(ps);
    assertEquals("Unexpected PathSet size", ps.size(), 2);
    int i = 0;
    for (String p1 : ps) {
        i++;
        String pathstr = p1;
        assertTrue(ps.contains(pathstr));
        assertTrue(ps.contains("/" + pathstr));
        assertTrue(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\')));
        assertFalse(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\') + "/a"));
        assertFalse(ps.contains("/a/" + StringUtils.replace(pathstr, '/', '\\')));
    }
    assertEquals("Wrong count of iterations", 2, i);
    ps.addPrefix("/ab/c/");
    i = 0;
    for (String p : ps) {
        i++;
        String pathstr = p;
        assertTrue(pathstr.startsWith("ab/c/"));
        assertFalse(pathstr.startsWith("ab/c//"));
        assertTrue(ps.contains(pathstr));
        assertTrue(ps.contains("/" + pathstr));
        assertTrue(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\')));
        assertFalse(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\') + "/a"));
        assertFalse(ps.contains("/ab/" + StringUtils.replace(pathstr, '/', '\\')));
    }
    assertEquals("Wrong count of iterations", 2, i);
}
Also used : PathSet(org.apache.maven.plugins.war.util.PathSet)

Aggregations

PathSet (org.apache.maven.plugins.war.util.PathSet)6 File (java.io.File)3 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 DirectoryScanner (org.codehaus.plexus.util.DirectoryScanner)1