TS 71 JavaHints
Hints Test Specification
Author: Max Sauer, Jiri Prox
Version: 7.1
Last update:2011/09/27
Introduction: This document serves as a test specification for Hints module.
Test suite: Basic hints
Purpose: Testing of baisc java Hints.
Setup: Open prepared test project.
- Simple Import
- Place caret at basic.Import:13
- Use hint Add import for javax.swing.JTable
- EXPECTED RESULT: Import is properly added
- Simple Import 2
- Place caret at basic.Import:14
- Press "Alt-Enter"
- EXPECTED RESULT: The hint Add import for FileReader is shown only once
- Import - Multiple Choice
- Place caret as basic.Import:15
- Press Alt-enter
- EXPECTED RESULT: Two possible imports are available to be added
- Exceptions
- Make sure Surround with try-catch hint is enabled in Options -> Java Code -> Hints
- Place caret at basic.Exceptions:20
- Use Add throws clause hint
- Undo change and use both variant of Surround Statement/Block with
- EXPECTED RESULT: In 3) the throws clause is added and hint in no longer provided on current line. In 4) the one line (Surround statemenr) of whole method body is surrounded with try-catch
- Exceptions - adding catch clause
- Place caret at basic.Exceptions:20
- Use Surround Block with hint
- Place caret on next line
- Use Surround Block with hint
- EXPECTED RESULT: The catch clauses is added to the existing one after step 4
- Exceptions - more exceptions
- Place caret at basic.Exceptions:28
- Try separately all hints: Surround Block/Statement with hint and Add throws
- EXPECTED RESULT: Two catch clauses are created/ throws exception is added to throws list
- Cast
- Place caret at basic.Cast:27
- Use hint Cast o
- EXPECTED RESULT: Cast to Number is added
- Cast - return
- Place caret at basic.Cast:19
- Use hint Cast get(...)
- EXPECTED RESULT: Cast to String is added
- Cast - return 2
- Place caret at basic.Cast:22
- Use hint Cast get(...)
- EXPECTED RESULT: Cast to List<? extends Integer> is added
- Cast - method argument
- Place caret at basic.Cast:32
- Use hint Cast o
- EXPECTED RESULT: Cast to List is added
- Change type - field
- Place caret at basic.ChangeType:17
- Use hint Change type
- EXPECTED RESULT: Type of field is changed to Integer
- Change type - return
- Place caret at basic.ChangeType:23
- Use hint Change type
- EXPECTED RESULT: Type of field is changed to proper type
- Implement All abstract method
- Place caret at basic.ImplementAll:16
- Use hint Implement all abstract methods...
- EXPECTED RESULT: public void run() is added, it contains only throw new UnsupportedOperationException("Not supported yet.");
- Implement All abstract method - generics
- Place caret at basic.ImplementAll:20
- Use hint Implement all abstract methods...
- EXPECTED RESULT: All required methods are added, the generic type is used correctly
- Implement All abstract method - abs. class
- Place caret at basic.ImplementAll:24
- Use hint Implement all abstract methods...
- EXPECTED RESULT: Methods from Runnable and AbsClass are added, @Override annotation is added to absMethod()
- Missing element
- Make sure Create local variable hint is enabled
- Place caret at basic.MissingElement:15
- Use hint to create local variable
- Use hint to create method parameter
- Use hint to create field
- Change type on the right side to smtg else (new List<String>(); 1.3f; method call; etc...)
- EXPECTED RESULT: The local variable/parameter/field with correct type is created
- Missing element - static
- Place caret at basic.MissingElement:19
- Use hint to create field in AuxClass
- EXPECTED RESULT: The static filed is created in AuxClass
- Create method
- Place caret at basic.CreateMethod:16
- Use hint to create new method
- EXPECTED RESULT: The new private method is created in current class, all argument and return type are correct
- Create method
- Place caret at basic.CreateMethod:17
- Use hint to create new method
- EXPECTED RESULT: The new static method is created in AuxClass
- Initialize primitive type
- Place caret at basic.Initialize:21
- Use hint to initialize variable
- Change int to different primitive type (or array)
- EXPECTED RESULT: The variable is initialized by correct value
- Initialize object
- Place caret at basic.Initialize:23
- Use hint to initialize variable
- Change String to different primitive type (array of types, generic type etc...)
- EXPECTED RESULT: The variable is initialized by correct value
Test suite: Standard Javac Hints
Purpose: Testing of Standard Javac Hints functionality.
Setup: Enable all hints in category Standard Javac Warnings, disable all other hints. Open Standard.java class
- Serialization
- Place caret on line 16, invoke hint.
- EXPECTED RESULT: Warning about undefined serialVersionUID.
- Finally
- Place caret on line 31, invoke hint.
- EXPECTED RESULT: Warning displayed, stating finally clause cannot complete normally.
- Fallthrough
- Place caret on line 28, invoke hint.
- EXPECTED RESULT: @SuppressWarnings("fallthrough") added, before method declaration.
- Deprecated
- Place caret on line 20, invoke hint.
- EXPECTED RESULT: @SuppressWarnings("deprecation") added, before method declaration.
- Empty statement after if
- Place caret on line 22, invoke hint.
- EXPECTED RESULT: Warning displayed, stating empty statement after if.
- Unnecessary cast
- Place caret on line 21, invoke hint.
- EXPECTED RESULT: Redundant cast has been removed.
- Division by zero
- Place caret on line 23, invoke hint.
- EXPECTED RESULT: Warning displayed, stating division by zero.
- Unchecked
- Place caret on line 19. Invoke hint.
- Place caret on line 42. Invoke hint.
- EXPECTED RESULT: Warning displayed, stating foo(java.lang.String[[ | ]]) in standard.Standard.java ....
Test suite: API Hints
Purpose: Testing of API Hints feature functionality.
Setup: Enable all hints in category APIs, disable all other hints
- Utility class with visible ctor
- Place caret on line 14 of API.java.
- Invoke appeared hint.
- EXPECTED RESULT: Constructor has been made private.
- Utility class w/o ctor
- Open API.java, remove constructor
- Put caret on line 12. Invoke appeared hint.
- EXPECTED RESULT: Newly created private ctor.
- Exposing private type through public API
- Open Private.java, place caret on LOC 20, 24 and 28
- Invoke appeared hint.
- EXPECTED RESULT: Warning displayed stating Exporting non-public type through public API.
Test suite: Empty Statements Hints
Purpose: Testing of Empty Statements Hints feature functionality.
Setup: Enable all hints in category Empty Statements, disable all other hints. Open Empty.java
- Empty statements
- Check the presence of warning icons on lines 15 - 19 and 22.
- EXPECTED RESULT: All empty statements should should bring up warning icon inside gutter. If hint is applied @SuppressWarnings("empty-statement") is added to the method declaration
Test suite: General Hints
Purpose: Testing of General Hints feature functionality.
Setup: Enable all hints in category General, disable all other hints. Open "General.java".
- Local variable Hides a Field
- Place caret on line 16.
- Invoke appeared hint.
- EXPECTED RESULT: This should invoke Instant rename action on local variable field. Field field shouldn't be affected.
- Double checked locking
- Place caret on line 53
- Invoke appeared hint
- EXPECTED RESULT: The outer if statement has been removed.
- Assign Return Value to New variable
- Place caret on LOC 18, inside parseInt(String) call.
- Invoke appeared hint
- EXPECTED RESULT: Return Value of parseInt() assigned to newly created variable, which becomes selected.
- String Comparing
- Put caret on line 19
- EXPECTED RESULT: Comparing warnings shown inside gutter.
- Generate Missing hashCode()
- Invoke hint on LOC 34.
- Select Generate Missig hasCode()
- Inside appeared dialog, check int x.
- EXPECTED RESULT: hashCode() generated, returning value based on x and a random prime number.
- EqualsWhichDoesntCheckParameterClass
- Invoke hint on LOC 34.
- Undo any previous changes
- select Suppress warning -EqualsWhichDoesntCheckParameterClass
- EXPECTED RESULT: Method is annotated with @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
- Generate Missing equals()
- Invoke hint on LOC 44.
- Inside appeared dialog, check int x.
- EXPECTED RESULT: equals() method is generated, using value of x.
- Accessing static via reference
- Place Caret on line 22 and invoke appeared hint.
- Place Caret on line 24 and invoke appeared hint.
- Invoke hint on LOC 5
- use Move class ...
- EXPECTED RESULT: The class is moved to correct package
- Incorrect Package - move
- Invoke hint on LOC 5
- use Change package declaration to ....
- EXPECTED RESULT: Package declaration has been altered as appropriate.
- Assignment to itself
- Put caret on line 81
- EXPECTED RESULT: Warning should be shown LOC 81
- Hided field inherited from superclass
- Invoke hint on LOC 67
- EXPECTED RESULT: This should bring up Rename Refactoring invoked on Integer ff.
- Synchronization on non-final field
- Open General2.java
- On line 16 there is warning
- add keyword final to the declaration on line 13
- EXPECTED RESULT: There is warning when the file is opened. When keyword is added the warning disappears.
- .equals Method not Checking Type
- Open General2.java
- On line 22 there is warning
- Add if(obj instanceof Object) { }; or obj.getClass(); to line 23
- EXPECTED RESULT: There is hint Suppress warning ... when the file is opened. When code is added the warning disappears.
- .equals on Incompatible Types
- Open General2.java
- EXPECTED RESULT: On lines 41 - 44 there are warnings.
- .equals on Incompatible Types
- Open General2.java
- Put caret on line 50
- {{{1}}}
Test suite: JDK 5 Hints
Purpose: Testing of JDK 5 and later specific hints.
Setup: Open "JDK15.java". Enable all hints in category "JDK 1.5 and later", disable all other hints.
- Add @Override
- Place caret on line 24
- Invoke hint (may be hidden "under" override glyph in gutter).
- EXPECTED RESULT: @Override annotation should be added before method declaration. Code should be properly formatted.
- Annotation as superinterface
- Place caret on LOC 16.
- EXPECTED RESULT: Warning displayed, stating 'Don't use annotation Deprecated as superinteface'.
Test suite: Import hints
Purpose: Testing of import hints.
Setup: Open "imports.ImportsImport.java". Enable all hints in category Imports, disable all other hints.
- Forbidden package
- Place caret on line 13, invoke hint.
- EXPECTED RESULT: Warning displayed, stating 'Import from forbidden package'.
- Forbidden package 2
- Invoke Tools|Options|Editor|Hints|Imports|Import From Forbidden Package.
- Add a package patten, ie importpack.**. and Confirm OD.
- Add import matching the given pattern.
- EXPECTED RESULT: Warning should be displayed also for imports of the added package from now on.
- Star import
- invoke hint on LOC 12.
- EXPECTED RESULT: Warning should be displayed, stating 'Star Import'.
- Unused import
- Invoke hint on LOC 9.
- EXPECTED RESULT: Unused import should be removed. If there are more unused imports, the hint Remove All Unused Imports should be provided as well
- Import from java.lang.**
- Invoke hint on LOC 11.
- EXPECTED RESULT: Import should be removed.
- Import from same package
- Invoke hint on LOC 14.
- EXPECTED RESULT: Import should be removed.
Test suite: Javadoc hints
Test suite: Braces hints
Purpose: Testing of braces hints.
Setup: Open "Braces.java". Enable all hints in category Braces, disable all other hints.
- If-else
- Place caret on line 15, invoke hint.
- Undo changes
- Place caret on line 16, invoke hint.
- EXPECTED RESULT: Braces added.
- While
- Place caret on line 17, invoke hint.
- EXPECTED RESULT: Braces added.
- Do-While
- Place caret on line 18, invoke hint.
- EXPECTED RESULT: Braces added.
- For
- Place caret on line 19, invoke hint.
- EXPECTED RESULT: Braces added.
Test suite: NetBeans Development
Purpose: Testing of hints specific for NetBeans development.
Setup: Open "Development.java". Enable all hints in category NetBeans Development, disable all other hints.
- Empty cancel
- Place caret on line 21, invoke hint.
- Place caret on line 44, invoke hint.
- EXPECTED RESULT: Warning is displayed, stating Empty cancel().
- Illegal use of instanceof operator
- Place caret on line 26, invoke hint.
- Place caret on line 28, invoke hint.
- Place caret on line 30, invoke hint.
- EXPECTED RESULT: Warning is displayed, stating Illegal use of instanceof.
Test suite: Error fixes customization
Purpose: Test of customization of basic error fixing hints
Setup: Open any file.
- Create local variable inline
- Open Options -> Editor->Hints and select Error fixes, Create local variable
- Uncheck Create local variable in line
- create new empty method and enter
int a =3;
int b = 3;
z = a+b; - use hint to create new local variable
- EXPECTED RESULT: The decalration int z is created before other two declarations (NOTE: if there is super call, z is declared behind it)
- Try-catch customization
- Open file from some nb module
- Open OD and select Java Code -> Hitns -> Error Fixes -> Surround with
- Uncheck all enabled checkboxes
- Type FileReader fr = new FileReader(""); in editor
- use hint to surround it with try/catch
- try other templates for try/catch
- EXPECTED RESULT: The code is surrounded by try/catch, the content of catch body corresponds with selected option
- Surround statement/block
- type in editor:
System.out.println("firstline");
new FileReader("aaa");
System.out.println("lastline"); - use Surround statement with ....
- undo all changes
- use Surround block with ....
- EXPECTED RESULT: In first case only one statement is surrounded, in the second case, the whole block is surrounded
- type in editor: