是否可以配置自定义工厂以生成
EqualsMethodTester
和
HashCodeMethodTester
来自的类
org.meanbean.test
? 当我通过适用于的配置时
BeanTester
到
等效方法测试仪
,我在错误回溯中得到以下消息:
组织。meanbean。工厂。ObjectCreationException:未能为属性[demoUrl]创建值。
未能为类型为[class java.net.URL]的属性[demoUrl]找到合适的工厂。请注册一家定制工厂。
组织。meanbean。工厂。ObjectCreationException:由于NoSuchMethodException,未能实例化[java.net.URL]类型的对象。
Java语言lang.NoSuchMethodException:
java.net.URL.<init>()
(两者
等效方法测试仪
和
HashCodeMethodTester
给出此错误。将“demoUrl”添加到
insignificantProperties
对于
EqualsMethodTester().testEqualsMethod()
我没有看到任何将配置传递到的选项
HashCodeMethodTester
. 我浏览了以下网站的文档,但既没有找到解决方案,也没有确认缺失的功能:
http://meanbean.sourceforge.net/docs/2.0.3/public/org/meanbean/test/EqualsMethodTester.html
http://meanbean.sourceforge.net/docs/2.0.3/public/org/meanbean/test/HashCodeMethodTester.html
http://meanbean.sourceforge.net/docs/2.0.3/public/org/meanbean/test/ConfigurationBuilder.html
http://meanbean.sourceforge.net/docs/2.0.3/Mean_Bean_2.0.3_User_Guide.pdf
(我使用的是MeanBeanV2.0.3和Java1.8。)
我有以下类,使用
java.net.URL
:
public class Product {
private String name;
private URL demoUrl;
public Product(){
super();
}
public int hashCode() {
return Objects.hash(getName(), whitehawkSKU);
}
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}
Product other = (Product) obj;
return Objects.equals(getName(), other.getName());
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public URL getDemoUrl() {
return demoUrl;
}
public void setDemoUrl(URL demoUrl) {
this.demoUrl = demoUrl;
}
}
meanbean: failed to test bean with arrays
它适用于
BeanTester公司
但不是为了
等效方法测试仪
:
import org.meanbean.lang.Factory;
import java.net.MalformedURLException;
import java.net.URL;
public class URLFactory implements Factory<URL> {
private static int counter = 0;
@Override
public URL create() {
String host = "http://test." + counter + ".url/";
try {
return new URL(host);
}
catch (MalformedURLException except) {
return null;
}
}
}
我的测试方法如下:
private Configuration configureMeanBeanTests() {
URLFactory urlFactory = new URLFactory();
return new ConfigurationBuilder()
.overrideFactory("demoUrl", urlFactory).build();
}
@Test
public void testAccessors() {
new BeanTester().testBean(Product.class, configureMeanBeanTests());
}
@Test
public void testEquals() {
new EqualsMethodTester().testEqualsMethod(
Product.class,
configureMeanBeanTests(),
"name",
"demoUrl"
);
}
@Test
public void testHashCode() {
new HashCodeMethodTester().testHashCodeMethod(Product.class);
}
我错过了什么?