提交 6521d8ef 编写于 作者: K kohsuke

added a new assertion method

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@16839 71c3de6d-444a-0410-be80-ed276b4c234a
上级 c9a0ec62
......@@ -79,7 +79,6 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Arrays;
......@@ -88,6 +87,7 @@ import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.beans.PropertyDescriptor;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
......@@ -96,9 +96,8 @@ import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.jvnet.hudson.test.HudsonHomeLoader.CopyExisting;
import org.jvnet.hudson.test.recipes.Recipe;
......@@ -121,7 +120,6 @@ import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.CSSParseException;
import org.w3c.css.sac.ErrorHandler;
import org.xml.sax.SAXException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import com.gargoylesoftware.htmlunit.AjaxController;
import com.gargoylesoftware.htmlunit.BrowserVersion;
......@@ -132,7 +130,6 @@ import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.gargoylesoftware.htmlunit.javascript.host.Stylesheet;
import com.gargoylesoftware.htmlunit.javascript.host.XMLHttpRequest;
......@@ -559,6 +556,39 @@ public abstract class HudsonTestCase extends TestCase {
return new StreamTaskListener(new CloseProofOutputStream(System.out));
}
/**
* Asserts that two JavaBeans are equal as far as the given list of properties are concerned.
*
* <p>
* This method takes two objects that have properties (getXyz, isXyz, or just the public xyz field),
* and makes sure that the property values for each given property are equals (by using {@link #assertEquals(Object, Object)})
*
* <p>
* Property values can be null on both objects, and that is OK, but passing in a property that doesn't
* exist will fail an assertion.
*
* <p>
* This method is very convenient for comparing a large number of properties on two objects,
* for example to verify that the configuration is identical after a config screen roundtrip.
*
* @param lhs
* One of the two objects to be compared.
* @param rhs
* The other object to be compared
* @param properties
* ','-separated list of property names that are compared.
* @since 1.297
*/
public void assertEqualBeans(Object lhs, Object rhs, String properties) throws Exception {
for (String p : properties.split(",")) {
PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(lhs, p);
assertNotNull("No such property "+p+" on "+lhs.getClass(),pd);
Object lp = PropertyUtils.getProperty(lhs, p);
Object rp = PropertyUtils.getProperty(rhs, p);
assertEquals("Property "+p+" is different",lp,rp);
}
}
//
// recipe methods. Control the test environments.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册