This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 162593 - [67cat] Add hints to Junit test generation
Summary: [67cat] Add hints to Junit test generation
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: JUnit (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Theofanis Oikonomou
URL:
Keywords: API, API_REVIEW_FAST, PLAN
Depends on:
Blocks:
 
Reported: 2009-04-14 14:36 UTC by theshadow27
Modified: 2013-02-14 02:20 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
a patch (44.59 KB, patch)
2013-02-06 10:57 UTC, Theofanis Oikonomou
Details | Diff
a patch (43.07 KB, patch)
2013-02-07 09:48 UTC, Theofanis Oikonomou
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description theshadow27 2009-04-14 14:36:36 UTC
It would be useful to:

1) Display a hint next to the class definition if (a) Junit is enabled for the project and (b) there is no unit test for the class
   \_ Clicking the hint next to the class should give the option to generate a unit test for the class

2) Display a hint next to each method in the class if (a) there is a unit test for the class and (b) there no corresponding unit test method 
   \_ Clicking the hint next to the method should give the option to generate a unit test for the method

These hints should have a setting next to the rest of the hints, to allow them to be toggled on and off.
Comment 1 Theofanis Oikonomou 2013-02-06 10:57:18 UTC
Created attachment 131055 [details]
a patch

The patch contains two things.

First the part of the hints. It includes three classes in java.testrunner module that provide the two hints and also using the new api from the second part.

Second the part that includes two classes in the gsf.testrunner module. This is needed in order to be able to use the same dialog to create tests from the hints popup.

The new api is needed as hints api related stuff are in java cluster while gsf.testrunner is in ide cluster. So I choose to put the new hints in java.testrunner module which is part of the java cluster.
Comment 2 Theofanis Oikonomou 2013-02-06 11:01:30 UTC
Please review. It is my first try with hints. I do not know if I am following hints standards, so any comments are more than welcome. Thank you
Comment 3 Jan Lahoda 2013-02-06 14:44:21 UTC
A few comments:
1. seems that that you want is a lightbulb that only appears when the cursor is at the class/method declaration. I would suggest to use: @Hint(..., category = "suggestions", hintKind = Kind.ACTION, severity = Severity.HINT). No strong need to use JavaFix when this is done, can use "normal" Fix. In general, I don't really like introducing the hintKind = Kind.INSPECTION, severity = Severity.HINT. Also, if you would like to keep hintKind = Kind.INSPECTION for any reason, please use either options=Options.QUERY (if the hint should work in Source/Inspect, but not in Refactor/Inspect and Transform) or options=Options.NO_BATCH (if the hint should worker in neither the Source/Inspect nor Refactor/Inspect and Transform) - the hint apparently cannot work properly in Refactor/Inspect and Transform (there must not be any side-effects of the JavaFix.performRewrite to make it work in I&T).
2. This:
private static HashMap<Object, ArrayList<String>> validCombinations;
seems very suspicious to me. When is the map cleared? Fields like this typically lead to a memory leak, and it seems the field is re-initialized before each use, so I would suggest to drop it completely, use CompilationInfo.putCachedValue, or at least make sure the values won't be kept in the memory for the whole eternity.
3. Don't use CaretAwareJavaSourceTaskFactory.getLastPosition, use HintContext.getCaretLocation.

Stylistic comments:
4. don't use tabulators.
5. in some cases
Lookup.getDefault().lookupResult(TestCreatorProvider.class).allItems();
could be replaced (with easier and more readable):
Lookup.getDefault().lookupAll(TestCreatorProvider.class)
6. I would suggest using Map/List instead of HashMap/ArrayList, unless HashMap/ArrayList is the only implementation that will ensure correct behaviour.
Comment 4 Theofanis Oikonomou 2013-02-07 09:46:25 UTC
(In reply to comment #3)
> A few comments:
> 1. seems that that you want is a lightbulb ...

wasn't sure which combination to use. I will use the @Hint(..., category =
"suggestions", hintKind = Kind.ACTION, severity = Severity.HINT)

> 2. This:
> private static HashMap<Object, ArrayList<String>> validCombinations;
> seems very suspicious to me...

made it method private and also clearing it when no more useful

> 3. Don't use CaretAwareJavaSourceTaskFactory.getLastPosition, use
> HintContext.getCaretLocation.

will do

> 
> Stylistic comments:
> 4. don't use tabulators.
> 5. in some cases
> Lookup.getDefault().lookupResult(TestCreatorProvider.class).allItems();
> could be replaced (with easier and more readable):
> Lookup.getDefault().lookupAll(TestCreatorProvider.class)
> 6. I would suggest using Map/List instead of HashMap/ArrayList, unless
> HashMap/ArrayList is the only implementation that will ensure correct
> behaviour.
Comment 5 Theofanis Oikonomou 2013-02-07 09:48:12 UTC
Created attachment 131085 [details]
a patch

updated the patch based on remarks from comment 3.
Comment 6 Theofanis Oikonomou 2013-02-11 11:31:49 UTC
If there are no objections, I plan to integrate the change on Wednesday. Thank you
Comment 7 Theofanis Oikonomou 2013-02-13 11:27:50 UTC
Changeset: 504efc1910de
Author:    Theofanis Oikonomou <theofanis@netbeans.org>
Date:      2013-02-13 12:25
Message:   
Issue #162593 - [67cat] Add hints to Junit test generation
Comment 8 Quality Engineering 2013-02-14 02:20:44 UTC
Integrated into 'main-golden', will be available in build *201302132300* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/504efc1910de
User: Theofanis Oikonomou <theofanis@netbeans.org>
Log: Issue #162593 - [67cat] Add hints to Junit test generation