TS 71 JavaHints

Revision as of 13:42, 27 September 2011 by Jiriprox (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)

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.

Contents

Test suite: Basic hints

Purpose: Testing of baisc java Hints.

Setup: Open prepared test 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
    • 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
  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. Cast - method argument
    1. Place caret at basic.Cast:32
    2. Use hint Cast o
    • EXPECTED RESULT: Cast to List is added
  11. Change type - field
    1. Place caret at basic.ChangeType:17
    2. Use hint Change type
    • EXPECTED RESULT: Type of field is changed to Integer
  12. 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
  13. 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.");
  14. 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
  15. 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()
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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: 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: 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: 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: 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: 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: 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: 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.

  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: 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: 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
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