@@ -136,11 +136,16 @@ public static Description createSuiteDescription(Class<?> testClass) {
136
136
*/
137
137
public static final Description TEST_MECHANISM = new Description (null , "Test mechanism" );
138
138
139
- private final Collection <Description > children = new ConcurrentLinkedQueue <Description >();
140
- private final String displayName ;
141
- private final Serializable uniqueId ;
142
- private final Annotation [] annotations ;
143
- private volatile /* write-once */ Class <?> testClass ;
139
+ /*
140
+ * We have to use the f prefix until the next major release to ensure
141
+ * serialization compatibility.
142
+ * See https://github.com/junit-team/junit/issues/976
143
+ */
144
+ private final Collection <Description > fChildren = new ConcurrentLinkedQueue <Description >();
145
+ private final String fDisplayName ;
146
+ private final Serializable fUniqueId ;
147
+ private final Annotation [] fAnnotations ;
148
+ private volatile /* write-once */ Class <?> fTestClass ;
144
149
145
150
private Description (Class <?> clazz , String displayName , Annotation ... annotations ) {
146
151
this (clazz , displayName , displayName , annotations );
@@ -155,17 +160,17 @@ private Description(Class<?> testClass, String displayName, Serializable uniqueI
155
160
throw new IllegalArgumentException (
156
161
"The unique id must not be null." );
157
162
}
158
- this .testClass = testClass ;
159
- this .displayName = displayName ;
160
- this .uniqueId = uniqueId ;
161
- this .annotations = annotations ;
163
+ this .fTestClass = testClass ;
164
+ this .fDisplayName = displayName ;
165
+ this .fUniqueId = uniqueId ;
166
+ this .fAnnotations = annotations ;
162
167
}
163
168
164
169
/**
165
170
* @return a user-understandable label
166
171
*/
167
172
public String getDisplayName () {
168
- return displayName ;
173
+ return fDisplayName ;
169
174
}
170
175
171
176
/**
@@ -174,15 +179,15 @@ public String getDisplayName() {
174
179
* @param description the soon-to-be child.
175
180
*/
176
181
public void addChild (Description description ) {
177
- children .add (description );
182
+ fChildren .add (description );
178
183
}
179
184
180
185
/**
181
186
* Gets the copy of the children of this {@code Description}.
182
187
* Returns an empty list if there are no children.
183
188
*/
184
189
public ArrayList <Description > getChildren () {
185
- return new ArrayList <Description >(children );
190
+ return new ArrayList <Description >(fChildren );
186
191
}
187
192
188
193
/**
@@ -196,7 +201,7 @@ public boolean isSuite() {
196
201
* @return <code>true</code> if the receiver is an atomic test
197
202
*/
198
203
public boolean isTest () {
199
- return children .isEmpty ();
204
+ return fChildren .isEmpty ();
200
205
}
201
206
202
207
/**
@@ -207,15 +212,15 @@ public int testCount() {
207
212
return 1 ;
208
213
}
209
214
int result = 0 ;
210
- for (Description child : children ) {
215
+ for (Description child : fChildren ) {
211
216
result += child .testCount ();
212
217
}
213
218
return result ;
214
219
}
215
220
216
221
@ Override
217
222
public int hashCode () {
218
- return uniqueId .hashCode ();
223
+ return fUniqueId .hashCode ();
219
224
}
220
225
221
226
@ Override
@@ -224,7 +229,7 @@ public boolean equals(Object obj) {
224
229
return false ;
225
230
}
226
231
Description d = (Description ) obj ;
227
- return uniqueId .equals (d .uniqueId );
232
+ return fUniqueId .equals (d .fUniqueId );
228
233
}
229
234
230
235
@ Override
@@ -244,15 +249,15 @@ public boolean isEmpty() {
244
249
* children will be added back)
245
250
*/
246
251
public Description childlessCopy () {
247
- return new Description (testClass , displayName , annotations );
252
+ return new Description (fTestClass , fDisplayName , fAnnotations );
248
253
}
249
254
250
255
/**
251
256
* @return the annotation of type annotationType that is attached to this description node,
252
257
* or null if none exists
253
258
*/
254
259
public <T extends Annotation > T getAnnotation (Class <T > annotationType ) {
255
- for (Annotation each : annotations ) {
260
+ for (Annotation each : fAnnotations ) {
256
261
if (each .annotationType ().equals (annotationType )) {
257
262
return annotationType .cast (each );
258
263
}
@@ -264,24 +269,24 @@ public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
264
269
* @return all of the annotations attached to this description node
265
270
*/
266
271
public Collection <Annotation > getAnnotations () {
267
- return Arrays .asList (annotations );
272
+ return Arrays .asList (fAnnotations );
268
273
}
269
274
270
275
/**
271
276
* @return If this describes a method invocation,
272
277
* the class of the test instance.
273
278
*/
274
279
public Class <?> getTestClass () {
275
- if (testClass != null ) {
276
- return testClass ;
280
+ if (fTestClass != null ) {
281
+ return fTestClass ;
277
282
}
278
283
String name = getClassName ();
279
284
if (name == null ) {
280
285
return null ;
281
286
}
282
287
try {
283
- testClass = Class .forName (name , false , getClass ().getClassLoader ());
284
- return testClass ;
288
+ fTestClass = Class .forName (name , false , getClass ().getClassLoader ());
289
+ return fTestClass ;
285
290
} catch (ClassNotFoundException e ) {
286
291
return null ;
287
292
}
@@ -292,7 +297,7 @@ public Class<?> getTestClass() {
292
297
* the name of the class of the test instance
293
298
*/
294
299
public String getClassName () {
295
- return testClass != null ? testClass .getName () : methodAndClassNamePatternGroupOrDefault (2 , toString ());
300
+ return fTestClass != null ? fTestClass .getName () : methodAndClassNamePatternGroupOrDefault (2 , toString ());
296
301
}
297
302
298
303
/**
0 commit comments