cornercorner
FeaturesPluginsDocs & SupportCommunityPartners

Refactoring Test Specification

Author: Jiri Prox
Version: 1.1.30
Last update: 24.08.2005
Introduction: This document serves as test-specification for following refactorings: Extract Method, Extract Interface, Extract Super Class and Safely Delete.
Comment:

Table of Contents

Test suite 1: General

Purpose: This suite tests general features common to all types of refactoring.
Setup:

  • Download project Refactoring
  • Unzip it
  • Start IDE with the fresh userdir
  • Open project Refactoring
  • Wait till the end of background classpath scanning

#Test caseDescription
1Menu items
  1. Open main menu Refactor
  2. Check if Extract Method item is present
  3. Check if Extract Interface item is present
  4. Check if Extract Super Class item is present
  5. Check if Safely Delete item is present
RESULT:All 4 checked items are present
2Context Menu
  1. Select Refactoring -> Source Packages in the explorer
  2. Check the presence of Refactor in the popup menu
  3. Select Refactoring -> Source Packages -> PackageA -> ClassA in the explorer
  4. Check the presence of Refactor | Extract Method in the popup menu
  5. Check the presence of Refactor | Extract Interface in the popup menu
  6. Check the presence of Refactor | Extract Super Class in the popup menu
  7. Check the presence of Refactor | Safe Delete in the popup menu
RESULT:For the Refactoring -> PackageA there is no refactoring in popup menu. The context menu for ClassA node contains all mentioned items and all of them are enabled.
3Refactorings Dialogs
  1. Select packageA -> ClassA node in the project explorer
  2. Click on each item from Refactor main menu
  3. Click on each item from the Refactor popup menu
RESULT:When a menu item is clicked a new dialog is opened. It contains further details of the desired refactoring or some kind of error message.
4ClassPath Scanning
  1. Exit IDE
  2. Start IDE with the clear userdir
  3. Open project Refactoring
  4. Select packageA.ClassA in the explorer
  5. Check if the all refactorings menu items are disabled when classpath scan is running
RESULT:The items are disabled (both in main menu and context menu). They are turned to enabled just when the scans ends.
In the suite there are several times mentioned all items in refactoring menu. It means only that ones this testspec is concerned at.

Test suite 2: Extract Method

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

#Test caseDescription
1New method without return statement
  1. Open file packageA.ClassA
  2. Select text between marks //1 and //2 in the method noReturn
  3. Call Refactor -> Extract method
  4. Check Preview all changes checkbox
  5. Confirm dialog by clicking on Next without any further changes.
  6. Inspect the provided changes
  7. Press Cancel button
  8. Repeat steps 2) - 6) and in the preview window press Do Refactoring
Teardown: Undo the refactoring
RESULT:After step 2: The dialog is popped up. The method's name and access modifier are set. In the Parameters table there are listed all variables that are used in the selected part of the code. After step 5: New window displaying changes to be made is opened. It's containing all changes which should be performed. After step 7: The preview window is closed, no changes are done. After step 8: The new method is created. Its body is formed by the previously selected code. The original selection is replaced by the method call. The class can be compiled.
2Method with return statement
  1. Open file packageA.ClassA
  2. Select the code form mark //3 to //4
  3. Call Refactor -> Extract Method
  4. Confirm dialog
  5. Inspect proposed changes
  6. Confirm changes
Teardown: Undo all changes
RESULT:New method without any parameters is created. The original place is modified that the variable c is initialized by method's call.
3Method with return statement 2
  1. Open file packageA.ClassA
  2. Select the code form mark //4 to //5
  3. Call Refactor -> Extract Method
  4. Confirm dialog
  5. Inspect proposed changes
  6. Confirm changes
Teardown: Undo all changes
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.
4Ending with return/break/continue
  1. Open file packageA.ClassA
  2. Mark code between //7 and //8
  3. Refactor -> Extract Method
  4. Confirm all changes and perform refactoring
  5. Undo changes
  6. Try to change the continue command to break and return respectively.
