hamcrest / JavaHamcrest

Java (and original) version of Hamcrest

Home Page:http://hamcrest.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duplicate regex Matcher

alb-i986 opened this issue · comments

Hi,

First of all, thanks for bringing this project back to life.

If I'm not mistaken there's a duplication in the regex matchers:

  • MatchesPattern
  • StringRegularExpression

There were none for such a long time and now there's two LOL
I'm not complaining huh, but I think it would be wise to leave only one ;)

Cheers

More specifically, there are two ways to match regex in test code:

  1. org.hamcrest.Matchers.matchesRegex(regexString)
  2. org.hamcrest.text.MatchesPattern.matchesPattern(regexString)

They are semantically the same, and mostly similar in implementation.

Yes the classes do appear to be duplicates and cover very similar functionaility;

org.hamcrest.Matchers.matchesRegex(String) basically calls out to org.hamcrest.core.StringRegularExpression

org.hamcrest.core.StringRegularExpression
org.hamcrest.text.MatchesPattern

I also wonder about:

  • theInstance(T) vs sameInstance(T)
  • any(Class<T>) vs instanceOf(Class<T>)

Also there is a general influx of badly-considered naming, documented here.

Similarly, there's Matchers.matchesPattern(Pattern) and Matchers.matchesRegex(Pattern).

This is confusing and wasting time for people trying to learn. I recommend deleting matchesRegex 👍