TS 60 Refactoring3

Refactoring Test Specification for

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


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

Contents


Test suite: 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.

  1. Pull Up Availability
    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. Open VIPCustomer class in editor and call Pull Up .
    • EXPECTED RESULT: Pull Up is present in the menu and is disabled for package scope. When called in the class scope and in editor the dialog is opened. It has correct title and provides all inner elements which can be pulled up.
  2. Pull Up basic
    1. Invoke Refactor | Pull Up for VIPCustomer class
    2. Select class Customer as a target
    3. Select all elements and press Preview
    4. Review all changes and click Do Refactoring
    • EXPECTED 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. (There is error in RegularCustomer class after the refactoring - invalid method overriding)
  3. Pull 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.
    3. Click Preview, review all changes and click Do Refactoring
    • EXPECTED 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
    1. Invoke Refactor | Pull Up for VIPCustomer class
    2. Check methods and check Make Abstract checkbox
    3. Select Customer as a target
    4. Click Preview, review all changes and click Do Refactoring
    • EXPECTED RESULT: Empty bodies of selected methods must be created in class Customer , VIPCustomer class must stay unchanged (there is error, since the other subclass of Customer does not implement pulled methods)
  5. Pull up private elements
    1. Invoke Refactor | Pull Up for BaseCustomer class
    2. Check all private elements
    3. Click Preview, review all changes and click Do Refactoring
    • EXPECTED RESULT: All selected elements are moved to superclass and their modificator is changed to protected
  6. Pull 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
    • EXPECTED RESULT: The element under caret is checked in the refactoring dialog
  7. Pull Up implemented interfaces
    1. Invoke Refactor | Pull Up for Implementor class
    2. Select all interfaces to be pulled up
    3. Click Preview, review all changes and click Do Refactoring
    • EXPECTED RESULT: The implementation statement is pulled up to superclass
  8. Pull Up w/o preview
    1. Invoke Refactor | Pull Up for BaseCustomer class
    2. Select some elements, Refactor
    • EXPECTED RESULT: Refactoring is performed w/o any further questions
  9. Pull Up refresh
    1. Invoke Refactor | Pull Up for VIPCustomer class
    2. Select some methods, change Destination Supertype and confirm by pressing Preview
    3. In the preview window press refresh button (that one with green arrow)
    • EXPECTED RESULT: Dialog is reopened, selection of elements is restored as it was before confirming dialog, destination supertype has desired value.
  10. Pull Up cancel
    1. Invoke Refactor | Pull Up for VIPCustomer class
    2. Select some elements and press Preview
    3. In preview press Cancel
    • EXPECTED RESULT: Action is canceled, no changes were done in the code
  11. Pull Up - no supertype
    1. Invoke Refactor | Pull Up for ClassWithNoSupertype class
    • EXPECTED RESULT: Error messages "Cannot pull up any members. The selected type has no supertypes in the currently opened projects" is shown, action cannot continue.
  12. Pull Up - no elements
    1. Invoke Refactor | Pull Up for ClassWithNoMembers class
    • EXPECTED RESULT: Error messages "The selected type and its supertypes have no members that could be pulled up." is shown. Action cannot continue.
  13. Pull Up - no elements selected
    1. Invoke Refactor | Pull Up for VIPCustomer class
    2. Keep all checkboxes unchecked
    3. Press Preview
    • EXPECTED 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.
  14. Pull Up undo
    1. Repeat some of the testcase
    2. Use Undo
    • EXPECTED RESULT: All changes are reverted.
  15. Pull up from interface
    1. Invoke Refactor | Pull Up for SubInterface class
    2. Select some elements
    3. Click Preview, review all changes and click Do Refactoring
    • EXPECTED RESULT: Selected elements are moved to super interface. In the 'Destination Supertype' there are listed all interface convenient as target classes.
  16. Pull Up to interface
    1. Invoke Refactor | Pull Up for ImplementsIface class
    2. Select all methods
    3. Click Preview, review all changes and click Do Refactoring
    • EXPECTED RESULT: Selected elements are moved. In the preview methods elements has checked and disabled checkbox Make abstract.