Teardown: Undo all changes
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.
5Illegal refactoring - wrong selection
  1. Open some file
  2. Try to select part of the command, expression or line and call Extract Method
  3. Try also selecting whole class and call Extract Method
  4. Try to select some unsuitable nodes from the project explorer (project root, package node, constructor node etc..) and invoke Extract Method on it
  5. Try to call Extract Method on items from Navigator (by selecting them and using main menu Refactor
RESULT:In all these cases the Extract Method should be disabled or the error message should be popped up.
6Illegal refactoring - too many outputs
  1. Open file packageA.ClassA
  2. Select code between //0 and //1
  3. Call Refactor | Extract Method
Teardown: Undo all changes
RESULT:Error message announcing too many return variables is popped up.
7Illegal refactoring - selection contains return/break/continue
  1. Open file packageA.ClassA
  2. Mark code between //6 and //7
  3. Refactor -> Extract Method
  4. Try to change the continue command to break and return respectively and repeat steps 2) and 3).
Teardown: Undo all changes if any was done.
RESULT:The error message is popped up after steps 3 and 4 informing about wrong position of continue, break and return respectively in the selected code.
8Illegal refactoring - method already defined
  1. Open file packageA.ClassA
  2. Select the code form mark //4 to //5
  3. Call Refactor -> Extract Method
  4. Change method name to existing
  5. Confirm dialog
  6. Press Back
  7. Change method's name to existing2 and existing3 respectively and go to step 5
Teardown: Undo refactoring
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
9Global variables
  1. Open file packageA.ClassA
  2. Select the code form mark //9 to //10
  3. Call Refactor -> Extract Method
Teardown: Undo changes
RESULT:The new method without any parameter and without return is created.
10Modifiers manipulation
  1. Go back to some previous test case
  2. Check Declare Static
  3. Try changing method's name
  4. Try also invalid method's name
Teardown: Undo changes
RESULT:Check if the method signature preview is updated correctly. Check if the new method is generated properly.
11Static modifier
  1. Open file packageA.ClassA
  2. Select the code form mark //11 to //12
  3. Call Extract Method
RESULT: Declare Static
12Parameters manipulation
  1. Go back to some previous test case
  2. In the refactoring dialog try to change the order of parameters, their types and names
Teardown: Undo all changes
RESULT:The method signature is updated according the changes in parameters table. It's not possible to change parameters types and names.
In this suite, there is used special marks in the code to specify the selection. They are formed by number behind comments. For example to select text between marks //1 and //2 means to find out these comments in the text (each is on the separate line) and select all the code between these lines.

Teardown: Exit IDE and start it with the fresh userdir in order to prevent this test suite to affect the next one.

Test suite 3: Extract Interface

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

#Test caseDescription
1Refactoring availability
Setup:Every time a refactoring dialog is opened, inspect its contents and close it again without doing refactoring.
  1. Open file packageB.ClassA
  2. Select the root of the project in explorer
  3. Check if menu item Extract Interface is enabled in main menu Refactor . Click on it.
  4. Check if the Extract Interface is present and enabled in the context menu. Click on it.
  5. Go one level lower in the hierarchical tree of project until the atomic nodes are reached and repeat steps 3 and 4.
  6. Click in the editor (where should by opened file packageB.ClassA) and repeat steps 4. and 5. one more time.
RESULT:The menu item are enabled/present only for suitable nodes (from the node corresponding to java file and lower). Every time an item is chosen the dialog is opened with the proper context (for the sub-nodes of java file node is the context the same as for java file node).
2Simple 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 in opened dialog and check Preview All Changes
  5. Click on Next
  6. Examine the proposed changes in preview window
  7. Click refresh button (that one with the green arrow)
  8. Select some members to be extracted and click on Next
  9. Inspect proposed changes and stop refactoring by clicking on Cancel
  10. Invoke again refactoring dialog, enter interface name and select some members to extract
  11. Confirm by clicking Next and Do Refactor
RESULT:After step 3. the refactor dialog is opened and all public methods and public static final members are listed in Members to Extract table In step 6. all proposed changes are correct and they are labeled properly After 7. the refactor dialog is reopened again, all is in the state as it was left. After step 9. no changes are made After step 11. new interface is created, its structure and name respects filled-in values
3Extract from interface and enumeration
  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
Teardown: Undo changes
RESULT:
  • Both refactorings are OK,
  • in the Extract Interface dialogs, there were displayed proper members,
  • new interfaces are created.
