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?

解决方案 »

  1.   

    我的理解就是验证构造方法DeviceBeanInfo会failed 因为会抛出一个java.beans.IntrospectionException的异常  你就catch一下 然后判断下就好了 
      

  2.   

    我的理解就是验证构造方法DeviceBeanInfo会failed 因为会抛出一个java.beans.IntrospectionException的异常  你就catch一下 然后判断下就好了 谢谢你的回复,但问题在于怎样使其抛出InstrospectionException,就是怎样构造出一种不合法的操作,是其构造器抛出预期的异常
      

  3.   

    在你的构造方法中,提供这样的一种可能性就行了。
    我不知道你为什么要让构造方法一定要抛这样的异常。
    如果一定要这么做的话,写下面的语句:
    if(false){
        String mess = "EXCETION";
        throw new InstrospectionException(mess);
    }
      

  4.   

    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?