TS 60 Refactoring2

Refactoring Test Specification for

Author: Jiri Prox
Version: 6.0
Last update: 18.07.2007
Introduction: This document serves as test-specification for following refactorings: Extract Method, Extract Interface, Extract Super Class and Safely Delete.
Comments: The test project used in all test scenarios in this document: refactoring_TS_60_Refactoring2.zip

Contents


Test suite: Introduce Method

Purpose: This Test suite is focused on common usecase of the Introduce Method refactoring.
Setup: Open project Refactoring , wait until the classpath scan ends.

  1. New method without return statement
    1. Open file packageA.ClassA
    2. Select text between marks //1 and //2 in the method noReturn
    3. Call Refactor -> Introduce method
    4. Fill in method name and press OK
    • EXPECTED RESULT: The new method is created containing the selected code.
  1. New method - cancel
    1. Open file packageA.ClassA
    2. Select text between marks //1 and //2 in the method noReturn
    3. Call Refactor -> Introduce method
    4. Enter any name and press Cancel button
    • EXPECTED RESULT: No changes are performed.
  1. Method with return statement
    1. Open file packageA.ClassA
    2. Select the code form mark //3 to //4
    3. Open quick fix menu (alt-enter) and invoke Introduce method hint
    4. Enter any name and press ok.
    • EXPECTED RESULT: New method without any parameters is created. The original place is modified that the variable c is initialized by method's call.
  1. Method with return statement 2
    1. Open file packageA.ClassA
    2. Select the code form mark //4 to //5
    3. Call Refactor -> Introduce Method
    4. Enter any name and confirm dialog
    • EXPECTED RESULT: The new method with two parameters is created. One of the parameters is final the second is ordinary (not final). The method contains return statement. At the original place there is assignment of method's result to a single variable.
  1. Ending with return/break/continue
    1. Open file packageA.ClassA
    2. Mark code between //7 and //8
    3. Refactor -> Introduce Method
    4. Perform refactoring
    5. Undo changes
    6. Try to change the continue command to break and return respectively.
    • EXPECTED RESULT: In the step 3 a new method is created. The original selection is replaced with method call and the last statement ( continue; ) stays as it is.

 
  1. Illegal refactoring - wrong selection
    1. Open some file
    2. Try to select part of the command, expression or line and call Introduce Method
    3. Try also selecting whole class and call Introduce Method
    4. Try to call Introduce Method on items from Navigator (by selecting them and using main menu Refactor)
    • EXPECTED RESULT: In all these cases the Introduce Method should be disabled or the error message should be popped up.
  1. Illegal refactoring - too many outputs
    1. Open file packageA.ClassA
    2. Select code between //0 and //1
    3. Call Refactor | Introduce Method
    • EXPECTED RESULT: Error message announcing too many return variables is popped up.
  1. Illegal refactoring - selection contains return/break/continue
    1. Open file packageA.ClassA
    2. Mark code between //6 and //7
    3. Refactor -> Introduce Method
    4. Try to change the continue command to break and return respectively and repeat steps 2) and 3).
    5. Comment out the line "s = s+"--, ";" and try again
    • EXPECTED RESULT: The error message "Too many output parameters" is displayed at first. After commenting out the specified line, the refactoring can be performed and semantic of the code is not changed
  1. Illegal refactoring - method already defined
    1. Open file packageA.ClassA
    2. Select the code form mark //4 to //5
    3. Call Refactor -> Introduce Method
    4. Change method name to existing
    5. Confirm dialog
    6. Repeat whole testcase, but change name to existing2 and existing3
    • EXPECTED RESULT: For existing and existing2 an error dialog is shown, announcing that the method with the same signature already exists. Method's name existing3 is OK
  1. Global variables
    1. Open file packageA.ClassA
    2. Select the code form mark //9 to //10
    3. Call Refactor -> Introduce Method
    • EXPECTED RESULT: The new method without any parameter and without return is created.
  1. Modifiers manipulation
    1. Go back to some previous test case
    2. Try changing access modifier
    • EXPECTED RESULT: Method is created with correct modifier
  1. Static modifier
    1. Open file packageA.ClassA
    2. Select the code form mark //11 to //12
    3. Call Introduce Method
    • EXPECTED RESULT: The created method is static

}}

Test suite: Introduce Field