4Extract from generic class
  1. Open file packageB.ClassB
  2. Call Extract Interface on it
  3. Check Preview All Changes
  4. Confirm dialog
  5. Inspect proposed changes
  6. Confirm refactoring
Teardown: Undo changes
RESULT:In the refactoring dialog, there are correctly listed public members. In the preview window there are properly displayed all necessary changes. The new generic interface is created and implements statement is correctly added to the original class.
5Extract 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. Check Preview All Changes and confirm dialog
  5. Examine proposed changes
  6. Perform refactoring
Teardown: Undo all changes
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.
6Extract 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)
  6. Try Extract Interface on ClassD node in explorer and sub-nodes.
RESULT:Every refactoring is performed with the proper element. When invoked from space between elements or from the node corresponding to the ClassD.java file the refactoring is done with ClassD class.
7Invalid 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
Teardown: Undo changes, if there was any
RESULT:In all case the error messages with clear and correct meaning should by shown.
Teardown: Exit IDE and start it with the fresh userdir in order to prevent this test suite to affect the next one.

Test suite 4: Extract Super Class

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

#Test caseDescription
1Refactoring availability
Setup:Every time a refactoring dialog is opened, inspect its contents and close it again without doing refactoring.
  1. Open file packageC.ClassA
  2. Select the root of the project in explorer
  3. Check if menu item Extract Interface is enabled in main menu Refactor . Click on it.
  4. Check if the Extract Interface is present and enabled in the context menu. Click on it.
  5. Go one level lower in the hierarchical tree of project until the atomic nodes are reached and repeat steps 3 and 4
  6. Click in the editor (where should by opened file packageC.ClassA and repeat steps 4. and 5. one more time.
RESULT:The menu item are enabled/present only for suitable nodes (from the node corresponding to java file and lower). Every time an item is chosen the dialog is opened with the proper context (for the sub-nodes of java file node is the context the same as for java file node).
2Basic case
  1. Open packageC.ClassA
  2. Call Refactor -> Extract Super Class
  3. Check Preview All Changes, select some items from 'Members to Extract' table and confirm the dialog
  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 Next 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
Teardown: Undo all changes
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.
3Making 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
Teardown: Undo all changes
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.
4Extracting 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
Teardown: Undo all changes
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. After step 4. the code is refactored correctly.
5Extracting from interface, enum and annotation
  1. Open class packageC.classD
  2. Try to call Extract super class for Interface, Annotation and Enum element.
RESULT:In all 3 cases a message saying the refactoring can not be performed is popped up.
6Refactoring 1.5 features
  1. Open file packageD.classE
  2. Invoke Refactor -> Extract Super Class
  3. Select method method() to be extracted
  4. Perform refactoring
Teardown: Undo changes
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.
7Refactorning class with import
  1. Open packageC.ClassF
  2. Call Refactor -> Extract Super Class
  3. Select method method() to be extracted
  4. Confirm refactoring
Teardown: Undo all changes
RESULT:New super class is created and it is containing method method(). All imports statements are updated correctly in both files.
8Invalid 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
Teardown: Undo changes
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.
Teardown: Exit IDE and start it with the fresh userdir in order to prevent this test suite to affect the next one.

Test suite 5: Safely Delete

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

#Test caseDescription
1Basic 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 check Search in Comments and Preview All Changes
  5. Confirm by clicking Next
  6. Click on Show Usages
Teardown: Do NOT undo changes and continue to next test case
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.
2Basic 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, check Preview All Changes and confirm dialog
  7. Inspect the contents of preview window
  8. Confirm action
Teardown: Undo all changes
RESULT:After step 3 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.
3Deleting 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 every sub-node of the ClassB.java node.
Teardown: Undo any changes
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.
4Deleting unused elements
Setup:Every time 'Safely delete' is performed undo all changes to get to original state.
  1. Delete class User.java
  2. Repeat last test case
RESULT:Now, no usages are found during refactoring and all possible elements are deleted.
5Deleting 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.
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.

Generated: 2005 08 24 10:21
Companion
Projects:
MySQL Database Server   GlassFish Community: an Open Source Application Server   Open Solaris  Open JDK: an Open SourceJDK   Mobile & Embedded Community     Sponsored by 
Sponsored by Sun Microsystems