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 250809 - Patch for: "Create class"-hint: TDD using Maven, create class in src/main/java
Summary: Patch for: "Create class"-hint: TDD using Maven, create class in src/main/java
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.2
Hardware: All All
: P2 normal (vote)
Assignee: Svata Dedic
URL:
Keywords: PATCH_AVAILABLE
Depends on: 252136
Blocks: 262857
  Show dependency tree
 
Reported: 2015-03-02 10:06 UTC by rjdkolb
Modified: 2016-07-25 11:29 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Proposed patch (9.72 KB, patch)
2015-03-03 10:13 UTC, markiewb
Details | Diff
Patch in action (9.90 KB, image/png)
2015-03-03 10:13 UTC, markiewb
Details
Patch in action v2 (18.25 KB, image/png)
2015-03-03 10:15 UTC, markiewb
Details
Proposed patch v2 (with reordering of hints) (13.23 KB, patch)
2015-03-03 12:12 UTC, markiewb
Details | Diff
Patch in action v3 (16.45 KB, image/png)
2015-03-03 12:13 UTC, markiewb
Details

Note You need to log in before you can comment on or make changes to this bug.
Description rjdkolb 2015-03-02 10:06:22 UTC
Netbeans really makes working with Maven a pleasure.

As a TDD person, I always create my test first and reference a class that I am going to test (it does not exist yet).
Inside my Test, I get a can't find symbol, and I get prompted 'Create class xxx' in package yyy
When creating this class it creates a class in src/test/java' which is usually not what I want.

Can I suggest there should be two options when this this is prompted in a unit test
'Create class xxx' in main package yyy
'Create class xxx' in test package yyy

If there is a short cut key for these it would be beautiful.

Search dependency can still be the top one.
Comment 1 brettryan 2015-03-02 16:45:26 UTC
While this sounds like a valid thing to do it's not usually how I would approach TDD. Instead, first create your interface contract in your projects `src/main/java`, then a concrete implementation where all methods throw `throw new UnsupportedOperationException("Not supported yet.");`. Then choose Tools > Create/Update Tests...

This way your junit/testNG stubs get nutted out for you so you don't need to do the work hitting the hint to create the method for every single test you're about to create.

In TDD you're testing the contracts, not the structure of the implementation.


Here's the outlined steps.

 1. Create new interface contract.
 2. Create new implementation extending interface in #1.
 3. Use the hint "Implement all abstract methods"
 4. Choose Tools > Create/Update Tests...

This is only 4 steps and gives you failing tests for all contracts. If you choose to test private members or parts of the implementation not part of the contract then that can be achieved by repeatedly invoking "Create/Update Tests...".
Comment 2 rjdkolb 2015-03-03 06:22:20 UTC
Thanks @BrettRyan.

I may be taking Uncle Bob's 'The Three Rules Of Tdd' a little our of context, but I don't think so.
Uncle Bob shows how to create the test first, and then the implementation.

http://butunclebob.com/files/downloads/Bowling%20Game%20Kata.ppt

Also here is a YouTube video where is seems IntelliJ always defaults to creating new classes in src/main/java
(I think it's bad to do something just because a competitor does it, but in this case I think it's a good idea.)

https://www.youtube.com/watch?v=NDikuKeYATg
Comment 3 markiewb 2015-03-03 10:13:05 UTC
Created attachment 152344 [details]
Proposed patch

Here is a patch proposal. Please review.

The patch introduces a check. If the current file in a test source group two fixes are shown (one for src and one for src-test). If the current file in a main source group one fixe is shown (one for src).
Comment 4 markiewb 2015-03-03 10:13:33 UTC
Created attachment 152345 [details]
Patch in action
Comment 5 markiewb 2015-03-03 10:15:55 UTC
Created attachment 152346 [details]
Patch in action v2
Comment 6 rjdkolb 2015-03-03 10:23:02 UTC
Looks wonderful, thanks @Markiewb !

If the order could be 'create in package src/test/java' and then 'create in package src/main/java' please.
Comment 7 markiewb 2015-03-03 12:12:10 UTC
Created attachment 152358 [details]
Proposed patch v2 (with reordering of hints)

(In reply to rjdkolb from comment #6)
> If the order could be 'create in package src/test/java' and then 'create in
> package src/main/java' please.
Fixed in the new patch. The patch implements EnhancedFix instead of Fix to provide #getSortText()

See related following issue, where the same approach has been used.
https://netbeans.org/bugzilla/show_bug.cgi?id=231133
Comment 8 markiewb 2015-03-03 12:13:05 UTC
Created attachment 152359 [details]
Patch in action v3
Comment 9 rjdkolb 2015-03-03 12:17:11 UTC
Excellent, thanks Markiewb
Comment 10 Svata Dedic 2015-04-27 11:59:33 UTC
Just a question: what is the reason the  SourceGroup displayName (i.e. "Source Packages" is not used, "Unit Test Packages" and display relative root path instead ?

Does it seem more readable / illustrative ?
Comment 11 markiewb 2015-04-27 14:19:44 UTC
(In reply to Svata Dedic from comment #10)
> Just a question: what is the reason the  SourceGroup displayName (i.e.
> "Source Packages" is not used, "Unit Test Packages" and display relative
> root path instead ?
> 
> Does it seem more readable / illustrative ?

@Svata: You can change it as you like! It is only my preference, but I am also fine if texts like "Source Packages" are used.
Comment 12 Svata Dedic 2015-04-28 12:42:26 UTC
I've changed the code a little; I would preferer not to use relative paths to project, as freeform ant project may include source roots unrelated to the project directory.

I also filed issue #252136 against project system - I was not able to enumerate multiple test source roots (or maybe I overlooked some similar approach).

Patch applied as jet-main#88989df5c99a.

Thanks for the contribution!
Comment 13 rjdkolb 2015-04-28 14:06:43 UTC
Thanks Svata and @Markiewb!
Comment 14 Quality Engineering 2015-05-12 03:26:02 UTC
Integrated into 'main-silver', will be available in build *201505120001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/88989df5c99a
User: Svata Dedic <sdedic@netbeans.org>
Log: #250809: implemented create class in test packages (by Markiewb)