Test suite: 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

  1. Push Down basic
    1. Invoke Refactor | Push Down for SuperBaseClass class
    2. Select all elements and press Preview
    3. Review all changes and click Do Refactoring
    • EXPECTED RESULT: All elements should be moved to all subclasses. Note that there is warning about field fieldString , which already exists in one of the subclasses. When refactoring is performed, the declaration of fieldString is doubled in one of the subclasses. Necessary imports are added to all subclasses.
  2. Push 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
    • EXPECTED RESULT: When caret is located in pushable element the relevant checkbox is checked in the refactoring dialog.
  3. Push Down implemented interface
    1. Invoke Refactor | Push Down for MySuperClass class
    2. Select implementing Serializable in the dialog
    3. Click Preview and click Do Refactoring
    • EXPECTED RESULT: The class MySubClass will now implement Serializable instead of MySuperClass
  4. Push 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 (push down the field x as well)
    3. Click Preview and click Do Refactoring
    • EXPECTED 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.
  5. Push Down w/o preview
    1. Invoke Refactor | Push Down for SuperBaseClass class
    2. Select some elements and press Refactor
    • EXPECTED RESULT: Refactoring is performed w/o any further questions.
  6. Push Down refresh
    1. Invoke Refactor | Push Down for SuperBaseClass class
    2. Select some elements and confirm by pressing Preview
    3. In the preview window press refresh button (that one with green arrow)
    • EXPECTED RESULT: Dialog is reopened, selection of elements is restored as it was before confirming dialog.
  7. Push Down cancel
    1. Invoke Refactor | Push Down for SuperBaseClass class
    2. Select some elements and press Preview
    3. In preview press Cancel
    • EXPECTED RESULT: Action is canceled, no changes were done in the code.
  8. Push Down - no subtype
    1. Invoke Refactor | Push Down for EmptyClass2 class
    • EXPECTED RESULT: Error "Cannot push down any members. The selected type has no subtypes in the currently opened projects." is displayed. Action cannot continue.
  9. Push Down - no elements
    1. Invoke Refactor | Push Down for SuperSuper class
    • EXPECTED RESULT: Error "The selected type has no members that could be pushed down." is displayed. Action cannot continue.
  10. Push Down - no elements selected
    1. Invoke Refactor | Push Down for SuperBaseClass class
    2. Keep all checkboxes unchecked
    3. Press Preview
    • EXPECTED RESULT: Dialog with message "No members are selected to be pushed down." is displayed. Action cannot continue.
  11. Push Down undo
    1. Repeat some of the testcase
    2. Use Undo
    • EXPECTED RESULT: All changes are reverted.
  12. Push Down from interface
    1. Invoke Refactor | Push Down for SuperInterface class
    2. Select all element press Preview
    3. Review all changes and click Do Refactoring
    • EXPECTED RESULT: All elements are moved to sub interface.


Test suite: 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

  1. Inner to Outer - basic
    1. Put caret in the body of class Inner1 located in OuterClass
    2. Call Move Inner to Outer Level
    3. In the dialog change Class Name to Rename,Field Name to orig
    4. Click Preview, inspect all changes and confirm by Do Refactoring
    • EXPECTED 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.
  2. Inner 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 Preview, review all changes and confirm by Do Refactoring
    • EXPECTED RESULT: The class is moved into new file as top-level class. Class User has correct reference to moved class. Filed referring to original class is not generated.
  3. Inner 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 Preview, review all changes and confirm by Do Refactoring
    • EXPECTED RESULT: Interface is moved to separate file. Reference in class User is updated
  4. Inner to Outer - enum
    1. Call Move Inner to Outer Level for enum InnerEnum located in OuterClass
    2. In the dialog change Class Name
    3. Click Preview, review all changes and confirm by Do Refactoring
    • EXPECTED RESULT: Enum is moved to separate file. Reference in class User is updated
  5. Inner to Outer - annotations
    1. Call Move Inner to Outer Level for class InnerAnot located in OuterClass
    2. In the dialog change Class Name
    3. Click Preview, review all changes and confirm by Do Refactoring
    • EXPECTED RESULT: Annotation is moved to separate file. Reference in class User is updated.
  6. Inner 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
    • EXPECTED RESULT: Class is moved to a separate file with all necessary imports.
  7. Inner 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 Preview, review all changes and confirm by Do Refactoring
    • EXPECTED RESULT: New separate file with class Inner is created. All constructors are updated to accept reference to outer class as additional parameter.
  8. Inner to Outer - two levels
    1. Call Move Inner to Outer Level for class InnerInnerClass located in Wrapper class
    2. Keep all as default, perform refactoring
    3. Call Move Inner to Outer Level for class InnerInnerClass again
    4. Keep all as default, perform refactoring
    • EXPECTED RESULT: The InnerInnerClass class is step by step propagated to outer level. The reference to previous outer classes are added to constructor.
  9. Inner 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 Refactor
    • EXPECTED RESULT: Action is performed w/o preview.
  10. Inner to Outer - cancel
    1. Call Move Inner to Outer Level for class Inner1 located in OuterClass
    2. Click Preview
    3. In preview click Cancel
    • EXPECTED RESULT: There are no changes in the code.
  11. Inner 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 Preview
    4. In preview click Refresh (button with the green arrow)
    • EXPECTED RESULT: The refactoring dialog is reopened, all values are restored.


