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 172723 - Incorrect code of the unit test generated for interfaces
Summary: Incorrect code of the unit test generated for interfaces
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: JUnit (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Victor Vasilyev
URL:
Keywords:
: 169565 (view as bug list)
Depends on:
Blocks: 172634
  Show dependency tree
 
Reported: 2009-09-22 00:06 UTC by David Konecny
Modified: 2011-03-29 08:40 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Konecny 2009-09-22 00:06:37 UTC
Create JUnit Tests action generates unit test also for interfaces. That:
* does not make any sense; and
* generate code is not compilable (extends is used instead of implements)
Comment 1 Victor Vasilyev 2009-09-24 22:14:01 UTC
> Create JUnit Tests action generates unit test also for interfaces. That:
> * does not make any sense; and
It is not true. There are cases when it is needed, e.g. see an example here:
http://en.wikipedia.org/wiki/Unit_testing#Design

FYI A stub implementation of your interface will be automatically generated for you in the test class as a nested class.
You could consider a final version of that implementation as a reference implementation, and use it as a proof of
concept for your interface. 

> * generate code is not compilable (extends is used instead of implements)
I agree it is a bug.

Comment 2 David Konecny 2009-09-24 22:58:00 UTC
OK, "does not make any sense" is too strong statement. In practice, stub implementations of interfaces are often needed
but because they are usually used from more that one test you would place them as top level classes. My usecase for
filling this issue was: I generated an EJB with Local and Remote interfaces (a class + 2 interfaces in a package). I did
it twice and then I wanted to generate unit tests for my two EJBs so I right clicked package and used Generate JUnit
Tests action which resulted in 4 stub implementations/tests which do not make any sense. In most of the cases I would
use Generate JUnit Test action on single files so this part of the problem is certainly not high priority one. Thanks
for fixing incorrectly generated code.
Comment 3 Victor Vasilyev 2009-09-25 00:45:30 UTC
David,

To fix this issue I'll correct the test code generating in a part of generating a nested class implementing an
abstraction under test, so that:
- "implements" will be used for both interfaces and annotation types
- "extends" will be used for both classes and enums.

Could you please, check such approach from viewpoint of existing EJB functionality.
Comment 4 David Konecny 2009-09-25 00:55:47 UTC
That sounds good. Perhaps "Create Tests" customizer (when executed on a package) should in addition to "Abstract Classes"
option has also "Interfaces/Annotations" option? That would give user control. Or will you use "Abstract Classes" one
for interfaces as well and do not generate stubs for interfaces if the option is set to false?
Comment 5 Victor Vasilyev 2009-09-25 04:00:18 UTC
I'm absolutely agree with you, we need have additional options in the "Create Tests" dialog, but it seems it is a
separate P3 enhancement for the next release/update.

 
Comment 6 Victor Vasilyev 2009-09-25 16:29:31 UTC
Fixed in the main trunk:
http://hg.netbeans.org/main/rev/32d829516966
Comment 7 Victor Vasilyev 2009-09-25 16:57:33 UTC
See also Enhancement Issue 173120 - Processing of units should be improved
Comment 8 David Konecny 2009-09-27 21:40:48 UTC
Thanks.
Comment 9 Quality Engineering 2009-09-27 22:38:06 UTC
Integrated into 'main-golden', will be available in build *200909270201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/32d829516966
User: Victor G. Vasilyev <vvg@netbeans.org>
Log: Issue #172723 - Incorrect code of the unit test generated for interfaces
Comment 10 Victor Vasilyev 2009-11-16 07:28:55 UTC
*** Bug 169565 has been marked as a duplicate of this bug. ***