views:

47

answers:

2

Is there any semantic difference between writing

assertThat(object1, is(equalTo(object2)));

and writing

assertThat(object1, equalTo(object2)));

? If not, I would prefer the first version, because it reads better. Are there any other considerations here?

A: 

They are equivalent, as far as I'm aware. The "Is" matcher just passes through to the contained matcher. It seems it's there to add readability, and perhaps backwards compatibility.

skaffman
+1  A: 

Documentation says it all:
Decorates another Matcher, retaining the behavior but allowing tests to be slightly more expressive.
eg. assertThat(cheese, equalTo(smelly))
vs assertThat(cheese, is(equalTo(smelly)))

http://www.junit.org/apidocs/org/hamcrest/core/Is.html
In other words, you're on the right track.

Nikita Rybak
Facepalm - I shoulda read that.
Space_C0wb0y