IntelliJ IDEA 2017.1: Spring is here
Group of people holding hands image via Shutterstock
Spring Testing now supports Spring Boot 1.4.3. Furthermore, the upcoming Spring 5.0. Spring Data tools are updated to version 2.0 (including MongoDB, Redis, Solr,KeyValue, Gemfire, Apache Cassandra, REST, Neo4j, Couchbase, and Elasticsearch) and there’s a new Data tab in the Spring tool window which brings better repository navigation.
Less than one week later, JetBrains’ Trisha Gee explained in a blog post that support for testing using the Spring framework has been enhanced.
Spring Testing improvements — Overview
Gutter icons and navigation
Users will notice that where they use the standard test annotations, there are gutter icons to help them navigate around the code, the same as they would usually expect from Spring annotations.
Users can now see and navigate to the relevant application contexts, and navigate to the declarations of autowired beans.
Furthermore, IntelliJ IDEA recognizes classes annotated with Spring test annotations as a test that can be run.
IntelliJ IDEA also understands mocks, and how they work in Spring tests, Gee wrote. Gutter icons take users to the declaration of the mock.
Users can easily work with WebAppConfiguration with the provided navigation and code completion.
IntelliJ 2017.1 also offers support for test property sources and meta annotations for properties. For example, users get code completion for
@TestPropertySource and navigation to the properties file.
Code completion and navigation still work as expected even when users declare their own TestProperties annotation and alias the TestPropertySource attributes.
Completion and navigation are also provided is in the
@Sql annotation. IntelliJ IDEA offers suggestions and can even show users when they have configured something incorrectly.
Users can now catch problems that arise from using the wrong attributes on
@DirtiesContext with the help of inspections. For example, if users set the methodMode at the class level, a warning will appear.
Same goes for setting hierarchy mode when it’s not applicable
and for using classMode at the method level
More new inspections show where the method signature doesn’t match the annotation’s expectations. For example, if there’s a return type on a method annotated with either
or if the
@AfterTransaction methods take arguments.
For more information about Spring Testing improvements, check the IntelliJ blog.
Update March 21, 2017
JetBrains’ Trisha Gee explained in a blog post that the support IntelliJ IDEA 2017.1 offers for Java 9’s new modularity(Project Jigsaw) consists of code completion in the
module-info.java file and quick fixes for adding modules to your project.
How it works
Step 1: We have an ordinary IntelliJ IDEA module which contains a simple “Hello World” type application.
IntelliJ IDEA lets you create a new
module-info.java for your module.
module-info.java will have the basic structure provided for you.
Everything works as it should; you notice the impact of using modularity only when you try to use Java classes that you’d normally be able to access, Trisha wrote.
IntelliJ IDEA will help you find the problem and offer suggestions to fix it.
Furthermore, it makes the correct changes to the
The IDE offers code completion and suggestions even when you choose to edit the
module-info.java file yourself.
Quick fixes are available for the standard Java modules, but that’s not all: they can also help you write modular code yourself. According to the blog post, if you are trying to access code which belongs in another IntelliJ IDEA module, from inside a module which uses Java 9’s modularity (indicated by the presence of a
module-info.java file), IntelliJ IDEA will point out that you need to make some changes.
Trisha revealed that there is more code completion available to help you make the changes to the module that needs to be accessed. Once you have a
module-info.java file in the module you want to use, the required packages can be quickly exported.
Let’s have a look at the module which needs to use this newly exported code: use Alt and Enter if you want to receive suggestions as to how to fix the problems. First, the IntelliJ IDEA module
one must have a dependency on the IntelliJ IDEA module
two. Second, the
module-info.java file for module
one can be updated to show that the module requires module
Users must keep in mind that there are two systems of modularly here:
- The IntelliJ IDEA modules that you are probably already familiar with
- The new Java 9 (Jigsaw) modules that are configured using
module-info.java. To use Java 9 modularity, each Java 9 module must correspond to an IntelliJ IDEA module.
Don’t forget to declare your IntelliJ IDEA module dependencies as well as your Java 9 module dependencies.
In the last example, module
one was dependent upon module
However, it also needed to declare that it requires module two in
We may be four months away from Java 9 but it’s good to know that IntelliJ IDEA 2017.1 provides support for working with Java 9 modularity (Jigsaw).