1   package com.lexicalscope.fluentreflection.endtoend;
2   
3   /*
4    * Copyright 2011 Tim Wood
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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 org.hamcrest.Matchers;
25  import org.junit.Test;
26  
27  import com.lexicalscope.fluentreflection.FluentMethod;
28  
29  public class TestReflectionOnInterface {
30      @Test public void classUnderReflectionReturnsClassUnderReflection() {
31          assertThat(
32                  type(ExampleInterface.class).classUnderReflection(),
33                  equalTo(ExampleInterface.class));
34      }
35  
36      @Test public void methodsCanBeSelectedByPrefix() {
37          assertThat(
38                  type(ExampleInterface.class).methods(hasNameStartingWith("get")),
39                  Matchers.<FluentMethod>hasItem(hasName("getPropertyOne")));
40      }
41  
42      @Test public void methodsCanBeSelectedBySuffix() {
43          assertThat(
44                  type(ExampleInterface.class).methods(hasNameEndingWith("One")),
45                  Matchers.<FluentMethod>hasItem(hasName("getPropertyOne")));
46      }
47  
48      @Test public void methodsCanBeSelectedByRegularExpression() {
49          assertThat(
50                  type(ExampleInterface.class).methods(hasNameMatching(".*Property.*")),
51                  Matchers.<FluentMethod>hasItem(hasName("getPropertyOne")));
52      }
53  
54      @Test public void methodsWithNoArgumentsCanBeSelected() {
55          assertThat(
56                  type(ExampleInterface.class).methods(
57                          hasArguments()),
58                  Matchers.<FluentMethod>hasItem(hasName("getPropertyOne")));
59      }
60  
61      @Test public void methodCanBeSelectedByArgument() {
62          assertThat(
63                  type(ExampleInterface.class).methods(hasArguments(String.class)),
64                  Matchers.<FluentMethod>hasItem(hasName("setPropertyOne")));
65      }
66  }