TS 61 FormRefactoring

Form Refactoring Test Specification

Author: Jiri Vagner
Version: 6.1
Lastupdate: 2008/01/29
Introduction: This document contains supported usual/typical scenarios that can be encountered by user which want to test a form refactoring functionality included in the NetBeans IDE. For each scenario there is a description of the triggering action, the changes done by standard java refactoring, and additional changes performed by the GUI builder.

Contents

Test suite: Rename component variable

  1. Simple rename
    • Setup: Start IDE with clear userdir. Create new project, Java Application (e.g. MyApplication) and create a new form (e.g JFrame)
    1. Add JButton component into form
    2. Go to Inspector window and select JButton node
    3. Invoke popup menu and click "Change Variable Name ..." menu item
    4. Change button name to "myNewButton" and press OK button
    • EXPECTED RESULT: Button variable was renamed from default "jButton1" to "myNewButton". Go to source of form and check the code. Try to find "jButton1" and "myNewButton" strings. Save form and open metadata xml file and find string "myNewButton".
  2. Event handler name method refactoring
    • Setup: Use previous project
    1. Select button in form designer and invoke popup menu
    2. Click "Events -> Action -> actionPerformed" menu item. It will generate event handler method myNewButtonActionPerformed()
    3. Go back to designer and select button in Inspector tree
    4. Press F2 and rename button to "mySecondButton"
    • EXPECTED RESULT: Go back to form code and check the event handler method for button. Method was renamed from "myNewButtonActionPerformed()" to "mySecondButtonActionPerformed()"
  3. Resource key refactoring
    • Setup: Start IDE with clear userdir. Create new project Java Desktop Application (e.g. MyApplication). Go to Options -> Misc. -> GUI Builder settings, enable automatic internationalization and create a new form (e.g JFrame)
    1. Add JButton component into form. Bundle.properties file is generated, check it's content. There is a "jButton1" key.
    2. Go to Inspector, select button node and press F2 to rename button.
    3. Change name from "jButton1" to "myNewButton"
    • EXPECTED RESULT: Check the content of Bundle.properties file. Key for button should be renamed to match new name.


Test suite: Rename the form class

  1. Application Framework project
    • Setup: Start IDE with clear userdir. Create new Java Desktop Application project (Basic shell).
    1. Project will start with opened ...View.java form. Explore the project tree and find corresponding ...View.properties file.
    2. Select ...View.java file in Project tree and press F2 key
    3. Change name from ...View to MyView.java
    • EXPECTED RESULT: Properties file changed name according new class name. Inside form source you can find renamed class reference in initComponents() method.
  2. Using automatic internationalization
    • Setup: Start IDE with clear userdir. Create new project Java Desktop Application (e.g. MyApplication). Go to Options -> Misc. -> GUI Builder settings, enable automatic internationalization and create a new form (e.g JFrame)
    1. Add JButton component into form. Bundle.properties file is generated, check it's content. There is a NewJFrame.jButton1.text key.
    2. Go to Project tree, select form node and press F2 to rename class.
    3. Change form name from "NewJFrame" to "MyFrame"
    • EXPECTED RESULT: Key in Bundle.properties file was changed from "NewJFrame.jButton1.text" to "MyFrame.jButton1.text"


Test suite: Move the form class

  1. Application Framework project
    • Setup: Start IDE with clear userdir. Create new Java Desktop Application project (Basic shell).
    1. Create new package in Source Packages project node
    2. Move class ...View.java into new package using drag and drop in project tree
    • EXPECTED RESULT: Form refactoring will create new subpackage "resources" in new package and will move with class also it's properties file into this subpackage.
  2. Using automatic internationalization
    • Setup: Start IDE with clear userdir. Create new project Java Desktop Application (e.g. MyApplication). Go to Options -> Misc. -> GUI Builder settings and enable automatic internationalization.
    1. Add two JFrame forms into project (e.g. FirstFrame, SecondFrame)
    2. Add JButton component into each form. It will generates Bundle.properties file with two keys for each button.
    3. Create new package in Source Packages project node
    4. Move second form into new package using drag and drop in project tree
    • EXPECTED RESULT: Refactoring will create new properties file in new package and it will copy keys for moved form. Compare content of properties files. Also path to bundle file is updated in form source code in generated code in initComponents() method, search usage of getBundle() method.


Test suite: Rename a package

  1. Rename a package
    • Setup: Start IDE with clear userdir. Create new Java Desktop Application project - Basic shell (e.g. DesktopApp)
    1. Open DesktopAboutBox.java file and go to source code
    2. Find usage of method getInstance() in initComponents() method body. It has parameter "desktopapp.DesktopApp.class"
    3. Now select "dekstopapp" root package in project tree and rename it to "myapp"
    • EXPECTED RESULT: Refactoring changed parameters in generated code. Again find usage of method getInstance() in initComponents() method body. Now it has parameter "myapp.DesktopApp.class" instead of "dekstopapp.DesktopApp.class"
  2. Rename a package of component
    • Setup: Start IDE with clear userdir. Create new Java Desktop Application project (Basic shell).
    1. Create new root package "newpackage"
    2. Add new empty class "MyButton" into this package.
    3. Modify MyButton class, just extends class with JButton and compile file (F9)
    4. Open ...View.java file in designer and drag and drop MyButton class from project tree into form.
    5. Now select package "newpackage" in project tree and rename it "mypackage"
    • EXPECTED RESULT: In ...View.java source code in guarded block, there was changed declaration of custom component from "newpackage.NewButton newButton1" to "mypackage.NewButton newButton1"


Test suite: Rename and move a component class

  1. Rename a component
    • Setup: Download, unpack and open RenameAndMoveComponent project.
    1. Execute menu item "Clean and Build" from popup menu above project root node
    2. Open NewJFrame form and explore it's source code. There you can find usage of MyButton component.
    3. Close form file
    4. Press F2 key with select MyButton.java class in project tree and rename it to "YourButton"
    5. Build project again
    • EXPECTED RESULT: Open NewJFrame again and check the code. There should be a declaration of renamed component YourButton at the end of source code.
  2. Move a component
    • Setup: Use project from previous case
    1. Create new package in main app package
    2. Drag YourButton.java file into new package in project tree
    3. Build the project
    • EXPECTED RESULT: Open NewJFrame and check the code. There should be a declaration of renamed component YourButton in new package at the end of source code.


Test suite: Updating embedded custom code

  1. Renaming a component variable
    • Setup: Start IDE with clear userdir. Create new project, Java Application (e.g. MyApplication) and create a new form (e.g JFrame)
    1. Add new JButton component into form
    2. Select new button in designer and go to Properties window into Code tab
    3. Fill code "jButton1.setText("my text");" into value of After-All-Set Code property
    4. Go to Inspector window and rename "jButton1" to "myButton" via F2 key
    • EXPECTED RESULT: Now open form file source code, there should be refactored
      myButton.setText("my text");
      instead of
      jButton1.setText("my text");
  1. Renaming a class
    • Setup: Use project from previous case
    1. Add following code into Main.java file: "public static JButton getMyButton(){return new JButton();}" and also add "import javax.swing.JButton;"
    2. Go to form and select button
    3. Go to Properties window into Code tab and fill into Custom Creation Code following code: "Main.getMyButton();"
    4. Rename class Main to MyMain class
    • EXPECTED RESULT:Now open form file source code, there should be refactored
      myButton = MyMain.getMyButton();
      instead of
      myButton = Main.getMyButton();
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