Can I use Hamcrest's assertThat
to assert something about several objects in one line of code? The objects are not in a collection. For instance, I would like to assertThat
four strings are equal. Also, how can I assert that all objects are null?
Asked
Active
Viewed 104 times
0

Duncan Jones
- 67,400
- 29
- 193
- 254

Stabilitronio
- 83
- 7
-
I found it difficult to read your original question. I've rewritten it, hope it still makes sense to you. If not, please edit it again (or let me know in a comment). – Duncan Jones Sep 26 '14 at 09:13
-
possible duplicate of [What is the idiomatic Hamcrest pattern to assert that each element of an iterable matches a given matcher?](http://stackoverflow.com/questions/5985610/what-is-the-idiomatic-hamcrest-pattern-to-assert-that-each-element-of-an-iterabl) – Joe Sep 26 '14 at 12:42
2 Answers
-1
assertThat("All values should be equals to origin", origin, allOf(is(str1), is(str2));
assertThat("All values should be null", null, allOf(is(obj1), is(obj2));

Stabilitronio
- 83
- 7
-
1I think it would be more helpful for the op and further visitors, when you add some explaination to your intension. – Reporter Sep 26 '14 at 09:18
-
@reporter Note that this answerer *is* the OP (Q&A style). But your point is still valid. – Duncan Jones Sep 26 '14 at 09:25