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:
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 case
Description
1
Pull Up Availability
Setup:
When dialog is opened, check its contents and close it again w/o performing the action
Check presence of Pull Up item in menu Refactor
Select package pull in the project windows and check in Pull Up is disabled both in Refactor | Pull Up and context menu.
Select node corresponding to VIPCustomer.java in project view and call Pull Up
Descend lower in the structure of VIPCustomer class and at each level call Pull Up from the main menu and context menu
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.
2
Pull Up basic
Invoke Refactor | Pull Up for VIPCustomer class
Select all elements, check Show All Changes and press Next
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.
3
Pull Up two and more levels
Invoke Refactor | Pull Up for RegularCustomer class in Editor
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.
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.
4
Pull Up and make abstract
Invoke Refactor | Pull Up for VIPCustomer class
Check methods and check Make Abstract checkbox
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
5
Pull up private elements
Invoke Refactor | Pull Up for BaseCustomer class
Check all private elements
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
6
Pull Up selected elements
Open VIPCustomer in editor
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..)
Call Refactor | Pull Up
Teardown:
Undo all changes
RESULT:
The element under caret is checked in the refactoring dialog
7
Pull Up selected elements II
Browse VIPCustomer in project view
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.
8
Pull Up implemented interfaces
Invoke Refactor | Pull Up for Implementor class
Select all interfaces to be pulled up
Click Next, review all changes and click Do Refactoring
Teardown:
Undo all changes
RESULT:
The implementation statement is pulled up to superclass
9
Pull Up w/o preview
Invoke Refactor | Pull Up for BaseCustomer class
Select some elements, uncheck Show All Changes and press Next
RESULT:
Refactoring is performed w/o any further questions
10
Pull Up refresh
Invoke Refactor | Pull Up for VIPCustomer class
Select some methods, check Show All Changes if it's unchecked, change Destination Supertype and confirm by pressing Next
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.
11
Pull Up cancel
Invoke Refactor | Pull Up for VIPCustomer class
Select some elements and press Next
In preview press Cancel
RESULT:
Action is canceled, no changes were done in the code
12
Pull Up - no supertype
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.
13
Pull Up - no elements
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.
14
Pull Up - no elements selected
Invoke Refactor | Pull Up for VIPCustomer class
Keep all checkboxes unchecked
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
15
Pull Up undo
Repeat some of the testcase
Use Undo
RESULT:
All changes are reverted
16
Pull up from interface
Invoke Refactor | Pull Up for SubInterface class
Select some elements
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.
17
Pull up abstract method
Invoke Refactor | Pull Up for SubAccount class
Select method method in the dialog
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
18
Pull Up to interface
Invoke Refactor | Pull Up for ImplementsIface class
Select all methods
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.
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 case
Description
1
PushDown availability
Check presence of Push Down item in menu Refactor
Select package push in the project windows and check in Push Down is disabled both in Refactor | Push Down and context menu.
Select node corresponding to SuperBaseClass.java in project view and call Push Down
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).
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.
2
Push Down basic
Invoke Refactor | Push Down for SuperBaseClass class
Select all elements, check Show All Changes and press Next
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.
3
Push Down selected element
Open SuperBaseClass in editor
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..)
Call Refactor | Push Down
RESULT:
When caret is located in pushable element the relevant checkbox is checked in the refactoring dialog
4
Push Down selected element II
Select node SuperBaseClass.java in project view
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
5
Push Down implemented interface
Invoke Refactor | Push Down for MySuperClass class
Select implementing Serializable in the dialog
Click Next, review all changes and click Do Refactoring
Teardown:
Undo all changes
RESULT:
The class MySubClass will now implement Serializable instead of MySuperClass
6
Push Down and keep abstract
Invoke Refactor | Push Down for MySuperClass class
Select methods getX and setX and check keep abstract for both of them
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.
7
Push Down w/o preview
Invoke Refactor | Push Down for SuperBaseClass class
Select some elements, uncheck Show All Changes and press Next
Teardown:
Undo all changes
RESULT:
Refactoring is performed w/o any further questions
8
Push Down refresh
Invoke Refactor | Push Down for SuperBaseClass class
Select some elements, check Show All Changes if it's unchecked and confirm by pressing Next
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.
9
Push Down cancel
Invoke Refactor | Push Down for SuperBaseClass class
Select some elements and press Next
In preview press Cancel
RESULT:
Action is canceled, no changes were done in the code
10
Push Down - no subtype
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.
11
Push Down - no elements
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.
12
Push Down - no elements selected
Invoke Refactor | Push Down for SuperBaseClass class
Keep all checkboxes unchecked
Press Next
RESULT:
Dialog with message "No members are selected to be pushed down." is displayed. Action cannot continue.
13
Push Down undo
Repeat some of the testcase
Use Undo
RESULT:
All changes are reverted
14
Push Down from interface
Invoke Refactor | Push Down for SuperInterface class
Select all elements, check Show All Changes and press Next
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 case
Description
1
Inner to Outer availability
Check if item Move Inner to Outer Level is present in manu Refactor and in context menu for relevant objects.
Browse through the structure of class moveinner.OuterClass in projects window, call Move Inner to Outer Level for each type of element.
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.
2
Inner to Outer - basic
Call Move Inner to Outer Level for class Inner1 located in OuterClass
In the dialog change Class Name to Rename,Field Name to orig and check Preview All Changes
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.
3
Inner to Outer - static class
Call Move Inner to Outer Level for class Inner2 located in OuterClass
Keep all options as default
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.
4
Inner to Outer - interfaces
Call Move Inner to Outer Level for class InnerIface located in OuterClass
In the dialog change Class Name
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
5
Inner to Outer - enum
Call Move Inner to Outer Level for class InnerEnum located in OuterClass
In the dialog change Class Name
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
6
Inner to Outer - annotations
Call Move Inner to Outer Level for class InnerEnum located in OuterClass
In the dialog change Class Name
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
7
Inner to Outer - fix imports
Call Move Inner to Outer Level for class FileHandler located in Wrapper class
Keep all defaults and perform refactoring
Teardown:
Undo all changes
RESULT:
Class is moved to a separate file with all necessary imports.
8
Inner to Outer - constructors
Call Move Inner to Outer Level for class InnerClass located in Wrapper class
In the dialog, leave all options as default
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.
9
Inner to Outer - two levels
Call Move Inner to Outer Level for class InnerInner located in Wrapper class
Keep all as default, perform refactoring
Call Move Inner to Outer Level for class InnerInner again
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.
10
Inner to Outer - w/o preview
Call Move Inner to Outer Level for class Inner1 located in OuterClass
In the dialog uncheck Preview All Changes
Click Next
Teardown:
Undo all changes
RESULT:
Action is performed w/o preview
11
Inner to Outer - cancel
Call Move Inner to Outer Level for class Inner1 located in OuterClass
In the dialog check Preview All Changes (should be unchecked because of previous test case)
Click Next
In preview click Cancel
RESULT:
There are no changes in the code
12
Inner to Outer - refresh
Call Move Inner to Outer Level for class Inner1 located in OuterClass
In the dialog change Class Name and Field Name
Click Next
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
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 case
Description
1
Anon to Inner availability
Check presence of Convert Anonymous Class to Inner item in menu Refactor
Browse through the structure of class convertanon.ClassA in projects window, call Convert Anonymous Class to Inner for each type of element.
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.
2
Anon to Inner - basic
Open ClassA in editor and call refactoring for its anonymous class.
Change Inner Class Name, change Access combo box value and check Preview All Changes.
Click Next, review all changes and confirm by Do Refactoring
Teardown:
Undo all changes
RESULT:
New inner class with proper name is created.
3
Anon to Inner - constructor
Open ClassB in editor and call refactoring for its anonymous class.
Check the checkbox Declare Static.
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.
4
Anon to Inner - constructor param
Open ClassD in editor and call refactoring for its anonymous class.
In the dialog change order of the table row
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.
5
Anon to Inner - cannot be static
Open ClassA in editor and call refactoring for its anonymous class.
Check Declare Static
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.
6
Anon to Inner - w/o preview
Open ClassA in editor and call refactoring for its anonymous class.
Uncheck Preview All Changes
Click Next.
Teardown:
Undo all changes
RESULT:
Action is performed w/o further questions
7
Anon to Inner - cancel
Open ClassA in editor and call refactoring for its anonymous class.
Check Preview All Changes if it is unchecked due to previous test case and click Next
In preview window click Cancel
RESULT:
Refactoring is canceled, no changes are made to the code.
8
Anon to Inner - refresh
Open ClassD in editor and call refactoring for its anonymous class.
Change Inner Class Name, Access, check Declare Static, order of Constructor Parameters, click Next
In preview click Refresh (button with the green arrow)
Teardown:
Close dialog
RESULT:
The dialog is reopened, all options are set to desired values
9
Anon to Inner - ilegal name
Open ClassD in editor and call refactoring for its anonymous class.
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
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 case
Description
1
Use Supertype - availability
Check presence of Use Supertype Where Possible item in menu Refactor
Browse through the structure of class usesupertype.Sub in projects window, call Use Supertype Where Possible for each type of element.
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.
2
Use Supertype - basic
Call Use Supertype Where Possible for class Sub
Select java.lang.Object from the list and check Preview All Changes
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.
3
Use Supertype - select type
Call Use Supertype Where Possible for class Sub
Select one item form the list
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
4
Use Supertype - w/o preview
Call Use Supertype Where Possible for class Sub
Select one item from the list, uncheck Preview All Changes
Click Next
Teardown:
Undo all changes
RESULT:
The action is performed w/o preview
5
Use Supertype - cancel
Call Use Supertype Where Possible for class Sub
Select one item from the list, check Preview All Changes if it is unchecked, click Next.
In the preview click Cancel
Teardown:
Close dialog
RESULT:
Refactoring is canceled, no changes are made to the code.
6
Use Supertype - refresh
Call Use Supertype Where Possible for class Sub
Select one item from the list, click Next
In preview click Refresh (button with the green arrow)
Teardown:
Close dialog
RESULT:
Dialog is reopened, previous selection is restored