TS 71 FormRefactoring

Form Refactoring Test Specification

Author: Adam Senk
Version: 7.1
Lastupdate: 2011/11/10
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 Navigator 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 Navigator 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 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 Navigator, 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. Using automatic internationalization
    • Setup: Start IDE with clear userdir. Create new project Java 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: Cut/Copy and Paste the form class

  1. Cut
    • Setup: Start IDE with clear userdir. Create 2 new projects Java Application (e.g. MyApplication1 and MyApplication2). In MyApplication1 create new JFrame Form.
    1. Add some Swing components into form.
    2. Change some properties of inserted Swing components.
    3. Cut the form file and paste it into MyApplication2
    4. Refactor
    • EXPECTED RESULT:Assure refactored file. Properties of Swing components aren't changed, source code is refactored correctly.


  1. Copy
    • Setup: Start IDE with clear userdir. Create 2 new projects Java Application (e.g. MyApplication1 and MyApplication2). In MyApplication1 create new JFrame Form.
    1. Add some Swing components into form.
    2. Change some properties of inserted Swing components.
    3. Copy the form file and paste it into MyApplication2
    4. Refactor
    • EXPECTED RESULT:Assure refactored file. Properties of Swing components aren't changed, source code is refactored correctly.


Test suite: Move the form class

  1. Using automatic internationalization
    • Setup: Start IDE with clear userdir. Create new project Java 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 of component
    • Setup: Start IDE with clear userdir. Create new Java 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: 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 Navigator 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");
  2. 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