4

I am using Hamcrest in a gradle/JVM project via the org.hamcrest:hamcrest:2.2 artifact which is what the Hamcrest website recommends. When I go to static import a matcher, e.g. is or notNullValue, I am presented with 3 options of where to import it from. In the case of notNullValue these are:

  • org.hamcrest.CoreMatchers
  • org.hamcrest.Matchers
  • org.hamcrest.core.IsNull

I was wondering if there was a 'best practice' one to choose?

choice of imports

hughjdavey
  • 1,122
  • 2
  • 9
  • 17
  • 1
    Related question: https://stackoverflow.com/questions/10932941/difference-between-hamcrest-library-matchers-and-hamcrest-core-corematchers – Michael Nov 26 '21 at 22:15

1 Answers1

1

You can import all of these functions like this:

import static org.hamcrest.Matchers.*;
gurkan
  • 509
  • 1
  • 4
  • 18
  • Thanks for the reply. I meant more like should you import from Matchers, CoreMatchers, or the specific package (e.g. Is.is)? You seem to have chosen Matchers - what is the reason for that? – hughjdavey Nov 29 '21 at 09:00