Assert regex matches in JUnit

If you use assertThat() with a Hamcrest matcher that tests for regex matches, then if the assertion fails you’ll get a nice message that indicates expected pattern and actual text. The assertion will read more fluently also, e.g.

assertThat("FooBarBaz", matchesPattern("^Foo"));

with Hamcrest 2 you can find a matchesPattern method at MatchesPattern.matchesPattern.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)