Purpose: This Test suite covers introduce field transformation
Setup: Open project Refactoring , wait until the classpath scan ends. After each refactoring press Undo to get sources to original state

  1. Constant expression
    1. Open file packageE.ClassA
    2. Select text "3+3"
    3. Call Refactor -> Introduce Field
    4. Fill in field name, set access modifier to private, check Replace all occurrences(4) and uncheck Declare Final, initialize in constructor
    5. Press OK
    • EXPECTED RESULT: Radio button Initialize in current method is disabled. When performed all occurrence of expression 3+3 are replaced by field of given name. Constructor is added, it it's body the new filed is initialized by selected expression.
  1. Constant expression, initialize in current method
    1. Open file packageE.ClassA
    2. Select text "3+3" in the first method
    3. Call Refactor -> Introduce Field
    4. Fill in field name, uncheck Replace all occurrences(4) and uncheck Declare Final, initialize in current method
    5. Press OK
    • EXPECTED RESULT: When the dialog is opened, the last values should be preset. When unchecking Declare final the radio button Initialize in current method is enabled. After confirmation the new field of given name is created, it is initialized in current method and selected expression is replaced by this new field
  1. Final field, initialize in field
    1. Open file packageE.ClassA
    2. Select text "Text" in the "method method3()"
    3. Use Alt-Enter to show list of possible hints and select
    4. Fillin field name, initialize in field, check Declare final, change access modifier to package private.
    5. Press OK
    • EXPECTED RESULT: The Replace All Occurrences are disabled (there is only one occurrence), when selecting Initialize in field, the declare final is enabled (if it was initially disabled). After confirmation the final package private field is created and it is used in the original place. Nre field is static
  1. Negative case - wrong selection
    1. Select part of code which in not an expression (part of identifier, line with ending ';', etc...)
    2. Open hint menu (Alt-Enter)
    3. Call Refactor -> Introduce Field
    • EXPECTED RESULT: The list of available hints (if there are any) does not contain Introduce Field. When invoking action from menu the error "Wrong selection" is shown.
  1. Negative case - existing identifier
    1. Open file packageE.ClassA
    2. Select text "Text" in the "method method3()"
    3. Use Alt-Enter to show list of possible hints and select
    4. Fill name of existing field as field name
    5. Press OK
    • EXPECTED RESULT: The warning that field already exist should be shown
  1. Negative case - wrong location
    1. Open file packageE.ClassA
    2. Select text "a" on the line where field "konst" is declared
    3. Use Alt-Enter to show list of possible hints and select
    • EXPECTED RESULT: Introduce field hint should not be provided


Test suite: Introduce Constant

Purpose: This Test suite covers introduce constant transformation
Setup: Open project Refactoring , wait until the classpath scan ends. After each refactoring press Undo to get sources to original state

  1. Introduce constant - replace all occurrences
    1. Open file packageE.ClassB
    2. Select "Text"
    3. Call Introduce Constant from menu
    4. Fill in a new name, check Replace All Occurrence
    5. Press OK
    • EXPECTED RESULT: The Declare final checkbox is always checked and disabled. After confirmation a new constant of given name is introduced and all occurrences of "Text" are replace by the new constant
  1. Introduce constant - change access modifier
    1. Repeat previous test case, but change access modifier
    2. Use list of hints to call Introduce constant
    • EXPECTED RESULT: Introduced constant has desired modifiers
  1. Introduce constant - negative case
    1. Open file packageE.ClassB
    2. Select part of code which cannot be turned into the new constant (whole line, part of identifier, etc...)
    3. Try fill in existing or invalid identifier
    • EXPECTED RESULT: If wrong part of code is selected the Introduce constant hint is not provided, invoking this action from menu open error dialog. Used or invalid identifier is detected and transformation is not performed in such situation
  1. Introduce constant - replace one occurrence
    1. Open file packageE.ClassB
    2. Select constant 3 in the method statMethod()
    3. Fill in a new name and uncheck Replace all occurrence
    4. Press OK
    • EXPECTED RESULT: The new constant is declared as static. Only selected occurrence of constant 3 is replaced by the new constant


Test suite: Introduce Variable

Purpose: This Test suite covers introduce variable refactoring
Setup: Open project Refactoring , wait until the classpath scan ends. After each refactoring press Undo to get sources to original state

  1. Introduce variable - all occurrences
    1. Open file packageE.ClassC
    2. Select "3.3" double literal
    3. Call Introduce Variable from the Refactor menu
    4. Fill in new name, check Replace all occurrences and uncheck Declare final
    5. Press OK
    • EXPECTED RESULT: New local variable is introduced and initialized to selected valued. All occurrences of selected expression are replace by the new variable
  1. Introduce variable - declare final
    1. Open file packageE.ClassC
    2. Select "3.3" and from hint list select introduce variable
    3. Enter new name, check Declare Final and uncheck Replace all occurrences
    • EXPECTED RESULT: Final variable is created. Only selected occurrence is replaced
  1. Introduce variable - negative testcase
    1. Open file packageE.ClassC
    2. Select invalid part of code
    3. Try Introduce variable
    • EXPECTED RESULT: Hint Introduce variable is not provided. Error message is shown when calling action from Refactor menu


