1 package com.lexicalscope.fluentreflection.endtoend;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import static com.lexicalscope.fluentreflection.FluentReflection.type;
20 import static com.lexicalscope.fluentreflection.ReflectionMatchers.*;
21 import static org.hamcrest.MatcherAssert.assertThat;
22 import static org.hamcrest.Matchers.equalTo;
23
24 import java.util.List;
25
26 import org.hamcrest.Matchers;
27 import org.junit.Test;
28
29 import com.lexicalscope.fluentreflection.FluentMethod;
30
31 public class TestReflectionOnInherentedMethods {
32 @Test
33 public void subinterfaceMethodsIncludeSuperinterfaceMethods() {
34 assertThat(
35 type(ExampleSubinterface.class).methods(hasNameContaining("Superinterface")),
36 Matchers.<FluentMethod>hasItem(hasName("getSuperinterfaceProperty")));
37 }
38
39 @Test
40 public void subinterfaceMethodsIncludeSubinterfaceMethods() {
41 assertThat(
42 type(ExampleSubinterface.class).methods(hasNameContaining("Subinterface")),
43 Matchers.<FluentMethod>hasItem(hasName("getSubinterfaceProperty")));
44 }
45
46 @Test
47 public void subclassMethodsIncludeSuperinterfaceMethods() {
48 assertThat(
49 type(ExampleSubclass.class).methods(hasNameContaining("Superinterface")),
50 Matchers.<FluentMethod>hasItem(hasName("getSuperinterfaceProperty")));
51 }
52
53 @Test
54 public void subclassMethodsIncludeSubinterfaceMethods() {
55 assertThat(
56 type(ExampleSubclass.class).methods(hasNameContaining("Subinterface")),
57 Matchers.<FluentMethod>hasItem(hasName("getSubinterfaceProperty")));
58 }
59
60 @Test
61 public void subclassMethodsIncludeSuperclassMethods() {
62 assertThat(
63 type(ExampleSubclass.class).methods(hasNameContaining("Superclass")),
64 Matchers.<FluentMethod>hasItem(hasName("getSuperclassProperty")));
65 }
66
67 @Test
68 public void subclassMethodsIncludeSubclassMethods() {
69 assertThat(
70 type(ExampleSubclass.class).methods(hasNameContaining("Subclass")),
71 Matchers.<FluentMethod>hasItem(hasName("getSubclassProperty")));
72 }
73
74 @Test
75 public void subsubclassMethodsIncludeSuperclassMethods() {
76 assertThat(
77 type(ExampleSubsubclass.class).methods(hasNameContaining("Superclass")),
78 Matchers.<FluentMethod>hasItem(hasName("getSuperclassProperty")));
79 }
80
81 @Test
82 public void declaredSubclassMethodsAreFound() {
83 final List<FluentMethod> methodsDeclaredByExampleSubclass =
84 type(ExampleSubclass.class).methods(declaredBy(ExampleSubclass.class));
85
86 assertThat(
87 methodsDeclaredByExampleSubclass,
88 Matchers.<FluentMethod>hasItem(hasName("getSubclassProperty")));
89
90 assertThat(
91 methodsDeclaredByExampleSubclass.size(),
92 equalTo(1));
93 }
94
95 @Test
96 public void declaredSuperclassMethodsAreFound() {
97 final List<FluentMethod> methodsDeclaredByExampleSuperclass =
98 type(ExampleSubclass.class).methods(declaredBy(ExampleSuperclass.class));
99
100 assertThat(
101 methodsDeclaredByExampleSuperclass,
102 Matchers.<FluentMethod>hasItem(hasName("getSuperclassProperty")));
103
104 assertThat(
105 methodsDeclaredByExampleSuperclass,
106 Matchers.<FluentMethod>hasItem(hasName("getSubinterfaceProperty")));
107
108 assertThat(
109 methodsDeclaredByExampleSuperclass,
110 Matchers.<FluentMethod>hasItem(hasName("getSuperinterfaceProperty")));
111
112 assertThat(
113 methodsDeclaredByExampleSuperclass.size(),
114 equalTo(3));
115 }
116 }