How to finish the java constructor throw Exception test?

nuohe 2009-08-19 11:27:32

Test case:
Verify Instance Creation through Constructor DeviceBeanInfo is failed

Summary: Verify Instance Creation through Constructor DeviceBeanInfo is failed
Preconditions: No Preconditions .
Steps:Invoke constructor DeviceBeanInfo .
Expected Results:on invalid operation it should throw IntrospectionException

The testing class:

import java.awt.Image;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.ziptie.addressing.IPAddress;

import com.alterpoint.aof.util.AofBeanInfo;
import com.alterpoint.aof.util.AofPropertyDescriptor;
import com.alterpoint.server.BootActiveStatus;
import com.alterpoint.server.plugin.compliance.status.ComplianceStatus;

/**
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class DeviceBeanInfo extends AofBeanInfo
{
protected BeanDescriptor bd = new BeanDescriptor(com.alterpoint.aof.objects.cm.Device.class);

/** Constructor for the CardBeanInfo object */
public DeviceBeanInfo() throws java.beans.IntrospectionException
{
// setup bean descriptor in constructor.
BeanInfo info = Introspector.getBeanInfo(getBeanDescriptor().getBeanClass().getSuperclass());
String order = info.getBeanDescriptor().getValue("propertyorder") == null ? "" : (String) info.getBeanDescriptor().getValue("propertyorder");
PropertyDescriptor[] pd = getPropertyDescriptors();
for (int i = 0; i != pd.length; i++)
{
if (order.indexOf(pd[i].getName()) == -1)
{
order = order + (order.length() == 0 ? "" : ":") + pd[i].getName();
}
}
getBeanDescriptor().setValue("propertyorder", order);
}

public BeanDescriptor getBeanDescriptor()
{
return this.bd;
}
}

when i attempted to code the test-case, i found that only the block of code "Introspector.getBeanInfo(getBeanDescriptor().getBeanClass().getSuperclass());" would throw the excepted Exception. How do i finish the test case without changing the construtor's code?
...全文
174 8 打赏 收藏 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
the big fundmental 2009-09-23
  • 打赏
  • 举报
回复
严重鄙视之!!!
whuisszl008 2009-08-20
  • 打赏
  • 举报
回复
还以为楼主只会英文或者不能输入汉字,鄙视之,搞得我不想看,欺负我英语没学好啊
nuohe 2009-08-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 bayougeng 的回复:]
在你的构造方法中,提供这样的一种可能性就行了。
我不知道你为什么要让构造方法一定要抛这样的异常。
如果一定要这么做的话,写下面的语句:
if(false){
    String mess = "EXCETION";
    throw new InstrospectionException(mess);
}

[/Quote]
Thanks for your response!
when i attempted to code the test-case, i found that only the block of code "Introspector.getBeanInfo(getBeanDescriptor().getBeanClass().getSuperclass());" would throw the excepted Exception. How do i finish the test case without changing the construtor's code?
nuohe 2009-08-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 bayougeng 的回复:]
在你的构造方法中,提供这样的一种可能性就行了。
我不知道你为什么要让构造方法一定要抛这样的异常。
如果一定要这么做的话,写下面的语句:
if(false){
    String mess = "EXCETION";
    throw new InstrospectionException(mess);
}

[/Quote]
谢谢你的回复,如果在这个测试中不改变测试类的代码,可有什么方法完成这个测试
nuohe 2009-08-19
  • 打赏
  • 举报
回复
我的理解就是验证构造方法DeviceBeanInfo会failed 因为会抛出一个java.beans.IntrospectionException的异常 你就catch一下 然后判断下就好了

谢谢你的回复,但问题在于怎样使其抛出InstrospectionException,就是怎样构造出一种不合法的操作,是其构造器抛出预期的异常
justinavril 2009-08-19
  • 打赏
  • 举报
回复
我的理解就是验证构造方法DeviceBeanInfo会failed 因为会抛出一个java.beans.IntrospectionException的异常 你就catch一下 然后判断下就好了
bayougeng 2009-08-19
  • 打赏
  • 举报
回复
在你的构造方法中,提供这样的一种可能性就行了。
我不知道你为什么要让构造方法一定要抛这样的异常。
如果一定要这么做的话,写下面的语句:
if(false){
String mess = "EXCETION";
throw new InstrospectionException(mess);
}
priestmoon 2009-08-19
  • 打赏
  • 举报
回复
标题的英文有语法错误

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