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