Test suite: Anonymous to Inner

Purpose: This refactoring converts selected anonymous class to regular inner class. Comments: This is implemented in Java/hints module.
Setup: Unzip and open project [[../data/ConvertClasses_TS_60_Refactoring3.zip| ConvertClasses]]

  1. Anon to Inner availability
    1. Check presence of Convert Anonymous Class to Inner item in menu Refactor
    2. Select package node and class node and check that menu item is disabled
    3. Open some java file and put carent into it -> the menu item is enabled
    4. Place cursor over identifier of supertype in anonymous class declaration (e.g. over second word Runnable in "Runnable r = new Runnable() { ... }") -> hint Convert anonymous ... is provided
    • EXPECTED RESULT: The menu item is avaiable and it's enable/disable status follow previous description.
  2. Anon to Inner - basic
    1. Open ClassA in editor and call refactoring for its anonymous class.
    2. Type new name
    3. Use editor undo for taking the changes back
    • EXPECTED RESULT: New inner class is created. It's name is derived from original name by appending "Impl", the body of anonymous class is move to the newly introduced class and at original place, there is call of its constructor. The instant-rename for name of new class is on, so when the user is typing the new class is beeing renamed. Enter ends the renaming. Undo reverts all changes.
  3. Anon to Inner - constructor
    1. Open ClassB in editor and call refactoring for its anonymous class.
    • EXPECTED RESULT: The new inner class is created. It's constructor accepts one parameter and delegates is to super class.
  4. Anon to Inner - static
    1. Open ClassD in editor and call refactoring for its anonymous class.
    • EXPECTED RESULT: The new class is declared as static, since it used in static context.


Test suite: 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 [[../data/ConvertClasses_TS_60_Refactoring3.zip| ConvertClasses]]

  1. Use 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
    • EXPECTED 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.
  2. Use 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 Preview, review all changes and confirm by Do Refactoring
    • EXPECTED RESULT: Occurrence is found, check the class User , there should be s6 retyped to Object .
  3. Use Supertype - select type
    1. Call Use Supertype Where Possible for class Sub
    2. Select one item form the list
    3. Click Preview, review all changes and confirm by Do Refactoring
    • EXPECTED RESULT: The identifiers s? should be typed according to the selected type.
  4. Use 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 Refactor
    • EXPECTED RESULT: The action is performed w/o preview
  5. Use Supertype - cancel
    1. Call Use Supertype Where Possible for class Sub
    2. Select one item from the list,
    3. Click Preview.
    4. In the preview click Cancel
    • EXPECTED RESULT: Refactoring is canceled, no changes are made to the code.
  6. Use Supertype - refresh
    1. Call Use Supertype Where Possible for class Sub
    2. Select one item from the list
    3. Click Preview
    4. In preview click Refresh (button with the green arrow)
    • EXPECTED RESULT: Dialog is reopened, previous selection is restored.


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