1 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 public MatcherReturnType(final Matcher<? super FluentClass<?>> returnTypeMatcher) {
12 this.returnTypeMatcher = returnTypeMatcher;
13 }
14
15 @Override
16 protected boolean matchesSafely(final FluentMember item) {
17 final FluentClass<?> actualReturnType = item.type();
18
19 if (actualReturnType == null) {
20 return false;
21 }
22
23 return returnTypeMatcher.matches(actualReturnType);
24 }
25
26 @Override
27 public void describeTo(final Description description) {
28 description.appendText("callable with return ").appendDescriptionOf(returnTypeMatcher);
29 }
30
31 @Override
32 public final boolean equals(final Object that) {
33 if (that != null && that.getClass().equals(this.getClass())) {
34 return new EqualsBuilder()
35 .append(returnTypeMatcher, ((MatcherReturnType) that).returnTypeMatcher)
36 .isEquals();
37 }
38 return false;
39 }
40
41 @Override
42 public final int hashCode() {
43 return new HashCodeBuilder().append(returnTypeMatcher).toHashCode();
44 }
45 }