1 | 32 | |
2 | |
|
3 | |
|
4 | |
package com.lexicalscope.fluentreflection; |
5 | |
|
6 | |
import java.util.regex.Pattern; |
7 | |
|
8 | |
import org.hamcrest.Description; |
9 | |
|
10 | |
final class MatcherHasNameMatching extends ReflectionMatcher<FluentMember> { |
11 | |
private final String regex; |
12 | |
private final Pattern pattern; |
13 | |
|
14 | 32 | MatcherHasNameMatching(final String regex) { |
15 | 32 | this.regex = regex; |
16 | 32 | pattern = Pattern.compile(regex); |
17 | 32 | } |
18 | |
|
19 | |
@Override |
20 | |
public boolean matchesSafely(final FluentMember arg) { |
21 | 32 | return pattern.matcher(arg.name()).matches(); |
22 | |
} |
23 | |
|
24 | |
@Override |
25 | |
public void describeTo(final Description description) { |
26 | 8 | description.appendText("callable matching ").appendValue(regex); |
27 | 8 | } |
28 | |
} |