Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a Java class from a groovy test file in IntelliJ

Trying to do TDD in a java project using groovy tests, I need to generate java classes on the fly (Alt+Enter from the test on the name of a class I want to introduce -> Create class -> Select the java main package as Target destination).
The problem is that, even if the Target destination is a java source directory, IntelliJ generates a groovy class.

Is there any way to quickly generate a Java class, instead?

like image 863
tibtof Avatar asked Oct 15 '16 10:10

tibtof


People also ask

How do I create a test class for a Java class in IntelliJ?

Create a new test class manuallyRight-click the test root folder or package in the test root folder in which you want to create a new test and select New | Java Class. Name the new class and press Enter . Press Alt+Insert and select Test Method to generate a new test method for this class.

How do I create a Groovy class in IntelliJ?

In the Project tool window, right-click the project and from the context menu, select Add Framework Support. In the dialog that opens, select Groovy and click OK. IntelliJ IDEA adds the Groovy SDK to your project and you can add Groovy classes and Groovy scripts.

How do I create a class file in IntelliJ?

In the Project tool window ( Alt+1 ), right-click the node in which you want to create a new class and select New | Java Class. Alternatively, select the node, press Alt+Insert , and select Java Class.


1 Answers

With the current version of IntelliJ IDEA (2016.2.4) the only solution I found is to generate a groovy class (Alt+Enter| Create class from the test) and then convert it to Java (Refactor | Convert to Java).
To make it faster I also added a shortcut for Convert to Java: Ctrl+Shift+O was the best available option for me.

like image 174
tibtof Avatar answered Sep 25 '22 21:09

tibtof