TS 71 Formatting

Code Formatting Test Specification

Author: Jiri Prox
Version:7.1
Last update:2011/09/14
Introduction: This is test specification for code formatting feature in NetBeans 7.1. It covers indentation in editor, reformat action, global formatting settings and project specific formatting settings. The formatting can be customized in several levels. The first level is general formatting respected by all languages. For small set languages there is language specific formatting reflexing the language sturcture of particular language. This settings overrides the default one. This two level hierarchy can customized also on project level. The project can have it's own formatting settings which has higher priority the the global settings. The customization is made in project properties dialog.

Contents

Test suite: General indentation setting

  1. Number of spaces per indent, right margin
    1. Open options dialog on proper tab.
    2. Select Language: All Languages, Category: Tabs And Indents
    3. Change 'Number Of Space per Indent' and 'Right Margin'
    4. Open all files Indentaiton.{java|html|xml} and reformat them
    • EXPECTED RESULT: The indentation is corrected to specified value, right margin is painted at correct position
  2. Expand tab to spaces, Tab size
    1. Open options dialog on proper tab.
    2. Select Language: All Languages, Category: Tabs And Indents
    3. Change 'Tab Size' and uncheck 'Expand tabs to spaces'
    4. Open all files indentaiton.{java|html|xml} and reformat them
    • EXPECTED RESULT: If there is N spaces in a row (where N is tab size) when invoking reformat, they are replace by one tab character. Tab key does not insert one tab char but tyies to add as many tab as it can, a the rest of space to the value of indentation level is filled with spaces. The spaces are never replaced by tab char when typing them manually.
  3. Tabs size, indentation level
    1. Open options dialog on proper tab.
    2. Select Language: All Languages, Category: Tabs And Indents
    3. Change 'Tab Size' and 'Number of Spaces per Indenr' to various values, keep 'Expand tabs to spaces' unchecked
    4. Open all files indentaiton.{java|html|xml} and reformat them after each change
    • EXPECTED RESULT: The spaces and tabs are inserted acording to notes in previous testcase result. Every time as many spaces as is possible is replaced by tabs,othervise the spaces are kept in code to get to appropriate indentation level.

Test suite: Tabs and indents

