FeaturesPluginsDocs & SupportCommunityPartners

Refactoring Test Specification

Author: Milan Kubec, Jiri Prox
Version: Revision: 1.1
Last update: Date: 2006/05/23 05:52:48
Introduction: This document is test specification for several kinds of refactoring provided by NetBeans IDE. Refactoring is an action changing inner structure of the code without influencing behaviour of the whole application. It's used above all for simplifying and reorganization of the code. This testspec concerns following types of refactoring:

  • Pull Up
  • Push Down
  • Move Inner to Outer Level
  • Convert Anonymous Class to Inner
  • Use Supertype Where Possible

Comment: Specifications: Pull Up, Push Down, Move Inner to Outer Level, Convert Anonymous Class to Inner, Use Supertype Where Possible.

Table of Contents

Test suite 1: Pull Up

Purpose: Pull Up moves elements of the class to the super class. Moved elements can be fields, methods, inner classes and implemented interfaces. When moving private elements its modifier must be changed to protected in order to be accessible from original class.
Setup: Unzip and open project PushPull.

#Test caseDescription
1Pull Up Availability
Setup: When dialog is opened, check its contents and close it again w/o performing the action
  1. Check presence of Pull Up item in menu Refactor
  2. Select package pull in the project windows and check in Pull Up is disabled both in Refactor | Pull Up and context menu.
  3. Select node corresponding to VIPCustomer.java in project view and call Pull Up
  4. Descend lower in the structure of VIPCustomer class and at each level call Pull Up from the main menu and context menu
  5. Open VIPCustomer class in editor and call Pull Up .
RESULT: Pull Up is present in the menu and is disabled for package scope. When called in the class scope and lower and from editor as well the dialog is opened. It has correct title and provides all inner elements which can be pulled up.
2Pull Up basic
  1. Invoke Refactor | Pull Up for VIPCustomer class
  2. Select all elements, check Show All Changes and press Next
  3. Review all changes and click Do Refactoring
Teardown: Undo all changes
RESULT: In the dialog, there are listed all pull-able elements. Methods have extra checkbox Make abstract. After confirming action, all elements are moved to the superclass.
3Pull Up two and more levels
  1. Invoke Refactor | Pull Up for RegularCustomer class in Editor
  2. Check some fields and methods from the list, select BaseCustomer class as Destination Supertype. The checkbox Show All Changes should be checked because of previous testcase.
  3. Click Next, review all changes and click Do Refactoring
Teardown: Undo all changes
RESULT: Selected elements should be propagated to desired class. Repeat the testcase once more and select class BaseCustomer as Destination Supertype.
4Pull Up and make abstract
  1. Invoke Refactor | Pull Up for VIPCustomer class
  2. Check methods and check Make Abstract checkbox
  3. Click Next, review all changes and click Do Refactoring
Teardown: Undo all changes
RESULT: Empty bodies of selected methods must be created in class Customer, VIPCustomer class must stay unchanged
5Pull up private elements
  1. Invoke Refactor | Pull Up for BaseCustomer class
  2. Check all private elements
  3. Click Next, review all changes and click Do Refactoring
