Allow the nav bean to count children. This could be done directly in jelly, but I hate jelly. And I can write

test cases in the same format as the other test cases.
PR: MAVEN-579


git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113658 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
bwalding committed 2003-07-17 09:33:12 +00:00
1 parent c3b706102f
commit 6ba41dd168
2 files changed
+50 -21

No files matched your search

+11 -1
View File
@@ -64,7 +64,7 @@ import org.dom4j.tree.DefaultElement;
/**
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
* @version $Id: NavBean.java,v 1.4 2003/03/10 14:18:41 bwalding Exp $
* @version $Id: NavBean.java,v 1.5 2003/07/17 09:33:12 bwalding Exp $
*/
public class NavBean
{
@@ -95,6 +95,16 @@ public class NavBean
{
return getAttribute(elem, "href", null);
}
/**
* Assumes that the node is visible.
* @param o
* @return the number of children for this node
*/
public int countChildren(DefaultElement elem) {
List l = elem.selectNodes("./item");
return l.size();
}
/**
* Determines if the given node is collapsed. If a parent of this node is
+39 -20
View File
@@ -64,10 +64,11 @@ import junit.framework.TestCase;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.dom4j.tree.DefaultElement;
/**
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
* @version $Id: NavBeanTest.java,v 1.2 2003/03/10 14:15:30 bwalding Exp $
* @version $Id: NavBeanTest.java,v 1.3 2003/07/17 09:33:12 bwalding Exp $
*/
public class NavBeanTest extends TestCase
{
@@ -80,7 +81,6 @@ public class NavBeanTest extends TestCase
testResources = new File(System.getProperty("basedir") + "/src/test-resources");
nb = new NavBean();
nb.setDocument(getTestDocument());
}
class Test
@@ -101,29 +101,29 @@ public class NavBeanTest extends TestCase
return reader.read(new FileInputStream(new File(testResources, "navigation.xml")));
}
public void testAll() throws Exception
public void testCollapsed() throws Exception
{
test("/alpha/index.html", "/alpha/index.html", false);
test("/alpha/one/index.html", "/alpha/index.html", false);
test("/alpha/two/index.html", "/alpha/index.html", false);
test("/beta/index.html", "/alpha/index.html", true);
testCollapsed("/alpha/index.html", "/alpha/index.html", false);
testCollapsed("/alpha/one/index.html", "/alpha/index.html", false);
testCollapsed("/alpha/two/index.html", "/alpha/index.html", false);
testCollapsed("/beta/index.html", "/alpha/index.html", true);
test("/alpha/index.html", "/beta/index.html", false);
test("/alpha/one/index.html", "/beta/index.html", false);
test("/alpha/two/index.html", "/beta/index.html", false);
test("/beta/index.html", "/beta/index.html", false);
test("/beta/one/index.html", "/beta/index.html", true);
test("/beta/two/index.html", "/beta/index.html", true);
testCollapsed("/alpha/index.html", "/beta/index.html", false);
testCollapsed("/alpha/one/index.html", "/beta/index.html", false);
testCollapsed("/alpha/two/index.html", "/beta/index.html", false);
testCollapsed("/beta/index.html", "/beta/index.html", false);
testCollapsed("/beta/one/index.html", "/beta/index.html", true);
testCollapsed("/beta/two/index.html", "/beta/index.html", true);
test("/alpha/index.html", "beta/index.html", false);
test("/alpha/one/index.html", "beta/index.html", false);
test("/alpha/two/index.html", "beta/index.html", false);
test("/beta/index.html", "beta/index.html", false);
test("/beta/one/index.html", "beta/index.html", true);
test("/beta/two/index.html", "beta/index.html", true);
testCollapsed("/alpha/index.html", "beta/index.html", false);
testCollapsed("/alpha/one/index.html", "beta/index.html", false);
testCollapsed("/alpha/two/index.html", "beta/index.html", false);
testCollapsed("/beta/index.html", "beta/index.html", false);
testCollapsed("/beta/one/index.html", "beta/index.html", true);
testCollapsed("/beta/two/index.html", "beta/index.html", true);
}
public void test(String href, String location, boolean expected)
public void testCollapsed(String href, String location, boolean expected)
{
nb.setLocation(location);
@@ -133,5 +133,24 @@ public class NavBeanTest extends TestCase
String s = "At location " + location + ", looking to generate link to " + href + ", expecting collapse = " + expected;
assertEquals(s, expected, nb.isCollapsed(node));
}
public void testCountChildren() throws Exception
{
testCountChildren("/alpha/index.html", 2);
testCountChildren("/alpha/one/index.html", 0);
testCountChildren("/alpha/two/index.html", 0);
testCountChildren("/beta/index.html", 2);
testCountChildren("/beta/one/index.html", 0);
testCountChildren("/beta/two/index.html", 0);
}
public void testCountChildren(String href, int expected)
{
Node node = nb.getFirstNodeByHREF(href);
assertNotNull(node);
String s = "At location " + href + ", expecting countChildren = " + expected;
assertEquals(s, expected, nb.countChildren((DefaultElement) node));
}
}