o MAVEN-320: Cleaned up tests to make them more understandable and useful

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113094 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
bwalding committed 2003-03-10 14:15:30 +00:00
1 parent 859bff9c13
commit ecdab533a7
1 file changed
+38 -41
+38 -41
View File
@@ -55,7 +55,7 @@ package org.apache.maven;
*
* ====================================================================
*/
import java.io.File;
import java.io.FileInputStream;
@@ -67,14 +67,20 @@ import org.dom4j.io.SAXReader;
/**
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
* @version $Id: NavBeanTest.java,v 1.1 2003/02/16 23:03:37 bwalding Exp $
* @version $Id: NavBeanTest.java,v 1.2 2003/03/10 14:15:30 bwalding Exp $
*/
public class NavBeanTest extends TestCase
{
private File testResources;
public void setUp() {
NavBean nb;
public void setUp() throws Exception
{
testResources = new File(System.getProperty("basedir") + "/src/test-resources");
nb = new NavBean();
nb.setDocument(getTestDocument());
}
class Test
@@ -87,54 +93,45 @@ public class NavBeanTest extends TestCase
this.collapsed = collapsed;
}
}
private Test[] testAlpha =
{
new Test("/alpha/index.html", false),
new Test("/alpha/one/index.html", false),
new Test("/alpha/two/index.html", false),
new Test("/beta/index.html", true)};
private Test[] testBeta =
{
new Test("/alpha/index.html", false),
new Test("/alpha/one/index.html", false),
new Test("/alpha/two/index.html", false),
new Test("/beta/index.html", false),
new Test("/beta/one/index.html", true),
new Test("/beta/two/index.html", true)};
public void testAlpha() throws Exception
{
testGroup("/alpha/index.html", testAlpha);
}
public void testBeta() throws Exception
{
testGroup("/beta/index.html", testBeta);
}
protected Document getTestDocument() throws Exception
{
SAXReader reader = new SAXReader();
return reader.read(new FileInputStream(new File(testResources, "navigation.xml")));
}
public void testGroup(String location, Test[] tests) throws Exception
public void testAll() 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);
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);
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);
}
public void test(String href, String location, boolean expected)
{
NavBean nb = new NavBean();
nb.setDocument(getTestDocument());
nb.setLocation(location);
for (int i = 0; i < tests.length; i++)
{
Test test = tests[i];
Node node = nb.getFirstNodeByHREF(test.href);
assertNotNull(node);
assertEquals(test.href + ".isCollapsed()", test.collapsed, nb.isCollapsed(node));
}
Node node = nb.getFirstNodeByHREF(href);
assertNotNull(node);
String s = "At location " + location + ", looking to generate link to " + href + ", expecting collapse = " + expected;
assertEquals(s, expected, nb.isCollapsed(node));
}
}