Test suite: Extract Interface

Purpose: This suite tests Extract Interface refactoring in several common usecases.
Setup: Open project Refactoring and wait until the classpath scan ends.

  1. Simple case
    1. Open file packageB.ClassA
    2. Go to editor
    3. Call Refactor -> Extract Interface from the main menu
    4. Fill in the interface name
    5. Select some members to be extracted and click on Preview
    6. Do Refactor
    • EXPECTED RESULT: Public static final fields, public methods and implemented interfaces are listed in the Extract Interface dialog. The preview shows all proposed changes. After refactoring is performed the new interface is created and all selected elements are moved/copied to it.
  1. Refresh button
    1. Open file packageB.ClassA
    2. Go to editor
    3. Call Refactor -> Extract Interface from the main menu
    4. Fill in the interface name
    5. Select some members to be extracted and click on Preview
    6. Press Cancel
    • EXPECTED RESULT: After clicking on Refresh the refactoring dialog is reopened in the state as it was left. Cancel button cancels refactoring w/o preforming any changes
  1. Extract from interface and enum
    1. Open file packageB.InterfaceA
    2. Call Extract Interface on it
    3. Enter new interface name and preform refactoring
    4. Undo changes
    5. Open file packageB.Enumeration
    6. Call Extract Interface on it
    7. Enter new interface name and preform refactoring
    • EXPECTED RESULT:
    • Both refactorings are OK,
    • in the Extract Interface dialogs, there were displayed proper members,
    • new interfaces are created.
  1. Extract from generic class
    1. Open file packageB.ClassB
    2. Call Extract Interface on it
    3. Select provided element
    4. Press preview
    5. Inspect proposed changes
    6. Confirm refactoring
    • EXPECTED RESULT: The new generic interface is created and implements statement is correctly added to the original class.
  1. Extract from class implementing interface
    1. Open file packageB.ClassC
    2. Call Extract Interface on it
    3. Enter new interface name, select "implements Runnable" and at least one more member
    4. Press Preview
    5. Perform refactoring
    • EXPECTED RESULT: In the preview there are correctly listed all changes. After finishing refactoring the new interface implementing runnable and containing selected methods is created. The original class now implements new interface.
  1. Extract from file with more toplevel elements
    1. Open file packageB.ClassD
    2. Put cursor in editor to class ClassD
    3. Perform Extract Interface
    4. Repeat steps 2 and 3 for each toplevel element and for the inner class
    5. Try refactoring when caret is in the space between elements (lines: 10, 12, 33, 39, 43)
    • EXPECTED RESULT: Every refactoring is performed with the proper element. When invoked from space between elements the refactoring is performed with ClassD class.
  1. Invalid refactorig
    1. Go back to any previous case and invoke Extract Interface dialog
    2. Try fill in invalid or already existing name
    3. Try also fill in the name of the original class
    • EXPECTED RESULT: In all case the error messages with clear and correct meaning should by shown.


Test suite: Extract Super Class

