17
17
import static com .google .common .base .Preconditions .checkArgument ;
18
18
import static com .google .common .collect .Iterables .getOnlyElement ;
19
19
20
- import com .google .auto . value . AutoValue ;
20
+ import com .google .common . annotations . VisibleForTesting ;
21
21
import com .google .common .base .Joiner ;
22
22
import com .google .common .collect .FluentIterable ;
23
23
import com .google .common .collect .ImmutableList ;
@@ -61,40 +61,14 @@ public final TestParameterValue value(@Nullable Object wrappedValue) {
61
61
* An immutable value class that contains extra information about the context of the parameter for
62
62
* which values are being provided.
63
63
*/
64
- @ AutoValue
65
- public abstract static class Context {
66
- /**
67
- * A list of all other annotations on the field or parameter that was annotated
68
- * with @TestParameter.
69
- *
70
- * <p>For example, if the test code is as follows:
71
- *
72
- * <pre>
73
- * {@literal @}Test
74
- * public void myTest_success(
75
- * {@literal @}CustomAnnotation(123) {@literal @}TestParameter(valuesProvider=MyProvider.class) Foo foo) {
76
- * ...
77
- * }
78
- * </pre>
79
- *
80
- * then this list will contain a single element: @CustomAnnotation(123).
81
- */
82
- abstract ImmutableList <Annotation > otherAnnotations ();
64
+ public static final class Context {
83
65
84
- /**
85
- * The class that contains the test that is currently being run.
86
- *
87
- * <p>Having this can be useful when sharing providers between tests that have the same base
88
- * class. In those cases, an abstract method can be called as follows:
89
- *
90
- * <pre>
91
- * ((MyBaseClass) context.testClass().newInstance()).myAbstractMethod()
92
- * </pre>
93
- */
94
- public abstract Class <?> testClass ();
66
+ private final ImmutableList <Annotation > otherAnnotations ;
67
+ private final Class <?> testClass ;
95
68
96
- static Context create (ImmutableList <Annotation > otherAnnotations , Class <?> testClass ) {
97
- return new AutoValue_TestParameterValuesProvider_Context (otherAnnotations , testClass );
69
+ Context (ImmutableList <Annotation > otherAnnotations , Class <?> testClass ) {
70
+ this .otherAnnotations = otherAnnotations ;
71
+ this .testClass = testClass ;
98
72
}
99
73
100
74
/**
@@ -119,7 +93,7 @@ static Context create(ImmutableList<Annotation> otherAnnotations, Class<?> testC
119
93
* handled by the TestParameterInjector framework.
120
94
*/
121
95
@ SuppressWarnings ("unchecked" ) // Safe because of the filter operation
122
- public final <A extends Annotation > A getOtherAnnotation (Class <A > annotationType ) {
96
+ public <A extends Annotation > A getOtherAnnotation (Class <A > annotationType ) {
123
97
checkArgument (
124
98
!TestParameter .class .equals (annotationType ),
125
99
"Getting the @TestParameter annotating the field or parameter is not allowed because"
@@ -133,14 +107,35 @@ public final <A extends Annotation> A getOtherAnnotation(Class<A> annotationType
133
107
134
108
// TODO: b/317524353 - Add support for repeated annotations
135
109
110
+ /**
111
+ * The class that contains the test that is currently being run.
112
+ *
113
+ * <p>Having this can be useful when sharing providers between tests that have the same base
114
+ * class. In those cases, an abstract method can be called as follows:
115
+ *
116
+ * <pre>
117
+ * ((MyBaseClass) context.testClass().newInstance()).myAbstractMethod()
118
+ * </pre>
119
+ */
120
+ public Class <?> testClass () {
121
+ return testClass ;
122
+ }
123
+
124
+ /**
125
+ * A list of all other annotations on the field or parameter that was annotated
126
+ * with @TestParameter.
127
+ */
128
+ @ VisibleForTesting
129
+ ImmutableList <Annotation > otherAnnotations () {
130
+ return otherAnnotations ;
131
+ }
132
+
136
133
@ Override
137
- public final String toString () {
134
+ public String toString () {
138
135
return String .format (
139
136
"Context(otherAnnotations=[%s],testClass=%s)" ,
140
137
FluentIterable .from (otherAnnotations ()).join (Joiner .on (',' )),
141
138
testClass ().getSimpleName ());
142
139
}
143
-
144
- Context () {} // Prevent implementations outside of this package
145
140
}
146
141
}
0 commit comments