Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

Have you ever had the case where you had to test for the negative of something? I was helping a teammate who wanted to test that a collection was not empty. It was pretty hard to track down how to test for that.

We settled on not()

import static org.hamcrest.Matchers.not;
...
...not(hasSize(0))

This was pretty hard to find. There wasn’t much documentation on negation.

June 30th, 2014

Posted In: hamcrest, Java, JUnit

Leave a Comment

LinkedIn Auto Publish Powered By : XYZScripts.com