ExpectedException#expectMessage(String) doesn't work at all; expectMessage(Matcher) doesn't work well

312 views
Skip to first unread message

eYeScReAmFM

unread,
Jul 21, 2016, 3:57:49 AM7/21/16
to mockito
Hi there,
I've just faced with 2 issues.

---1. For the following example of code (assume it's a nominal case, i.e. the test should pass):

@Rule
public ExpectedException expectedException = ExpectedException.none();
...
@Test
public void test() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Abc!");
...
}

the following exception is thrown:

java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V

It is caused by another NoSuchMethodError: org.hamcrest.CoreMatchers.containsString(Ljava/lang/String;)

I've checked method expectMessage, and, indeed, it has a reference to
CoreMatchers.containsString(substring)

which doesn't exist for mockito implementation of CoreMatchers.

Current versions in use by me are: junit-4.11; mockito-all-1.10.8; hamcrest-core-1.3, but I've also checked junit-4.12 & mockito-all-1.10.19, mockito-all-2.0.2-beta

Workaround for nominal test case is to use
expectedException.expectMessage(CoreMatchers.equalTo("Abc!"));

---2. but! even with the 1st problem worked around, in any error case, i.e. when the test should fail, it fails with the same exception:

java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V

Could you investigate and fix this?
Reply all
Reply to author
Forward
0 new messages