1 | 1472 | package com.lexicalscope.fluentreflection; |
2 | |
|
3 | |
import org.apache.commons.lang3.builder.EqualsBuilder; |
4 | |
import org.apache.commons.lang3.builder.HashCodeBuilder; |
5 | |
import org.hamcrest.Description; |
6 | |
import org.hamcrest.Matcher; |
7 | |
|
8 | |
final class MatcherReturnType extends ReflectionMatcher<FluentMember> { |
9 | |
private final Matcher<? super FluentClass<?>> returnTypeMatcher; |
10 | |
|
11 | 800 | public MatcherReturnType(final Matcher<? super FluentClass<?>> returnTypeMatcher) { |
12 | 800 | this.returnTypeMatcher = returnTypeMatcher; |
13 | 800 | } |
14 | |
|
15 | |
@Override |
16 | |
protected boolean matchesSafely(final FluentMember item) { |
17 | 1472 | final FluentClass<?> actualReturnType = item.type(); |
18 | |
|
19 | 1472 | if (actualReturnType == null) { |
20 | 0 | return false; |
21 | |
} |
22 | |
|
23 | 1472 | return returnTypeMatcher.matches(actualReturnType); |
24 | |
} |
25 | |
|
26 | |
@Override |
27 | |
public void describeTo(final Description description) { |
28 | 8 | description.appendText("callable with return ").appendDescriptionOf(returnTypeMatcher); |
29 | 8 | } |
30 | |
|
31 | |
@Override |
32 | |
public final boolean equals(final Object that) { |
33 | 0 | if (that != null && that.getClass().equals(this.getClass())) { |
34 | 0 | return new EqualsBuilder() |
35 | 0 | .append(returnTypeMatcher, ((MatcherReturnType) that).returnTypeMatcher) |
36 | 0 | .isEquals(); |
37 | |
} |
38 | 0 | return false; |
39 | |
} |
40 | |
|
41 | |
@Override |
42 | |
public final int hashCode() { |
43 | 0 | return new HashCodeBuilder().append(returnTypeMatcher).toHashCode(); |
44 | |
} |
45 | |
} |