• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.support.annotation;
17 
18 import static java.lang.annotation.RetentionPolicy.CLASS;
19 
20 import java.lang.annotation.Retention;
21 
22 /**
23  * Denotes that the class, method or field has its visibility relaxed, so that it is more widely
24  * visible than otherwise necessary to make code testable.
25  * <p>
26  * You can optionally specify what the visibility <b>should</b> have been if not for
27  * testing; this allows tools to catch unintended access from within production
28  * code.
29  * <p>
30  * Example:
31  * <pre><code>
32  *  &#64;VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
33  *  public String printDiagnostics() { ... }
34  * </code></pre>
35  *
36  * If not specified, the intended visibility is assumed to be private.
37  */
38 @Retention(CLASS)
39 public @interface VisibleForTesting {
40     /**
41      * The visibility the annotated element would have if it did not need to be made visible for
42      * testing.
43      */
44     @ProductionVisibility
otherwise()45     int otherwise() default PRIVATE;
46 
47     /**
48      * The annotated element would have "private" visibility
49      */
50     int PRIVATE = 2; // Happens to be the same as Modifier.PRIVATE
51 
52     /**
53      * The annotated element would have "package private" visibility
54      */
55     int PACKAGE_PRIVATE = 3;
56 
57     /**
58      * The annotated element would have "protected" visibility
59      */
60     int PROTECTED = 4; // Happens to be the same as Modifier.PROTECTED
61 
62     /**
63      * The annotated element should never be called from production code, only from tests.
64      * <p>
65      * This is equivalent to {@code @RestrictTo.Scope.TESTS}.
66      */
67     int NONE = 5;
68 }
69