Purpose: This suite is focused on Java language formatting settings
Setup: Set default formatting setting before performing this suite

  1. Continuation indentation
    1. Open options dialog on proper tab.
    2. Select Language: Java, Category: Tabs And Indents
    3. Change 'Continuation Indentation Size'
    4. Open any java file and type (in scope where it makes sence:
      1. int i = <enter>
      2. public void <enter>
      3. public void metgod(int a, <enter>
      4. class <enter>
      5. int a = 3 <enter>
    • EXPECTED RESULT: The caret is moved to next line. The position of cursot is indentation level + continuation indentation
  2. Label indentation
    1. Open options dialog on proper tab.
    2. Select Language: Java, Category: Tabs And Indents
    3. Change 'Label indentation' and 'Absolute label indentation'
    4. Try another combination of values
    5. Open file Label.java and reformat it
    • EXPECTED RESULT: If 'Absolute indentation' is checked, the label is moved to the 1st colum, othervise it respect indentation level. The 'Label indentaiton' controls additional indentation of the block the label belong to. E.g. the code in block is at position: 'indentation level'*'indentation size'+'label indentation'. If the label indentation is bigger the lable name + 1 for ':' char the blocks is moved to begin at the same line as lable, otherview the block is moved to begin in new line. (Try remaning label to test this)
  3. Indent Top Level Class Members, Indent Case Statements
    1. Open options dialog on proper tab, Language: Java, Category: Tabs And Indents
    2. Uncheck 'Indent Top Level Class Members'
    3. Reformat class Indentation.java
    4. Open options dialog on proper tab, Language: Java, Category: Tabs And Indents
    5. Uncheck 'Indent Case Statement In Switch'
    6. Reformat class Indentation.java
    • EXPECTED RESULT: Whne first checkbox is unselected all class members (methods, fields, inner classes, initializers) are indented to begin at 1st column. (also in inner classes). When second checkbox is unselected the 'case' statements is indented to begin as the same position as related 'switch' statement
  4. Overriding default indentation settings
    1. Open options dialog on proper tab, Language: Java, Category: Tabs And Indents
    2. Check 'Override Global Options' and set new values for items which are enabled.
    3. Open Indentation.java and reformat it
    4. Open OD and uncheck 'Override Global Options' again
    • EXPECTED RESULT: The reformat in java respects entered values. Formatting in others files is unchanged. Once the global settings are not overrided the formatting settings is same in all files.

Test suite: Alignment

  1. New lines
    1. Open options dialog on proper tab, Language: Java, Category: Alignment
    2. Check all checkboxes in section New Lines
    3. Open Alignment.java and reformat it
    4. Open OD and uncheck all checboxes again
    • EXPECTED RESULT: New lines are inserted before 'void' in method declaration, else, while, catch and finally. Whne the checkbox are unchecked the newlines are removed again
  2. Multiline Alignment 1
    1. Open options dialog on proper tab, Language: Java, Category: Alignment
    2. Check all checkboxes in 1st column in section Multiline Alignment
    3. Open Alignment2.java and reformat it
    4. Open OD and uncheck all checboxes again
    • EXPECTED RESULT: The parameters in method declaration, arguments in annotations, exceptions behing throws, operands of binary operator , parts of assign statemen are indented that the identifiers stars at the same column. When the checkboxes are unchecked the value of continuation indentation is important again.
  3. Multiline Alignment 2
    1. Open options dialog on proper tab, Language: Java, Category: Alignment
    2. Check all checkboxes in 2st column in section Multiline Alignment
    3. Open Alignment3.java and reformat it
    4. Open OD and uncheck all checboxes again
    • EXPECTED RESULT: The arguments in method call, interfaces behing 'implements', array elements, parts of ternary operator, parts of for statements are indented that the identifiers stars at the same column. When the checkboxes are unchecked the value of continuation indentation is important again.

Test suite: Braces

  1. Position - Class
    1. Open options dialog on proper tab, Language: Java, Category: Braces
    2. In combobox 'Class Declaration' select values
      1. Same line
      2. New line
      3. New line half indented
      4. New line indented
    3. Open BracesPosition.java and reformat it
    • EXPECTED RESULT: The checkbox controls only position of class bracess, and the formatting is following 1) opening braces is behind class name, closing is at 1st column, 2) opening brace is at first column at a new line, closing is at 1st column, 3) opening and closing braces are as separated lines, indented by half value of intentation size, 4) opening and closing braces are indented by indentation size
  2. Position - Method
    1. Open options dialog on proper tab, Language: Java, Category: Braces
    2. In combobox 'Method declartion' select values
      1. Same line
      2. New line
      3. New line half indented
      4. New line indented
    3. Open BracesPosition.java and reformat it
    • EXPECTED RESULT: The checkbox controls only position of braces in method declarations, the position is described above
  3. Position - Other
    1. Open options dialog on proper tab, Language: Java, Category: Braces
    2. In combobox 'Other' select values
      1. Same line
      2. New line
      3. New line half indented
      4. New line indented
    3. Open BracesPosition.java and reformat it
    • EXPECTED RESULT: The checkbox controls only position of other types of braces - ifs, initializers, array initializers, block, synchronized blocks, lools, switch, the position where are braces moved is described above
  4. else if
    1. Open options dialog on proper tab, Language: Java, Category: Braces
    2. Uncheck 'Special else if Threatment
    3. Open BracesPosition.java and reformat it
    4. Restore the setting and reformat again
    • EXPECTED RESULT: If check box is selected the else if is not separated into two lines but the code is kept togeather in one line
  5. Brace generation
    1. Open options dialog on proper tab, Language: Java, Category: Braces
    2. In section Braces Generation set folowing values in all comboboxex -
      1. Leave alone
      2. Gnerate
      3. Eliminate
    3. Open BracesGeneration.java and reformat it after each kind of value is set.
    • EXPECTED RESULT: When 'leave alone' is set, there is not added or removed any braces. When 'generate' is set the bodies of if, while, do while, for is wrapped into a block. See method generate(). If 'eliminate' is set, the body of loops and for are unwrapped from a block if it is possible, e.g. the body contains only one statement. See method 'eliminate()' and 'cannotEliminate'

Test suite: Wrapping

Comments: This suite tests the line wrapping, wrapping of each element can by set to 3 level: Never - the code construction is never wrapped, If long - the code is wrapped only if it exceeds right margin, Always - the code is always separated into new lines. To test this follow theses steps 1) open requested file, set mentioned rule to Always and reformat code, 2) undo changes, set right margin to 40 and set wrapping value to If Long, reformat code, 3) undo changes, set wrapping value to Never and reformat 4) set right margin back to 80

  1. Wrapping
    1. Open options dialog on proper tab, Language: Java, Category: Wrapping
    2. Open Wraping1.java
    3. Perform steps described in Comments with first half of the rules one by one - from Extend/Implements to ArrayInitializer
    4. Open options dialog on proper tab, Language: Java, Category: Wrapping
    5. Open Wraping2.java
    6. Perform steps described in Comments with the second half of the rules one by one - from For to Assignment Operator
    • {{{1}}}
      }}

