1 | 1712 | package com.lexicalscope.fluentreflection; |
2 | |
|
3 | |
import static org.hamcrest.Matchers.contains; |
4 | |
|
5 | |
import java.util.ArrayList; |
6 | |
import java.util.List; |
7 | |
|
8 | |
import org.apache.commons.lang3.builder.EqualsBuilder; |
9 | |
import org.apache.commons.lang3.builder.HashCodeBuilder; |
10 | |
import org.hamcrest.Description; |
11 | |
import org.hamcrest.Matcher; |
12 | |
|
13 | |
final class MatcherArgumentTypes extends ReflectionMatcher<FluentMember> { |
14 | |
private final List<Matcher<? super FluentClass<?>>> argumentTypeMatchers; |
15 | |
|
16 | 966 | public MatcherArgumentTypes(final List<? extends Matcher<? super FluentClass<?>>> argumentTypeMatchers) { |
17 | 966 | this.argumentTypeMatchers = new ArrayList<Matcher<? super FluentClass<?>>>(argumentTypeMatchers); |
18 | 966 | } |
19 | |
|
20 | |
@Override |
21 | |
protected boolean matchesSafely(final FluentMember item) { |
22 | 1712 | final int actualArgumentCount = item.argCount(); |
23 | 1712 | final int expectedArgumentCount = argumentTypeMatchers.size(); |
24 | |
|
25 | 1712 | if (actualArgumentCount != expectedArgumentCount) { |
26 | 98 | return false; |
27 | 1614 | } else if (actualArgumentCount == 0 && expectedArgumentCount == 0) { |
28 | 802 | return true; |
29 | |
} |
30 | |
|
31 | 812 | return contains(argumentTypeMatchers).matches(item.args()); |
32 | |
} |
33 | |
|
34 | |
@Override |
35 | |
public void describeTo(final Description description) { |
36 | 8 | description.appendText("callable with arguments ").appendList("(", ", ", ")", argumentTypeMatchers); |
37 | 8 | } |
38 | |
|
39 | |
@Override |
40 | |
public final boolean equals(final Object that) { |
41 | 8 | if (that != null && that.getClass().equals(this.getClass())) { |
42 | 16 | return new EqualsBuilder() |
43 | 8 | .append(argumentTypeMatchers, ((MatcherArgumentTypes) that).argumentTypeMatchers) |
44 | 8 | .isEquals(); |
45 | |
} |
46 | 0 | return false; |
47 | |
} |
48 | |
|
49 | |
@Override |
50 | |
public final int hashCode() { |
51 | 0 | return new HashCodeBuilder().append(argumentTypeMatchers).toHashCode(); |
52 | |
} |
53 | |
} |