Content assist for static classes

Static imports have become common practice in jUnit, Mockito, Guava, Apache String Utils and Spring Test but by default Eclipse doesn’t have auto complete for static methods/fields. This leads to developers having to look up import statements (import static org.junit.Assert.assertTrue;) or making code less readable by referencing the Class.method (Assert.*). A powerful feature of eclipse is content assist (CRTL+SPACEBAR) and luckily with some configuration we are able to enjoy auto complete for static methods/fields. Wanting to learn more about static imports, check out Java documentation website.

Preferences -> Search for 'Content Assist' -> Java -> Content Assist

Eclipse Static imports Content Assists

Click static imports -> new type -> ‘org.junit.Assert’ (no *)

Eclipse Static imports Content Assists Favorites

Some of my favorites are:

  • org.hamcrest.Matchers
  • org.hamcrest.CoreMatchers
  • com.jayway.jsonassert.JsonAssert
  • org.junit.Assert
  • org.mockito.Matchers
  • org.mockito.Mockito
  • org.springframework.test.web.servlet.request.MockMvcRequestBuilders
  • org.springframework.test.web.servlet.result.MockMvcResultHandlers
  • org.springframework.test.web.servlet.result.MockMvcResultMatchers
  • org.springframework.test.web.servlet.setup.MockMvcBuilders
  • com.google.common.base.Preconditions