TS 72 JavaHints

(Difference between revisions)
Jiriprox (Talk | contribs)
(Created page with '==Hints Test Specification== '''Author:'''Jiri Prox [mailto:Jiri.Prox@Sun.COM Jiri Prox] <br/> '''Version:''' 7.2<br/> '''Last update:'''2012/05/11<br/> '''Introduction:'''This d…')

Current revision as of 12:17, 29 May 2012

Hints Test Specification

Author:Jiri Prox Jiri Prox
Version: 7.2
Last update:2012/05/11
Introduction:This document serves as a test specification for Hints module. It covers all java specific hints

Contents

Test suite: Basic hints

Purpose: Testing of baisc java Hints.
Setup: Open attached project

  1. Simple Import
    1. Place caret at basic.Import:13
    2. Use hint Add import for javax.swing.JTable
    • EXPECTED RESULT: Import is properly added
  2. Simple Import 2
    1. Place caret at basic.Import:14
    2. Press "Alt-Enter"
    • EXPECTED RESULT: The hint Add import for FileReader is shown only once
  3. Import - Multiple Choice
    1. Place caret as basic.Import:15
    2. Press Alt-enter
    • EXPECTED RESULT:Two possible imports are available to be added
  4. Exceptions
    1. Make sure Surround with try-catch hint is enabled in Options -> Java Code -> Hints
    2. Place caret at basic.Exceptions:20
    3. Use Add throws clause hint
    4. Undo change and use both variant of Surround Statement/Block with try-catch
    • EXPECTED RESULT:In step 3) the throws clause is added and hint in no longer provided on current line. In step 4) the one line (Surround statement) of whole method body is surrounded with try-catch
  5. Exceptions - adding catch clause
    1. Place caret at basic.Exceptions:20
    2. Use Surround Block with hint
    3. Place caret on next line
    4. Use Surround Block with hint
    • EXPECTED RESULT: The catch clauses is added to the existing one after step 4
  6. Exceptions - more exceptions
    1. Place caret at basic.Exceptions:28
    2. 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
  7. Cast
    1. Place caret at basic.Cast:27
    2. Use hint Cast o
    • EXPECTED RESULT: Cast to Number is added
  8. Cast - return
    1. Place caret at basic.Cast:19
    2. Use hint Cast get(...)
    • EXPECTED RESULT: Cast to String is added
  9. Cast - return 2
    1. Place caret at basic.Cast:22
    2. Use hint Cast get(...)
    • EXPECTED RESULT: Cast to List<? extends Integer> is added
  10. Change type - field
    1. Place caret at basic.ChangeType:17
    2. Use hint Change type
    • EXPECTED RESULT: Type of field is changed to Integer
  11. Change type - return
    1. Place caret at basic.ChangeType:23
    2. Use hint Change type
    • EXPECTED RESULT: Type of field is changed to proper type
  12. Implement All abstract method
    1. Place caret at basic.ImplementAll:16
    2. Use hint Implement all abstract methods...
    • EXPECTED RESULT: public void run() is added, it contains only throw new UnsupportedOperationException("Not supported yet.");
  13. Implement All abstract method - generics
    1. Place caret at basic.ImplementAll:20
    2. Use hint Implement all abstract methods...
    • EXPECTED RESULT: All required methods are added, the generic type is used correctly
  14. Implement All abstract method - abs. class
    1. Place caret at basic.ImplementAll:24
    2. Use hint Implement all abstract methods...
    • EXPECTED RESULT: Methods from Runnable and AbsClass are added, @Override annotation is added to absMethod()
  15. Missing element
    1. Make sure Create local variable hint is enabled
    2. Place caret at basic.MissingElement:15
    3. Use hint to create local variable
    4. Use hint to create method parameter
    5. Use hint to create field
    6. 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
  16. Missing element - static
    1. Place caret at basic.MissingElement:19
    2. Use hint to create field in AuxClass
    • EXPECTED RESULT: The static filed is created in AuxClass
  17. Create method
    1. Place caret at basic.CreateMethod:16
    2. Use hint to create new method
    • EXPECTED RESULT: The new private method is created in current class, all argument and return type are correct
  18. Create method
    1. Place caret at basic.CreateMethod:17
    2. Use hint to create new method
    • EXPECTED RESULT: The new static method is created in AuxClass
  19. Initialize primitive type
    1. Place caret at basic.Initialize:21
    2. Use hint to initialize variable
    3. Change int to different primitive type (or array)
    • EXPECTED RESULT: The variable is initialized by correct value
  20. Initialize object
    1. Place caret at basic.Initialize:23
    2. Use hint to initialize variable
    3. Change String to different primitive type (array of types, generic type etc...)
    • EXPECTED RESULT: The variable is initialized by correct value

Test suite: API Hints

Purpose: Testing of API Hints feature functionality.

Setup: Enable all hints in category APIs, disable all other hints

  1. Utility class with visible ctor
    1. Place caret on line 14 of API.java.
    2. Invoke appeared hint.
    • EXPECTED RESULT: Constructor has been made private.
  2. Utility class w/o ctor
    1. Open API.java, remove constructor
    2. Put caret on line 12. Invoke appeared hint.
    • EXPECTED RESULT: Newly created private ctor.
  3. Exposing private type through public API
    1. Open Private.java, place caret on LOC 20, 24 and 28
    2. Invoke appeared hint.
    • EXPECTED RESULT: Warning displayed stating Exporting non-public type through public API.

Test suite: Assignment Issues

Setup: Enable all hints in Assignment category

  1. Assignment replaceable by operator
    1. Open Assignment.java
    2. Put cursor at line 10
    3. Apply hint
    • {{{1}}}
  2. Assignment to catch block parameter
    1. Open Assignment.java
    2. Put caret at line 14
    • EXPECTED RESULT:Warning 'Assignment to catch block parameter' is displayed at this line
  3. Assignment to for-loop parameter
    1. Open Assignment.java
    2. Put caret at line 17
    • EXPECTED RESULT:Warning 'Assignment to for loop parameter' is displayed at this line
  4. Assignment to method parameter
    1. Open Assignment.java
    2. Put caret at line 19
    • EXPECTED RESULT:Warning 'Assignment to method parameter' is displayed at this line
  5. Nested Assignment
    1. Open Assignment.java
    2. Put caret at line 20 or 21
    • EXPECTED RESULT:Warning about nested assignment is displayed at this line
  6. Value of increment expression used
    1. Open Assignment.java
    2. Put caret at line 24
    • EXPECTED RESULT:Waring about increment/decrement usage is assignment is displayed here

Test suite: Bitwise Operations

Setup: Enable all hints in bitwise operations branch

  1. Incompatible mask
    1. Open Bitwise.java
    2. Put caret on line 5 and 6
    • EXPECTED RESULT:On both lines there is waring about incompatible mask
  2. Pointless bitwise operation
    1. Open Bitwise.java
    2. Put caret on lines 9, 10, 11, 12 and apply hint
    3. Put cursor at line 13 and apply hint
    • val;
  3. Shift operation outside of the reasonable range
    1. Open Bitwise.java
    2. Put caret at lines 15, 16, 18, 19
    3. Put caret at line 21
    • EXPECTED RESULT:Waring about shift operation out of range is shown at all lines

Test suite: Braces hints

Purpose: Testing of braces hints.

Setup: Open "Braces.java". Enable all hints in category Braces, disable all other hints.

  1. If-else
    1. Place caret on line 15, invoke hint.
    2. Undo changes
    3. Place caret on line 16, invoke hint.
    • EXPECTED RESULT: Braces added.
  2. While
    1. Place caret on line 17, invoke hint.
    • EXPECTED RESULT: Braces added.
  3. Do-While
    1. Place caret on line 18, invoke hint.
    • EXPECTED RESULT: Braces added.
  4. For
    1. Place caret on line 19, invoke hint.
    • EXPECTED RESULT: Braces added.

Test suite: Class Structure

Setup: Open ClassStructure.java. Enable all hints in Class Structure branch, optionally disable all other hints

  1. Class May Be Interface
    1. Put caret at line 6
    2. Apply hint
    • EXPECTED RESULT:Class MayBeInterface is changed into interface
  2. Class May Be Interface - negative
    1. Open ClassStructure.java
    2. At line 12 type "int x;"
    • EXPECTED RESULT:Hint Class may be interface is not provided at line 6, since the class contains fields which are not static private final, non-abstract method or inner class which cannot be changed into interface
  3. Final Class
    1. Put caret at line 16
    2. Apply hint
    • EXPECTED RESULT:Final class Final it turned into non-final
  4. Final Method
    1. Disable hint Final Method in Final Class
    2. Put cursor at line 17
    3. Apply hint
    • EXPECTED RESULT:final method meth() is turned into non-final
  5. Final Method in Final Class
    1. Turn on Final Method in final Class and disable Final Method and Final Class hints
    2. Put caret on line 17
    3. Apply hint
    • EXPECTED RESULT:method meth() is changed into non-final
  6. Final Private Method
    1. Put cursor on line 21
    2. Apply hint
    • EXPECTED RESULT:method meth2() is turned into non-final
  7. Final Static Method
    1. Put cursor at line 23
    2. Apply hint
    • EXPECTED RESULT:Method meth3() is changed into non-final
  8. Marker interface
    1. Put cursor at line 25
    • EXPECTED RESULT:Hint Marker Interface' is provided at this line
  9. Marker Interface - negative
    1. Put cursor at line 27
    • EXPECTED RESULT:Hint Marker Interface' is not provided at this line, since the Marker1 extends two other interfaces
  10. Multiple Top-level Classes
    1. Put cursor at line 49
    • EXPECTED RESULT:Multiple top level classes are reported here
  11. No-op method in abstract class
    1. Put cursor at line 30
    • EXPECTED RESULT:Empty method in abstract class is reported here, try adding come code to hide this hint
  12. Protected Member in Final Class
    1. Put cursor at line 40 and 42
    2. Apply hint at each line
    • EXPECTED RESULT:Both member are changed from protected to package private
  13. Public Constructor in Non-public Class
    1. Put cursor at line 51
    2. Apply the hint
    • EXPECTED RESULT:Cursor is changed from public to package private

Test suite: Code Maturity Issues

Setup: Enable all Code Maturity hints, optionally disable all other hints. Open Maturity.java

  1. Obsolete Collection
    1. Put cursor at line 9 and 10
    • EXPECTED RESULT:On both lines there is waring about usage of obsolete classes
  2. Print Stack Trace
    1. Put cursor at line 21
    2. Apply hint
    • EXPECTED RESULT:e.printStackTrace() is removed
  3. System out/err
    1. Put cursor at lines 15,16 and 17
    2. On all line apply the hint
    • EXPECTED RESULT:System.out and System.err usages are removed
  4. Thread Dump Stack
    1. Put cursor at line 20
    2. Apply hint
    • EXPECTED RESULT:Thread.dumpStack() is removed

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

  1. Empty statements
    1. 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: Encapsulation

Setup: Enable all Encapsulation hints, optionally disable all other hints. Open Encapsulation.java

  1. Access of Private Field Of Another Object
    1. Put cursor at line 44
    • EXPECTED RESULT:Waring about access to private filed of another object is present. See that there is no waring when accessing private method (line 45)
  2. Assignment to Array Field from Parameter
    1. Put cursor at line 49
    • EXPECTED RESULT:Warning about assignment to array is present at this line
  3. Assignment to Collection Field from Parameter
    1. Put cursor at line 61
    2. Try changing java.util.List to another subclass of Collection
    • EXPECTED RESULT:Warning about assignment to collection is present at this line
  4. Assignment to Date or Calendar Field from Parameter
    1. Put cursor at line 53 and 57
    • EXPECTED RESULT:Warnings about assignment to Data and Calendar are present at this lines
  5. Package Field
    1. Put caret at line 9
    2. Put caret at line 16
    • EXPECTED RESULT:Encapsulate refactoring dialog should be shown, witch preselected actual field
  6. Package Inner Class
    1. Put caret at line 16
    2. Apply hint (Move Inner To Outer)
    • EXPECTED RESULT:Move Inner Class To Outer refactoring should be invoked
  7. Protected Field
    1. Put caret at line 10
    2. Put caret at line 16
    • EXPECTED RESULT:Encapsulate refactoring dialog should be shown, witch preselected actual field
  8. Protected Inner Class
    1. Put caret at line 20
    2. Apply hint (Move Inner To Outer)
    • EXPECTED RESULT:Move Inner Class To Outer refactoring should be invoked
  9. Public Field
    1. Put caret at line 16
    • EXPECTED RESULT:Encapsulate refactoring dialog should be shown, witch preselected actual field
  10. Public Inner Class
    1. Put caret at line 24
    2. Apply hint (Move Inner To Outer)
    • EXPECTED RESULT:Move Inner Class To Outer refactoring should be invoked
  11. Return of Array Field
    1. Put caret at line 28
    • EXPECTED RESULT:Warning about returning array is present here
  12. Return of Collection Field
    1. Put caret at line 32
    • EXPECTED RESULT:Warning about returning collection is present here
  13. Return of Date or Calendar field
    1. Put caret at line 36 and 40
    • EXPECTED RESULT:Warnings about returning Date and Calendar are present at this lines
  14. Customization
    1. Write tests steps here
    • EXPECTED RESULT:
  15. Suppress warning
    1. Write tests steps here
    • EXPECTED RESULT:

Test suite: Error fixes customization

Purpose: Test of customization of basic error fixing hints

Setup: Open any file.

  1. Create local variable inline
    1. Open Options -> Editor->Hints and select Error fixes, Create local variable
    2. Uncheck Create local variable in line
    3. create new empty method and enter
      int a =3;
      int b = 3;
      z = a+b;
    4. 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)
  2. Try-catch customization
    1. Open file from some nb module
    2. Open OD and select Java Code -> Hitns -> Error Fixes -> Surround with
    3. Uncheck all enabled checkboxes
    4. Type FileReader fr = new FileReader(""); in editor
    5. use hint to surround it with try/catch
    6. try other templates for try/catch
    • EXPECTED RESULT: The code is surrounded by try/catch, the content of catch body corresponds with selected option
  3. Surround statement/block
    1. type in editor:
      System.out.println("firstline");
      new FileReader("aaa");
      System.out.println("lastline");
    2. use Surround statement with ....
    3. undo all changes
    4. use Surround block with ....
    • EXPECTED RESULT: In first case only one statement is surrounded, in the second case, the whole block is surrounded

Test suite: Finalization

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".

  1. Local variable Hides a Field
    1. Place caret on line 16.
    2. Invoke appeared hint.
    • EXPECTED RESULT: This should invoke Instant rename action on local variable field. Field field shouldn't be affected.
  2. Double checked locking
    1. Place caret on line 53
    2. Invoke appeared hint
    • EXPECTED RESULT: The outer if statement has been removed.
  3. Assign Return Value to New variable
    1. Place caret on LOC 18, inside parseInt(String) call.
    2. Invoke appeared hint
    • EXPECTED RESULT: Return Value of parseInt() assigned to newly created variable, which becomes selected.
  4. String Comparing
    1. Put caret on line 19
    • EXPECTED RESULT: Comparing warnings shown inside gutter.
  5. Generate Missing hashCode()
    1. Invoke hint on LOC 34.
    2. Select Generate Missig hasCode()
    3. Inside appeared dialog, check int x.
    • EXPECTED RESULT: hashCode() generated, returning value based on x and a random prime number.
  6. EqualsWhichDoesntCheckParameterClass
    1. Invoke hint on LOC 34.
    2. Undo any previous changes
    3. select Suppress warning -EqualsWhichDoesntCheckParameterClass
    • EXPECTED RESULT: Method is annotated with @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
  7. Generate Missing equals()
    1. Invoke hint on LOC 44.
    2. Inside appeared dialog, check int x.
    • EXPECTED RESULT: equals() method is generated, using value of x.
  8. Accessing static via reference
    1. Place Caret on line 22 and invoke appeared hint.
    2. Place Caret on line 24 and invoke appeared hint.
    3. Invoke hint on LOC 5
    4. use Move class ...
    • EXPECTED RESULT: The class is moved to correct package
  9. Incorrect Package - move
    1. Invoke hint on LOC 5
    2. use Change package declaration to ....
    • EXPECTED RESULT: Package declaration has been altered as appropriate.
  10. Assignment to itself
    1. Put caret on line 81
    • EXPECTED RESULT: Warning should be shown LOC 81
  11. Hided field inherited from superclass
    1. Invoke hint on LOC 67
    • EXPECTED RESULT: This should bring up Rename Refactoring invoked on Integer ff.
  12. Synchronization on non-final field
    1. Open General2.java
    2. On line 16 there is warning
    3. 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.
  13. .equals Method not Checking Type
    1. Open General2.java
    2. On line 22 there is warning
    3. 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.
  14. .equals on Incompatible Types
    1. Open General2.java
    • EXPECTED RESULT: On lines 41 - 44 there are warnings.
  15. .equals on Incompatible Types
    1. Open General2.java
    2. Put caret on line 50
    • {{{1}}}

Test suite: Import hints

Purpose: Testing of import hints.

Setup: Open "imports.ImportsImport.java". Enable all hints in category Imports, disable all other hints.

  1. Forbidden package
    1. Place caret on line 13, invoke hint.
    • EXPECTED RESULT: Warning displayed, stating 'Import from forbidden package'.
  2. Forbidden package 2
    1. Invoke Tools|Options|Editor|Hints|Imports|Import From Forbidden Package.
    2. Add a package patten, ie importpack.**. and Confirm OD.
    3. Add import matching the given pattern.
    • EXPECTED RESULT: Warning should be displayed also for imports of the added package from now on.
  3. Star import
    1. invoke hint on LOC 12.
    • EXPECTED RESULT: Warning should be displayed, stating 'Star Import'.
  4. Unused import
    1. 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
  5. Import from java.lang.**
    1. Invoke hint on LOC 11.
    • EXPECTED RESULT: Import should be removed.
  6. Import from same package
    1. Invoke hint on LOC 14.
    • EXPECTED RESULT: Import should be removed.

Test suite: Initialization

Test suite: Javadoc hints

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.

  1. Add @Override
    1. Place caret on line 24
    2. 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.
  2. Annotation as superinterface
    1. Place caret on LOC 16.
    • EXPECTED RESULT: Warning displayed, stating 'Don't use annotation Deprecated as superinteface'.

Test suite: Logging

Test suite: Maven

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.

  1. Empty cancel
    1. Place caret on line 21, invoke hint.
    2. Place caret on line 44, invoke hint.
    • EXPECTED RESULT: Warning is displayed, stating Empty cancel().
  2. Illegal use of instanceof operator
    1. Place caret on line 26, invoke hint.
    2. Place caret on line 28, invoke hint.
    3. Place caret on line 30, invoke hint.
    • EXPECTED RESULT: Warning is displayed, stating Illegal use of instanceof.

Test suite: Performance

Test suite: Portable Bugs

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

  1. Serialization
    1. Place caret on line 16, invoke hint.
    • EXPECTED RESULT: Warning about undefined serialVersionUID.
  2. Finally
    1. Place caret on line 31, invoke hint.
    • EXPECTED RESULT: Warning displayed, stating finally clause cannot complete normally.
  3. Fallthrough
    1. Place caret on line 28, invoke hint.
    • EXPECTED RESULT: @SuppressWarnings("fallthrough") added, before method declaration.
  4. Deprecated
    1. Place caret on line 20, invoke hint.
    • EXPECTED RESULT: @SuppressWarnings("deprecation") added, before method declaration.
  5. Empty statement after if
    1. Place caret on line 22, invoke hint.
    • EXPECTED RESULT: Warning displayed, stating empty statement after if.
  6. Unnecessary cast
    1. Place caret on line 21, invoke hint.
    • EXPECTED RESULT: Redundant cast has been removed.
  7. Division by zero
    1. Place caret on line 23, invoke hint.
    • EXPECTED RESULT: Warning displayed, stating division by zero.
  8. Unchecked
    1. Place caret on line 19. Invoke hint.
    2. Place caret on line 42. Invoke hint.
    • EXPECTED RESULT: Warning displayed, stating foo(java.lang.String[[ | ]]) in standard.Standard.java ....

Test suite: Suggestions

Test suite: Threading

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