3 ms·
I don't like them in general either, but there's one place I use them extensively: JUnit tests (statically import Mockito, Hamcrest, Assert, etc). It mostly ha
by peeters 15y ago
I don't like them in general either, but there's one place I use them extensively: JUnit tests (statically import Mockito, Hamcrest, Assert, etc).
It mostly has to do with how much the library tries to be a DSL, and how much readability will suffer if I don't use a static import. IMO, this
assertThat(6, isGreaterThan(5));
reads a heckuva lot better than
Assert.assertThat(6, Matchers.isGreaterThan(5));
Of course the combination of poor Java type inference and Generics-heavy libraries make it so that often I have to do the latter to make use of angle braces, but that's another story.
- ZitchDog 15y agoIt really should be Assert.that(6, Is.greaterThan(7)), shouldn't it? Best of both worlds!