JavaHamcrest icon indicating copy to clipboard operation
JavaHamcrest copied to clipboard

Duplicate regex Matcher

Open alb-i986 opened this issue 5 years ago • 4 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

alb-i986 avatar Apr 17 '20 14:04 alb-i986

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.

tingtron avatar Jul 28 '20 18:07 tingtron

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

nhojpatrick avatar Aug 06 '20 21:08 nhojpatrick

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.

hakanai avatar Feb 18 '21 23:02 hakanai