less than 1 minute read

This article will be a short one. Today I was trying to write a test case which I had to compare 2 maps, one expected map against an output map.

I could use Hamcrest to accomplish the task but that would involve importing another lib into the project. I noticed Spring Boot imports an lib called AssertJ by default. Following the lib documentation, I had a happy surprise seeing how easy and natural is to write test cases with AssertJ syntax.

The example below contains how to test the map and some additional examples about how to use AssertJ. The best thing is that different from Hamcrest you don’t need to know the matchers beforehand. The autocomplete feature of your favorite IDE will do that job for you.

For more info see the official documentation. If you are interested how to accomplish the same with Hamcrest I found a good example at Stack Overflow.

Have fun and keep coding!

Updated: