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   
7   import org.junit.Test;
8   
9   import com.lexicalscope.fluentreflection.Visibility;
10  
11  /*
12   * Copyright 2012 Tim Wood
13   *
14   * Licensed under the Apache License, Version 2.0 (the "License");
15   * you may not use this file except in compliance with the License.
16   * You may obtain a copy of the License at
17   *
18   * http://www.apache.org/licenses/LICENSE-2.0
19   *
20   * Unless required by applicable law or agreed to in writing, software
21   * distributed under the License is distributed on an "AS IS" BASIS,
22   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23   * See the License for the specific language governing permissions and
24   * limitations under the License.
25   */
26  
27  public class TestIdentifyMembersByVisibiity {
28      public static class AnnotatedFields {
29          public String fieldPublic;
30          String fieldPackage;
31          protected String fieldProtected;
32          private String fieldPrivate;
33  
34          public String getFieldPublic() {
35              return fieldPublic;
36          }
37  
38          String getFieldPackage() {
39              return fieldPackage;
40          }
41  
42          protected String getFieldProtected() {
43              return fieldProtected;
44          }
45  
46          private String getFieldPrivate() {
47              return fieldPrivate;
48          }
49      }
50  
51      private final AnnotatedFields subject = new AnnotatedFields();
52  
53      @Test public void canMatchPublicFieldVisibility() throws Exception {
54          assertThat(object(subject).field(hasName("fieldPublic")), hasVisibility(Visibility.PUBLIC));
55      }
56  
57      @Test public void canMatchPackageFieldVisibility() throws Exception {
58          assertThat(object(subject).field(hasName("fieldPackage")), hasVisibility(Visibility.DEFAULT));
59      }
60  
61      @Test public void canMatchProtectedFieldVisibility() throws Exception {
62          assertThat(object(subject).field(hasName("fieldProtected")), hasVisibility(Visibility.PROTECTED));
63      }
64  
65      @Test public void canMatchPrivateFieldVisibility() throws Exception {
66          assertThat(object(subject).field(hasName("fieldPrivate")), hasVisibility(Visibility.PRIVATE));
67      }
68  
69      @Test public void canMatchPublicMethodVisibility() throws Exception {
70          assertThat(object(subject).method(hasName("getFieldPublic")), hasVisibility(Visibility.PUBLIC));
71      }
72  
73      @Test public void canMatchPackageMethodVisibility() throws Exception {
74          assertThat(object(subject).method(hasName("getFieldPackage")), hasVisibility(Visibility.DEFAULT));
75      }
76  
77      @Test public void canMatchProtectedMethodVisibility() throws Exception {
78          assertThat(object(subject).method(hasName("getFieldProtected")), hasVisibility(Visibility.PROTECTED));
79      }
80  
81      @Test public void canMatchPrivateMethodVisibility() throws Exception {
82          assertThat(object(subject).method(hasName("getFieldPrivate")), hasVisibility(Visibility.PRIVATE));
83      }
84  }