From bd62d913b95a45adc21e87625d8eb671b13e6901 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Thu, 29 Apr 2010 22:49:36 +0000 Subject: [PATCH] added more convenience methods. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@30525 71c3de6d-444a-0410-be80-ed276b4c234a --- .../org/jvnet/hudson/test/HudsonTestCase.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index d911358930..320a704fed 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -72,6 +72,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.lang.annotation.Annotation; import java.lang.ref.WeakReference; +import java.lang.reflect.Array; import java.lang.reflect.Method; import java.lang.reflect.Field; import java.net.MalformedURLException; @@ -829,7 +830,7 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { public Object call() throws Exception { Descriptor d = hudson.getDescriptor(type); WebClient wc = createWebClient(); - for (String property : properties.split(",")) { + for (String property : listProperties(properties)) { String url = d.getHelpFile(property); assertNotNull("Help file for the property "+property+" is missing on "+type, url); wc.goTo(url); // make sure it successfully loads @@ -839,6 +840,18 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { }); } + /** + * Tokenizes "foo,bar,zot,-bar" and returns "foo,zot" (the token that starts with '-' is handled as + * a cancellation. + */ + private List listProperties(String properties) { + List props = new ArrayList(Arrays.asList(properties.split(","))); + for (String p : props.toArray(new String[props.size()])) { + if (p.startsWith("-")) + props.remove(p.substring(1)); + } + } + /** * Submits the form. * @@ -935,6 +948,17 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { lp = PropertyUtils.getProperty(lhs, p); rp = PropertyUtils.getProperty(rhs, p); } + + if (lp!=null && rp!=null && lp.getClass().isArray() && rp.getClass().isArray()) { + // deep array equality comparison + int m = Array.getLength(lp); + int n = Array.getLength(rp); + assertEquals("Array length is different for property "+p, m,n); + for (int i=0; i