1   package com.lexicalscope.fluentreflection;
2   
3   import static com.lexicalscope.fluentreflection.Visibility.PUBLIC;
4   import static org.hamcrest.MatcherAssert.assertThat;
5   import static org.hamcrest.Matchers.equalTo;
6   
7   import java.lang.reflect.Member;
8   
9   import org.jmock.Expectations;
10  import org.jmock.auto.Mock;
11  import org.jmock.integration.junit4.JUnitRuleMockery;
12  import org.junit.Before;
13  import org.junit.Rule;
14  import org.junit.Test;
15  
16  /*
17   * Copyright 2012 Tim Wood
18   *
19   * Licensed under the Apache License, Version 2.0 (the "License");
20   * you may not use this file except in compliance with the License.
21   * You may obtain a copy of the License at
22   *
23   * http://www.apache.org/licenses/LICENSE-2.0
24   *
25   * Unless required by applicable law or agreed to in writing, software
26   * distributed under the License is distributed on an "AS IS" BASIS,
27   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28   * See the License for the specific language governing permissions and
29   * limitations under the License.
30   */
31  
32  public class TestBoundReflectedMemberImpl {
33      @Rule public final JUnitRuleMockery context = new JUnitRuleMockery();
34  
35      @Mock private FluentMember member;
36      private final Object instance = new Object();
37  
38      private BoundFluentMemberImpl boundReflectedMemberImpl;
39  
40      @Before public void setUp() {
41          context.checking(new Expectations() {
42              {
43                  oneOf(member).isStatic(); will(returnValue(false));
44              }
45          });
46  
47          boundReflectedMemberImpl = new BoundFluentMemberImpl(null, member, instance) {
48              @Override public Member member() {
49                  return null;
50              }
51          };
52      }
53  
54      @Test public void isStaticIsDelegated() {
55          assertThat(boundReflectedMemberImpl.isStatic(), equalTo(false));
56      }
57  
58      @Test public void isFinalIsDelegated() {
59          context.checking(new Expectations() {
60              {
61                  oneOf(member).isFinal(); will(returnValue(true));
62              }
63          });
64          assertThat(boundReflectedMemberImpl.isFinal(), equalTo(true));
65      }
66  
67      @Test public void visibilityIsDelegated() {
68          context.checking(new Expectations() {
69              {
70                  oneOf(member).visibility(); will(returnValue(PUBLIC));
71              }
72          });
73          assertThat(boundReflectedMemberImpl.visibility(), equalTo(PUBLIC));
74      }
75  }