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
17
18
19
20
21
22
23
24
25
26
27
28
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 }