TS 61 Beans

Beans support test specification

Author: Jiri Prox
Version: 6.1
Last update: 08/02/2008
Introduction: This is test specification for beans support in NetBeans. It describes generating getters and setters and generating event firing support

Contents


Test suite: Beans property

Purpose: ""
Setup: "Open empty java class in editor"

  1. Adding property
    1. Put caret inside class body
    2. Press Alt-insert and select "Add property"
    3. Change Name, default value (at the same line as Name, behind '=') and Type text field to "prop","1","int"
    4. Keep other options as default and press OK
    • EXPECTED RESULT: New field and its getter and setter are generated.
  2. Access modifier
    1. Open Add property dialog
    2. Try to change access modifier
    3. Try selecting "static" and "final" checkbox
    4. Confirm dialog
    • EXPECTED RESULT: The field has expected modifier, getter & setter are always public. When final is selected, only getter can be generated. When static is selected, event firing support cannot be generated
  3. Getter/Setter
    1. Open Add property dialog
    2. Try generate only setter or getter
    • EXPECTED RESULT: Getter or setter is generated according to specified values
  4. Indexed
    1. Open Add property dialog
    2. Check "indexed" checkbox
    3. Enter property name, type and default value
    • EXPECTED RESULT:
   private String[] indexed_prop = {"a", "b", "c"};
   /**
    * Get the value of indexed_prop
    *
    * @return the value of indexed_prop
    */
   public String[] getIndexed_prop() {
       return this.indexed_prop;
   }
   /**
    * Set the value of indexed_prop
    *
    * @param newindexed_prop new value of indexed_prop
    */
   public void setIndexed_prop(String[] newindexed_prop) {
       this.indexed_prop = newindexed_prop;
   }
   /**
    * Get the value of indexed_prop at specified index
    *
    * @param index
    * @return the value of indexed_prop at specified index
    */
   public String getIndexed_prop(int index) {
       return this.indexed_prop[Index];
   }
   /**
    * Set the value of indexed_prop at specified index.
    *
    * @param index
    * @param newindexed_prop new value of indexed_prop at specified index
    */
   public void setIndexed_prop(int index, String newindexed_prop) {
       this.indexed_prop[Index] = newindexed_prop;
   }
  1. Javadoc
    1. Try any from the previous usecase
    2. Check the javadoc is correct in preview and in generated code
    3. Unselect javadoc checkbox
    4. Confirm dialog
    • EXPECTED RESULT: All method has javadoc stub. After unselecting the checkbox no javadoc is present in preview and generated code


Test suite: Firing events support

  1. Property change support
    1. Open Add property dialog
    2. Enter any property name and type
    3. Check "Generate Property Change Support"
    • EXPECTED RESULT: The firing event support is added in preview and into generated code. For property change this code is added:
   private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
   /**
    * Add PropertyChangeListener.
    *
    * @param listener
    */
   public void addPropertyChangeListener(PropertyChangeListener listener) {
       propertyChangeSupport.addPropertyChangeListener(listener);
   }
   /**
    * Remove PropertyChangeListener.
    *
    * @param listener
    */
   public void removePropertyChangeListener(PropertyChangeListener listener) {
       propertyChangeSupport.removePropertyChangeListener(listener);
   }        
  1. Property vetoable change support
    1. Open Add property dialog
    2. Enter any property name and type
    3. Check "Generate Vetoable Change Support"
    • EXPECTED RESULT: This code is added for vetoable change
   private VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this);
   /**
    * Add VetoableChangeListener.
    *
    * @param listener
    */
   public void addVetoableChangeListener(VetoableChangeListener listener) {
       vetoableChangeSupport.addVetoableChangeListener(listener);
   }
   /**
    * Remove VetoableChangeListener.
    *
    * @param listener
    */
   public void removeVetoableChangeListener(VetoableChangeListener listener) {
       vetoableChangeSupport.removeVetoableChangeListener(listener);
   }
  1. Bound property
    1. Open Add property dialog
    2. Enter name and type
    3. Select Bound checkbox, and specify its name
    • EXPECTED RESULT: Besides the property itself another filed is added and setter is changed as in following code:
          
      
   public static final String PROP_PROP = "prop";
   public void setProp(String newprop) {
       String oldprop = prop;
       this.prop = newprop;
       propertyChangeSupport.firePropertyChange(PROP_PROP, oldprop, newprop);
   }
  1. Vetoable property
    1. Open Add property dialog
    2. Enter name and type
    3. Select Bound checkbox, specify its name and select Vetoable checkbox
    • EXPECTED RESULT: Besides the property itself another filed is added and setter is changed as in following code:
   public void setProp(String newprop) throws java.beans.PropertyVetoException {
       String oldprop = prop;
       vetoableChangeSupport.fireVetoableChange(PROP_PROP, oldprop, newprop);
       this.prop = newprop;
       propertyChangeSupport.firePropertyChange(PROP_PROP, oldprop, newprop);
   }
  1. Javadoc
    1. Check javadoc for all method of event firing support
    • EXPECTED RESULT: All javadoc stubs are present
  2. Indexed bound property
    1. Add new indexed vetoable bound property
    • EXPECTED RESULT: The both setters are changed to
   public void setString(String[] newstring) throws java.beans.PropertyVetoException {
       String[] oldstring = string;
       vetoableChangeSupport.fireVetoableChange(PROP_STRING, oldstring, newstring);
       this.string = newstring;
       propertyChangeSupport.firePropertyChange(PROP_STRING, oldstring, newstring);
   }
   public void setString(int index, String newstring) throws java.beans.PropertyVetoException {
       String oldstring = string[Index];
       vetoableChangeSupport.fireVetoableChange(PROP_STRING, oldstring, newstring);
       this.string[Index] = newstring;
       propertyChangeSupport.fireIndexedPropertyChange(PROP_STRING, index, oldstring, newstring);
   }