Test suite: Blank lines

Comments: The testsuite focuses on controling number of blank lines between elements in java code. The number of empty spaces between element A and B is the bigger number from blank lines behind A and blank lines before B. The javadoc and inline comments counts as part of releated element. The blank lines inside methods body must stay untouched.

  1. Blank lines
    1. Open options dialog on proper tab, Language: Java, Category: Blank lines
    2. Try change each value one by one
    3. After entering new value, open EmptyLines.java and reformat it
    • EXPECTED RESULT: The number of blank lines respect entered values. How is computed exact number of empty lines is descibed in the comments
  2. Blank lines - comments
    1. Open EmptyLines.java and add comments - javadoc, block and inline
    2. Open options dialog on proper tab, Language: Java, Category: Blank lines
    3. Try change each value one by one
    4. After entering new value, open EmptyLines.java and reformat it
    • EXPECTED RESULT: The number of blank lines respect entered values. The comment is handeled as a part of element

Test suite: Spaces

  1. Spaces
    1. Open ClassA.java
    2. Open options dialog on proper tab, Language: Java, Category: Spaces
    3. Try change each value one by one
    4. After entering new value, open ClassA.java and reformat it
    • EXPECTED RESULT: The spaces are insrted to proper positons

Test suite: Comments

  1. Enable Comments Formatting
    1. Open Comment Formatting setting
    2. Uncheck Enable Comments Formatting
    3. Open comments.Comments class
    4. Reformat Code
    • EXPECTED RESULT: Javadoc is not reformated
  2. Add Leading star
    1. Enable JavaDoc formatting if is turned off from previous testcase
    2. Uncheck all comboboxes (exept the first one - Enable javadoc formatting)
    3. Reformat code
    4. Turn on 'Add Leading Star' and reformat code again
    • EXPECTED RESULT: After the first reformat, all leading stars are removed. After second reformat they are added again
  3. Wrap Text
    1. In formatting settings check 'Wrap text at right margin'
    2. Reformat code
    3. Try chaning position of the right margin and reformat again
    • EXPECTED RESULT: Long lines of javadoc are wrapped.
  4. Wrap one line comments
    1. In formatting settings check 'Wrap Oneline Comments'
    2. Reformat code
    • EXPECTED RESULT: One line comments, e.g. /** some comment*/ are expanded to 3 lines
  5. Preserve New Lines
    1. In formatting settings check 'Preserve blank lines' and 'Wrap text at right margin'
    2. Reformat code
    • EXPECTED RESULT: All new lines are preserved. E.g. when long line is splited into several lines the next line is not pasted just after the end of splitted line but it starts at new line.
  6. Blanks Lines
    1. Check 'Add Blank Line After Description', 'Add Blank Line After Parameter Description' and 'Add Blank Line After Return Tag'
    2. Reformat code
    • EXPECTED RESULT: Each part of javadoc is separated by blank line.
  7. Generate paragraph tag
    1. In formatting setting check 'Generate <p/> On Blanks Lines'
    2. Reformat code
    • EXPECTED RESULT: At each empty line in javadac there is generated <p/> tag
  8. Align
    1. Open comments.Comments class
    2. Reformat javadoc that long lines are separated into several lines
    3. In formatting setting check all three checkboxes starting with 'Allign ... '
    4. Reformat code
    • EXPECTED RESULT: The second and next line of parameter description, return tag description and exception description starts at the same column as the fisrt line

Test suite: Organize Imports

