Finding the right Mockito import

I really enjoy working with Mockito, it’s a fantastic mocking framework for Java. However it can be a pain sometimes to know which packages to import for the tests you are writing.

A quick tip is to import everything while writing your tests & mocks like this:

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.mockito.Matchers.*;

Then once you have completed writing your tests use the CTRL+SHIFT+O (it’s CMD+SHIFT+O on Mac) shortcut in Eclipse to breakdown your imported packages to what you actually used.

You’ll end up with something like this:

import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Matchers.anyString;

Much easier yeah? 🙂

Source: Finding import static statements for Mockito constructs

Changing the CTRL + SHIFT + F settings in STS or Eclipse

I’m a big fan of clean well indented code but I’ve found the CTRL + SHIFT + F setting in STS & Eclipse to wrap lines way too soon.

Most people develop at 1080p resolution these days so it makes no sense to wrap lines so soon.

To change the line wrapping rules go to Window > Preferences > Java > Code Style > Formatter

Now create a new profile based off the current one, in my case this was Eclipse [built-in].

Click on Edit.. and go to the Line Wrapping tab, I set the Maximum line width to 240 but you can change it to whatever suits.

line wrapping 2

line wrapping

Source: Possible to change settings for CTRL + SHIFT + F in Eclipse?

Dmaven multiModuleProjectDirectory system propery is not set

This error just drove me mad in STS/Eclipse.

You need to add the Default VM argument -Dmaven.multiModuleProjectDirectory=$M2_HOME.

You do this by going to Window > Preference > Java > Installed JREs > Edit


This assumes you have the Environment variable M2_HOME set up correctly (this should be done when installed Maven).

Source: Stack Overflow