Test suite: Beans patterns recognition

  1. Single property
    1. Open empty class and select Beans Patterns in the combo-box in the Navigator window
    2. Manually add getter method
    3. Manually add setter method
    4. Modify getter/setter name, return type etc...
    • EXPECTED RESULT: The beans pattern is recognized in the Navigator, the type and name of property is correctly derived from methods name. The icon indicates if the property is read only, write only or read/write
  2. indexed property
    1. Open empty class and select Beans Patterns in navigator
    2. Manually add getter method for indexed property (e.g. method <TYPE> get<NAME>(int index) )
    3. Manually add setter method for indexed property (e.g. method void set<NAME>(<TYPE> value,int index) )
    4. Change names, return types and argument types
    5. Add getter/setter method for single property (<TYPE> get<NAME>() and void set<NAME>(<TYPE> value) )
    • EXPECTED RESULT: The index property is recognized properly, only indexed property is shown in navigator when both types of getter/setter are present
  3. Change support
    1. Manually add methods for even firing support (public void addPropertyChangeListener(PropertyChangeListener listener) and public void removePropertyChangeListener(PropertyChangeListener listener) )
    2. Manually add support for vetoable change (public void addVetoableChangeListener(VetoableChangeListener listener) and public void removeVetoableChangeListener(VetoableChangeListener listener) )
    • EXPECTED RESULT: Event firing support is recognized and proper node is added to navigator.


Test suite: Miscellaneous

  1. Duplicate names
    1. Open Add property dialog
    2. Try to add property which match already existing field
    3. Specify bound name to value which is already added
    • EXPECTED RESULT: The property generation cannot continue, there is clear message in the dialog
  2. Type selection
    1. Open Add property dialog
    2. Check all primitive types + String is in type combobox
    3. Try use Browse button to select the type
    • {{result|EXPECTED RESULT: All primitive types are present, Browse button opens the dialog for selecting class name, the correct class name is inserted in the code when dialog is confirmed
  3. Duplicate change support
    1. Open class where is present support for firing events
    2. Open Add property dialog
    • EXPECTED RESULT: Appropriate checkbox is disabled, so the support cannot be generated twice
  4. Inner classes
    1. Call Add Property within inner class
    • EXPECTED RESULT: The getter/setter are added to proper class
  5. Generate inside method
    1. Put caret inside method body
    2. Call Add property
    • EXPECTED RESULT: Getter/Setter are added to correct position (e.g. in class body, not in method body)
  6. Availability
    1. Create a new annotation type, enum and interface inside the existing class
    2. Try to call Add Property from bodies of enum, interface and annotation type
    3. Create a new files: Java Annotation Type, Java Enum and Java Interface (File > New File, select the Java category)
    4. Try to call Add Property from Insert Code menu in each file
    • EXPECTED RESULT: Add Property is NOT available INSIDE the interface and the annotation type, but it is available in the enum.


Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo