Where is the declaration of JUnit Matcher#startsWith?

import static org.hamcrest.core.StringStartsWith.startsWith;

enables both

assertThat(msg, startsWith ("what"));

and

ExpectedException.none().expectMessage(startsWith("What")); //HERE

Most likely this is the startsWith method from the Hamcrest org.hamcrest.Matchers class.


Looking at ExpectedException, we can see that there are two expectMessage methods defined, one String and one Matcher, which is indeed org.hamcrest.Matcher.

/**
 * Adds to the list of requirements for any thrown exception that it should
 * <em>contain</em> string {@code substring}
 */
public void expectMessage(String substring) {
    expectMessage(containsString(substring));
}

/**
 * Adds {@code matcher} to the list of requirements for the message returned
 * from any thrown exception.
 */
public void expectMessage(Matcher<String> matcher) {
    expect(hasMessage(matcher));
}