Teardown: Undo all changes
RESULT: All selected elements are moved to superclass and their modificator is changed to protected
6Pull Up selected elements
  1. Open VIPCustomer in editor
  2. Put caret on element which can be pulled up (note: this doesn't work for elements with further inner elements such as classes, inner ifaces etc..)
  3. Call Refactor | Pull Up
Teardown: Undo all changes
RESULT:The element under caret is checked in the refactoring dialog
7Pull Up selected elements II
  1. Browse VIPCustomer in project view
  2. Call Refactoring | Pull Up for each type of node in hierarchical tree
Teardown: Undo all changes
RESULT: Correct row is checked in dialog when action is called for pull-able element (methods, fields ...), otherwise nothing is checked and dialog looks like it was called for the whole class scope.
8Pull Up implemented interfaces
  1. Invoke Refactor | Pull Up for Implementor class
  2. Select all interfaces to be pulled up
  3. Click Next, review all changes and click Do Refactoring
Teardown: Undo all changes
RESULT:The implementation statement is pulled up to superclass
9Pull Up w/o preview
  1. Invoke Refactor | Pull Up for BaseCustomer class
  2. Select some elements, uncheck Show All Changes and press Next
RESULT:Refactoring is performed w/o any further questions
10Pull Up refresh
  1. Invoke Refactor | Pull Up for VIPCustomer class
  2. Select some methods, check Show All Changes if it's unchecked, change Destination Supertype and confirm by pressing Next
  3. In the preview window press refresh button (that one with green arrow)
Teardown: Close dialog without performing refactoring
RESULT: Dialog is reopened, selection of elements is restored as it was before confirming dialog, destination supertype has desired value.
11Pull Up cancel
  1. Invoke Refactor | Pull Up for VIPCustomer class
  2. Select some elements and press Next
  3. In preview press Cancel
RESULT:Action is canceled, no changes were done in the code
12Pull Up - no supertype
  1. Invoke Refactor | Pull Up for ClassWithNoSupertype class
RESULT: Error messages "Cannot pull up any members. The selected type has no supertypes in the currently opened projects" is shown, action cannot continue.
13Pull Up - no elements
  1. Invoke Refactor | Pull Up for ClassWithNoMembers class
RESULT: Error messages "The selected type and its supertypes have no members that could be pulled up." is shown. Action cannot continue.
14Pull Up - no elements selected
  1. Invoke Refactor | Pull Up for VIPCustomer class
  2. Keep all checkboxes unchecked
  3. Press Next
RESULT: In step 2 error "No members are selected to be pulled up." is shown in the lower part of the dialog. In step 3 dialog contains only error message and action cannot continue
15Pull Up undo
  1. Repeat some of the testcase
  2. Use Undo
RESULT:All changes are reverted
16Pull up from interface
  1. Invoke Refactor | Pull Up for SubInterface class
  2. Select some elements
  3. Click Next, review all changes and click Do Refactoring
Teardown: Undo all changes
RESULT: Selected elements are moved to super interface. In the 'Destination Supertype' there are listed all interface convenient as target classes.
17Pull up abstract method
  1. Invoke Refactor | Pull Up for SubAccount class
  2. Select method method in the dialog
  3. Click Next, review all changes and click Do Refactoring
Teardown: Undo all changes
RESULT:In the dialog there is checked and disabled checkbox Make abstract
18Pull Up to interface
  1. Invoke Refactor | Pull Up for ImplementsIface class
  2. Select all methods
  3. Click Next, review all changes and click Do Refactoring
Teardown: Undo all changes
RESULT: Selected elements are moved. In the preview methods elements has checked and disabled checkbox Make abstract.

Test suite 2: Push Down

Purpose: Push down moves selected elements lower to the subclasses. If the actual class has more subclasses the elements are propagated to all of them. All elements such fields, methods, inner classes and implemented interfaces can be pulled down, regardless of their modificators.
Setup: Unzip and open project PushPull

#Test caseDescription
1PushDown availability
  1. Check presence of Push Down item in menu Refactor
  2. Select package push in the project windows and check in Push Down is disabled both in Refactor | Push Down and context menu.
  3. Select node corresponding to SuperBaseClass.java in project view and call Push Down
  4. Descend lower in the structure of the class and at each level call Push Down from the main menu and context menu (close the dialog w/o any action whenever is opened).
  5. Open the class in editor and call Push Down.
RESULT: Push Down is present in the menu and is disabled for package scope. When called in the class scope and lower and from editor as well the dialog is opened. It has correct title and provides all inner elements which can be pushed down.
2Push Down basic
  1. Invoke Refactor | Push Down for SuperBaseClass class
  2. Select all elements, check Show All Changes and press Next
  3. Review all changes and click Do Refactoring
Teardown: Undo all changes
RESULT: All elements should be moved to all subclasses. Note that in BaseClass1 there is already present fieldString so the relevant checkbox is unchecked by default in the preview. Necessary imports are added to all subclasses.
3Push Down selected element
  1. Open SuperBaseClass in editor
  2. Put caret on element which can be pushed down (note: this doesn't work for elements with further inner elements such as classes, inner ifaces etc..)
  3. Call Refactor | Push Down
RESULT: When caret is located in pushable element the relevant checkbox is checked in the refactoring dialog
4Push Down selected element II
  1. Select node SuperBaseClass.java in project view
  2. Browse the inner structure and for each type of node call Push Down
RESULT: When node for pushable element is selected the relevant check box is is checked in refactoring dialog
5Push Down implemented interface
  1. Invoke Refactor | Push Down for MySuperClass class
  2. Select implementing Serializable in the dialog
  3. Click Next, review all changes and click Do Refactoring
Teardown: Undo all changes
RESULT:The class MySubClass will now implement Serializable instead of MySuperClass
6Push Down and keep abstract
  1. Invoke Refactor | Push Down for MySuperClass class
  2. Select methods getX and setX and check keep abstract for both of them
  3. Click Next, review all changes and click Do Refactoring
Teardown: Undo all changes
RESULT: Both methods are moved to subclass, in the current class abstract methods are created instead of them. Note that modifier of x changed from private to protected.
7Push Down w/o preview
  1. Invoke Refactor | Push Down for SuperBaseClass class
  2. Select some elements, uncheck Show All Changes and press Next
Teardown: Undo all changes
RESULT:Refactoring is performed w/o any further questions
8Push Down refresh
  1. Invoke Refactor | Push Down for SuperBaseClass class
  2. Select some elements, check Show All Changes if it's unchecked and confirm by pressing Next
  3. In the preview window press refresh button (that one with green arrow)
RESULT: Dialog is reopened, selection of elements is restored as it was before confirming dialog.
9Push Down cancel
  1. Invoke Refactor | Push Down for SuperBaseClass class
  2. Select some elements and press Next
  3. In preview press Cancel
RESULT:Action is canceled, no changes were done in the code
10Push Down - no subtype
  1. Invoke Refactor | Push Down for EmptyClass2 class
RESULT: Error "Cannot push down any members. The selected type has no subtypes in the currently opened projects." is displayed. Action cannot continue.
11Push Down - no elements
  1. Invoke Refactor | Push Down for SuperSuper class
RESULT: Error "The selected type has no members that could be pushed down." is displayed. Action cannot continue.
12Push Down - no elements selected
  1. Invoke Refactor | Push Down for SuperBaseClass class
  2. Keep all checkboxes unchecked
  3. Press Next
RESULT: Dialog with message "No members are selected to be pushed down." is displayed. Action cannot continue.
13Push Down undo
  1. Repeat some of the testcase
  2. Use Undo
RESULT:All changes are reverted
14Push Down from interface
  1. Invoke Refactor | Push Down for SuperInterface class
  2. Select all elements, check Show All Changes and press Next
  3. Review all changes and click Do Refactoring
RESULT:All elements are moved to sub interface

Test suite 3: Inner to Outer

Purpose: This type of refactoring moves inner class one level up. If it was originally in the top level class it is moved to separate file. The problem with accessing elements in the original outer class is solved by adding parameter to constructor passing instance of outer class.
Setup: Unzip and open project ConvertClasses

#Test caseDescription
1Inner to Outer availability
  1. Check if item Move Inner to Outer Level is present in manu Refactor and in context menu for relevant objects.
  2. Browse through the structure of class moveinner.OuterClass in projects window, call Move Inner to Outer Level for each type of element.
  3. Open class OuterClass in editor and call refactoring from various position in the class
RESULT: Menu item is valid and is enabled for all types of elements except package. When refactoring is called for element which is inner class the dialog asking for further options is opened. Otherwise warning is displayed and action cannot continue.
2Inner to Outer - basic
  1. Call Move Inner to Outer Level for class Inner1 located in OuterClass
  2. In the dialog change Class Name to Rename,Field Name to orig and check Preview All Changes
  3. Click Next, review all changes and confirm by Do Refactoring
Teardown: Undo all changes
RESULT: New file with class Renamed is created. Its constructor has one parameter orig of type OuterClass. The occurrences of Inner1 is replaced with the new name. The modifiers of field and privMethod are changed to package public. The getInner() method of the original outer class contains return new Renamed(this);. Class User has correct reference to new class.
3Inner to Outer - static class
  1. Call Move Inner to Outer Level for class Inner2 located in OuterClass
  2. Keep all options as default
  3. Click Next, review all changes and confirm by Do Refactoring
Teardown: Undo all changes
RESULT: The class is moved into new file as top-level class. Class User has correct reference to moved class.
4Inner to Outer - interfaces
  1. Call Move Inner to Outer Level for class InnerIface located in OuterClass
  2. In the dialog change Class Name
  3. Click Next, review all changes and confirm by Do Refactoring
Teardown: Undo all changes
RESULT: Interface is moved to separate file. Reference in class User is updated
5Inner to Outer - enum
  1. Call Move Inner to Outer Level for class InnerEnum located in OuterClass
  2. In the dialog change Class Name
  3. Click Next, review all changes and confirm by Do Refactoring
Teardown: Undo all changes
RESULT:Enum is moved to separate file. Reference in class User is updated
6Inner to Outer - annotations
  1. Call Move Inner to Outer Level for class InnerEnum located in OuterClass
  2. In the dialog change Class Name
  3. Click Next, review all changes and confirm by Do Refactoring
Teardown: Undo all changes
RESULT: Annotation is moved to separate file. Reference in class User is updated
7Inner to Outer - fix imports
  1. Call Move Inner to Outer Level for class FileHandler located in Wrapper class
  2. Keep all defaults and perform refactoring
Teardown: Undo all changes
RESULT:Class is moved to a separate file with all necessary imports.
8Inner to Outer - constructors
  1. Call Move Inner to Outer Level for class InnerClass located in Wrapper class
  2. In the dialog, leave all options as default
  3. Click Next, review all changes and confirm by Do Refactoring
Teardown: Undo all changes
RESULT: New separate file with class Inner is created. All constructors are updated to accept reference to outer class as additional parameter.
9Inner to Outer - two levels
  1. Call Move Inner to Outer Level for class InnerInner located in Wrapper class
  2. Keep all as default, perform refactoring
  3. Call Move Inner to Outer Level for class InnerInner again
  4. Keep all as default, perform refactoring
Teardown: Undo all changes
RESULT: The InnerInner class is step by step propagated to outer level. The reference to previous outer classes are added to constructor.
10Inner to Outer - w/o preview
  1. Call Move Inner to Outer Level for class Inner1 located in OuterClass
  2. In the dialog uncheck Preview All Changes
  3. Click Next
Teardown: Undo all changes
RESULT:Action is performed w/o preview
11Inner to Outer - cancel
  1. Call Move Inner to Outer Level for class Inner1 located in OuterClass
  2. In the dialog check Preview All Changes (should be unchecked because of previous test case)
  3. Click Next
  4. In preview click Cancel
RESULT:There are no changes in the code
12Inner to Outer - refresh
  1. Call Move Inner to Outer Level for class Inner1 located in OuterClass
  2. In the dialog change Class Name and Field Name
  3. Click Next
  4. In preview click Refresh (button with the green arrow)
Teardown: Close dialog w/o refactoring
RESULT:The refactoring dialog is reopened, all values are restored

Test suite 4: Anonymous to Inner

Purpose: This refactoring converts selected anonymous class to regular inner class. The user is allowed to change its name, modificator and order of constructor's parameters.
Setup: Unzip and open project ConvertClasses

#Test caseDescription
1Anon to Inner availability
  1. Check presence of Convert Anonymous Class to Inner item in menu Refactor
  2. Browse through the structure of class convertanon.ClassA in projects window, call Convert Anonymous Class to Inner for each type of element.
  3. Open ClassA in editor and call refactoring from various position in the class
RESULT: When refactoring is called for anonymous class element from editor refactoring dialog is opened. Otherwise message No anonymous class selected. is displayed.
2Anon to Inner - basic
  1. Open ClassA in editor and call refactoring for its anonymous class.
  2. Change Inner Class Name, change Access combo box value and check Preview All Changes.
  3. Click Next, review all changes and confirm by Do Refactoring
Teardown: Undo all changes
RESULT:New inner class with proper name is created.
3Anon to Inner - constructor
  1. Open ClassB in editor and call refactoring for its anonymous class.
  2. Check the checkbox Declare Static.
  3. Click Next, review all changes and confirm by Do Refactoring
Teardown: Undo all changes
RESULT: When the dialog is opened, there is one row in the table of constructors parameters. After the action is finished, new inner class is created with correct constructors.
4Anon to Inner - constructor param
  1. Open ClassD in editor and call refactoring for its anonymous class.
  2. In the dialog change order of the table row
  3. Click Next, review all changes and confirm by Do Refactoring
Teardown: Undo all changes
RESULT:Class is converted to inner. Parameters of constructor are in desired order.
5Anon to Inner - cannot be static
  1. Open ClassA in editor and call refactoring for its anonymous class.
  2. Check Declare Static
  3. Click Next.
Teardown: Close dialog
RESULT: Refactoring cannot continue. The dialog displays The anonymous class accesses instance features in outer class, it cannot be declared static.
6Anon to Inner - w/o preview
  1. Open ClassA in editor and call refactoring for its anonymous class.
  2. Uncheck Preview All Changes
  3. Click Next.
Teardown: Undo all changes
RESULT:Action is performed w/o further questions
7Anon to Inner - cancel
  1. Open ClassA in editor and call refactoring for its anonymous class.
  2. Check Preview All Changes if it is unchecked due to previous test case and click Next
  3. In preview window click Cancel
RESULT:Refactoring is canceled, no changes are made to the code.
8Anon to Inner - refresh
  1. Open ClassD in editor and call refactoring for its anonymous class.
  2. Change Inner Class Name, Access, check Declare Static, order of Constructor Parameters, click Next
  3. In preview click Refresh (button with the green arrow)
Teardown: Close dialog
RESULT:The dialog is reopened, all options are set to desired values
9Anon to Inner - ilegal name
  1. Open ClassD in editor and call refactoring for its anonymous class.
  2. Input illegal name as Inner Class Name as "123" or "a.b.c"
Teardown: Close dialog
RESULT: Error ... is not a valid Java identifier is shown in the bottom of dialog. Next button is disabled

Test suite 5: Use Supertype

Purpose: This kind of refactoring tries to use selected supertype where possible, e.g. changes the type of variable to the supertype if it doesn't use methods or fields of any its subtype.
Setup: Unzip and open project ConvertClasses

#Test caseDescription
1Use Supertype - availability
  1. Check presence of Use Supertype Where Possible item in menu Refactor
  2. Browse through the structure of class usesupertype.Sub in projects window, call Use Supertype Where Possible for each type of element.
  3. Open Sub in editor and call refactoring from various position in the class
RESULT: Use Supertype Where Possible is enabled available for classes, e.g form node corresponding to java file and form node corresponding directly to the class. In the editor the menu item is always enabled but when it is called not from class scope or for identifier of class message Use Supertype can only be invoked on valid types is shown.
2Use Supertype - basic
  1. Call Use Supertype Where Possible for class Sub
  2. Select java.lang.Object from the list and check Preview All Changes
  3. Click Next, review all changes and confirm by Do Refactoring
Teardown: Undo all changes
RESULT: Occurrence is found, check the class User, there should be s6 retyped to Object.
3Use Supertype - select type
  1. Call Use Supertype Where Possible for class Sub
  2. Select one item form the list
  3. Click Next, review all changes and confirm by Do Refactoring
Teardown: Undo all changes
RESULT:The identifiers s? should be typed according to the selected type
4Use Supertype - w/o preview
  1. Call Use Supertype Where Possible for class Sub
  2. Select one item from the list, uncheck Preview All Changes
  3. Click Next
Teardown: Undo all changes
RESULT:The action is performed w/o preview
5Use Supertype - cancel
  1. Call Use Supertype Where Possible for class Sub
  2. Select one item from the list, check Preview All Changes if it is unchecked, click Next.
  3. In the preview click Cancel
Teardown: Close dialog
RESULT:Refactoring is canceled, no changes are made to the code.
6Use Supertype - refresh
  1. Call Use Supertype Where Possible for class Sub
  2. Select one item from the list, click Next
  3. In preview click Refresh (button with the green arrow)
Teardown: Close dialog
RESULT:Dialog is reopened, previous selection is restored

Generated: 2006 06 02 01:33
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by