Comments: This suite describe how to use formatting of imports statement.

  1. Use Single Class Imports
    1. In imports formatting setting select 'Use Single Class Import'
    2. Open class imports.Imports
    3. Add some class from another package (for example LinkedList) using code completion
    • EXPECTED RESULT: Correct import of single class is added
  2. Import Inner Classes
    1. In import formatting setting check 'Import Inner Classes'
    2. In class imports.Imports type 'Inner" and from code completino select imports.anotherpackage.AuxClass.Inner class
    3. Delete inserted code (including import)
    4. Turn off 'Import Inner Classes'
    5. Use code completion to insert class 'Inner' again
    • EXPECTED RESULT: In first case the identifier 'AuxClass.Inner" is pasted at the cursor position and 'import imports.anotherpackage.AuxClass;' is added. In the second case 'Inner' is inserted at the cursor position and 'import imports.anotherpackage.AuxClass.Inner;' is added.
  3. Class Count To Use Star Import
    1. In setting set 'Class Count To Use Star Import' to 3
    2. In imports.Count class use import hint to resolve import, one by one
    3. Delete all inserted import and use Fix Imports (ctrl-shift-I)
    4. Delete all imports and all classes from java.util and insert them againg using code completion
    • EXPECTED RESULT: All import are resolvet correctly, when inserting 3rd import from the same package the single class imports are replaced by star import
  4. Class Count To Use Star Import - Organize Imports
    1. Open import.Count class
    2. Arrange imports so they do not obey formatting setting - e.g. add more single class imports from java.util
    • EXPECTED RESULT: Organize hint should be provided. After applying it the imports statements are re-arranged according to the setting
  5. Members Count To Use Static Star Import
    1. In settings set Members Count To Use Static Star Import to 3
    2. Open class imports.Count
    3. Use Organize Impoets Hint
    • EXPECTED RESULT: Static imports are replaced by one static star import
  6. Packages To Use Star Import
    1. In setting add one row to table "Packages To Use Star Import", containing package 'java.io' (ckeck box should by checked)
    2. In imports.Imports use code completion to add line File f;
    3. Delete inserted code, go back to formatting setting and uncheck the 'star' column in the table and repeat previous step
    • EXPECTED RESULT: When the start checkbox is checked, the star import is used, even when there is single import from the given package
  7. Use Package Imports
    1. In import formatting setting set 'Use Package Imports'
    2. Use code completion to insert some class
    3. Try fix imports, import hint
    4. Open class where simple class imports are use and use Optimize Imports hint
    • EXPECTED RESULT: Always star import is generated
  8. Use FQN
    1. In import formatting setting set 'Use Fully Qualified Names'
    2. Use code completion to add filed File f; into the code
    • EXPECTED RESULT: When completing identifier File the fully qualified name is inserted (and no import)
  9. Imports Layout
    1. In formatting setting select 'Use Single Class Imports' and increase both 'Count ...'
    2. Modify 'Inport Layout table' so it contains following items (in this order): java.util, all other imports, java.io. Separate Statis Imports is unchecked
    3. Open class imports.Layout and use Organize Imports hint
    • EXPECTED RESULT: The imports are rearranged accoring to the given order
  10. Imports Layout - Separate Static Imports
    1. Open Formatting Setting and check 'Separate Static Imports'
    2. Modify the table so it contains: java.io (static), java.util, all other imports, java.io, all other imports (static)
    3. In imports.Layout use Organize Import hint
    • EXPECTED RESULT: The imports are rearranged accoring to the given order
  11. Imports Layout - Separate Groups
    1. In setting check 'Separate Groups'
    2. Use Organise Imports hints in imports.Layout
    • EXPECTED RESULT: Each group (related to single item in layout table) is separated by blank line

Test suite: Per-project formatting

Purpose: This tests formatting setting which applies only to one specific projects. This settings can be compiled among the projects
Setup: Start IDE with default formatting settings (clear userdir) and create new J2se project

  1. Formatting
    1. Open project properties
    2. Select tab formatting
    3. Select 'Use project specific options'
    4. Customize the formatting setting is this dialog
    5. Confirm and reformat source code
    • EXPECTED RESULT: The project formatting is changed. It effects only files in this project. Other files are unchanged. The formatting settings are written to project.properties as a set of properties which differs from the default setting.
  2. Formatting - setting to default
    1. Open project properties
    2. Open project properties
    3. Select tab formatting
    4. Select 'Use global setting'
    5. Confirm and reformat code
    • EXPECTED RESULT: The sources are formatted according to default setting. A prompt dialog appears when 'Use global settings' is selected. Formatting settings are removed form project.properties
  3. Copy formatting setting
    1. Open project properties and customize project specific formatting
    2. Create new project
    3. Go to project properties, formatting tab
    4. Select 'Use project specific formatting' and press 'Load from other project'
    5. In the dialog select first project and confirm
    • EXPECTED RESULT: The settings are copied from the original project to the actual one.
  4. Invalid copy
    1. Repeat previous test case, but in the last step select project w/o project specific formatting
    • EXPECTED RESULT: A warning appears after selection of project, informing that there are no project specific formatting available
  5. Go to global setting
    1. Open project properties
    2. Select tab formatting
    3. Press 'Edit global options'
    • EXPECTED RESULT: Options dialog is opened with preselected Editor -> Formatting category


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