1   package com.lexicalscope.fluentreflection.usecases;
2   
3   import static com.lexicalscope.fluentreflection.FluentReflection.object;
4   import static com.lexicalscope.fluentreflection.ReflectionMatchers.*;
5   import static org.hamcrest.MatcherAssert.assertThat;
6   import static org.hamcrest.Matchers.containsInAnyOrder;
7   
8   import javax.inject.Inject;
9   
10  import org.junit.Test;
11  
12  /*
13   * Copyright 2012 Tim Wood
14   *
15   * Licensed under the Apache License, Version 2.0 (the "License");
16   * you may not use this file except in compliance with the License.
17   * You may obtain a copy of the License at
18   *
19   * http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing, software
22   * distributed under the License is distributed on an "AS IS" BASIS,
23   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24   * See the License for the specific language governing permissions and
25   * limitations under the License.
26   */
27  
28  public class TestCanFindAllAnnotatedFields {
29      public static class AnnotatedFields {
30          public String field0;
31          String field1;
32          protected String field2;
33          @SuppressWarnings("unused") private String field3;
34  
35          @Inject public String annotatedField0;
36          @Inject String annotatedField1;
37          @Inject protected String annotatedField2;
38          @SuppressWarnings("unused") @Inject private String annotatedField3;
39      }
40  
41      private final AnnotatedFields subject = new AnnotatedFields();
42  
43      @SuppressWarnings("unchecked") @Test
44      public void canSelectAllFieldThatAreAnnotated() throws Exception {
45          assertThat(
46                  object(subject).fields(annotatedWith(Inject.class)),
47                  containsInAnyOrder(
48                          hasName("annotatedField0"),
49                          hasName("annotatedField1"),
50                          hasName("annotatedField2"),
51                          hasName("annotatedField3")));
52      }
53  }