Purpose: This test suit concerns Extract Super Class refactorings.
Setup: Open project Refactoring , wait until the classpath scan ends.

  1. Basic case
    1. Open packageC.ClassA
    2. Call Refactor -> Extract Super Class
    3. Select some items from 'Members to Extract' table and press Preview
    4. Inspect the contents of the preview window
    5. Click to refresh button
    6. Select different items from 'Members to Extract' table and confirm by clicking on Preview button
    7. Inspect new contents of preview window and cancel refactoring
    8. Call again Refactor -> Extract Super Class
    9. Select some items from Members to extract table and confirm dialog
    10. Confirm refactoring
    • EXPECTED RESULT: In refactoring dialog there are listed all elements form class ClassA which can be extracted to super class. The preview window always contains planned changes reflecting the values entered in the dialog. After canceling operation no changes are made to the code. After last step the refactoring is performed, new class is created and the original class is modified.
  1. Making methods abstract
    1. Open packageC.ClassB
    2. Call Refactor -> Extract Super Class
    3. In the 'Members to Extract' table select the method method() to be extracted and check Make abstract.
    4. Confirm dialog
    5. Confirm whole refactoring if preview window is opened
    • EXPECTED RESULT: The new abstract super class is created with abstract method method . In the original class, the name of the new super class is added to extends statement and the code of the extracted method is not changed.
  1. Extracting from file with more top level elements
    1. Open packageC.ClassC
    2. Try to invoke refactoring from different places of the source code
    3. Try to call refactoring from different positions from the project view .
    4. Perform Extract Super Class for class TopLevelElement
    • EXPECTED RESULT: Every time the dialog is opened it has right context. If it is called from the editor when cursor is outside of any element (e.g. lines 10. 30, 35) or from the node corresponding to java file the context is set to ClassC .
  1. Extracting from interface, enum and annotation
    1. Open class packageC.classD
    2. Try to call Extract super class for Interface, Annotation and Enum element.
    • EXPECTED RESULT: In all 3 cases a message saying the refactoring can not be performed is popped up.
  1. Refactoring 1.5 features
    1. Open file packageC.classE
    2. Invoke Refactor -> Extract Super Class
    3. Select method method() to be extracted
    4. Perform refactoring
    • EXPECTED RESULT: The refactoring is performed correctly. New generic super class is created, its name (without generic type) is added to extends statement. The both classes can be compiled.
  1. Refactorning class with import
    1. Open packageC.ClassF
    2. Call Refactor -> Extract Super Class
    3. Select method method() to be extracted
    4. Confirm refactoring
    • EXPECTED RESULT: New super class is created and it is containing method method() . All imports statements are updated correctly in both files.
  1. Invalid refactoring
    1. Call Extract Super Class on some class as in previous test cases.
    2. Try to fill in invalid class name (e.g. '1NewClass' or some keyword)
    3. Try to fill in existing class name
    • EXPECTED RESULT: In all cases the user should be informed that the refactoring is impossible. The error message should clearly described why the refactoring is unsuitable.


Test suite: Safely Delete

Purpose: This suite tests common usage of Safe Delete refactoring.
Setup: Open project Refactoring , wait until the classpath scan ends.

  1. Basic Safe Delete
    1. Open packageD.ClassA
    2. Select variable i at the line 19
    3. Call Refactor -> Safely Delete
    4. In the Safe Delete dialog press Preview
    5. Click on Show Usages
    6. In Find Usages result window press Refresh button
    • EXPECTED RESULT: The 'Safe delete' dialog is opened. It is clear, which element is going to be deleted. After confirming a new dialog is opened informing that usages had been found. In the 'Show usages' window, there are listed both usages. Refresh button will bring back original Safe delete dialog
  1. Basic Safe Delete II
    1. In opened file ClassA remove line 22 ( i = 1)
    2. Call Refactor -> Safely Delete on element i
    3. Check Search in Comments and confirm dialog
    4. Click on Show Usages
    5. Click on Return Safe Delete
    6. Uncheck Search in Comments and press Preview
    7. Confirm action
    • EXPECTED RESULT: At a first try a dialog informing about found usages is opened. After clicking on Show usages, one usage (in comment) is shown. The second try of safe delete is OK, in the preview there are listed all changes to be done. After refactoring the declaration of i is deleted.
  1. Deleting used elements
    1. Open packageD.ClassB
    2. Step by step keep placing cursor on every word in the source code and try Safely delete (for fully qualified names, put cursor on every part separated by '.')
    3. Go to project view and call Refactor -> Safe Delete from the context menu on the ClassB.java node.
    • EXPECTED RESULT: Every time the refactoring dialog is opened it contains information about the element which is going to be deleted or a error message the safe delete isn't supported for the appropriate node. When continuing in the refactoring the usages are found.
  1. Deleting unused elements
    1. Delete class User.java
    2. Repeat last test case
    • EXPECTED RESULT: Now, no usages are found during refactoring and all possible elements are deleted.
  1. Deleting locally referenced items
    1. Open packageD.ClassC
    2. Try to safely delete field field , method method() and inner class Inner
    3. Delete method user()
    4. Repeat step 2.
    • EXPECTED RESULT: In step 2 any of the elements cannot be deleted, because they are used in method user() . When this method is deleted these elements can be safely deleted.
  1. Deleting from project view
    1. Select packageD.User in the project
    2. Press delete
    3. Check safe delete checkbox
    4. Confirm
    • EXPECTED RESULT: The safe delete action is performed



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