@@ -248,11 +248,11 @@ private static int getOrder(MethodDescriptor descriptor) {
248
248
* <h2>Custom Seed</h2>
249
249
*
250
250
* <p>By default, the random <em>seed</em> used for ordering methods is the
251
- * value returned by {@link System#nanoTime()} during static initialization
252
- * of this class . In order to support repeatable builds, the value of the
251
+ * value returned by {@link System#nanoTime()} during static class
252
+ * initialization . In order to support repeatable builds, the value of the
253
253
* default random seed is logged at {@code CONFIG} level. In addition, a
254
254
* custom seed (potentially the default seed from the previous test plan
255
- * execution) may be specified via the {@value ClassOrderer. Random#RANDOM_SEED_PROPERTY_NAME}
255
+ * execution) may be specified via the {@value Random#RANDOM_SEED_PROPERTY_NAME}
256
256
* <em>configuration parameter</em> which can be supplied via the {@code Launcher}
257
257
* API, build tools (e.g., Gradle and Maven), a JVM system property, or the JUnit
258
258
* Platform configuration file (i.e., a file named {@code junit-platform.properties}
@@ -265,15 +265,8 @@ class Random implements MethodOrderer {
265
265
266
266
private static final Logger logger = LoggerFactory .getLogger (Random .class );
267
267
268
- /**
269
- * Default seed, which is generated during initialization of this class
270
- * via {@link System#nanoTime()} for reproducibility of tests.
271
- */
272
- private static final long DEFAULT_SEED ;
273
-
274
268
static {
275
- DEFAULT_SEED = System .nanoTime ();
276
- logger .config (() -> "MethodOrderer.Random default seed: " + DEFAULT_SEED );
269
+ logger .config (() -> "MethodOrderer.Random default seed: " + RandomOrdererUtils .DEFAULT_SEED );
277
270
}
278
271
279
272
/**
@@ -294,7 +287,7 @@ class Random implements MethodOrderer {
294
287
*
295
288
* @see ClassOrderer.Random
296
289
*/
297
- public static final String RANDOM_SEED_PROPERTY_NAME = "junit.jupiter.execution.order.random.seed" ;
290
+ public static final String RANDOM_SEED_PROPERTY_NAME = RandomOrdererUtils . RANDOM_SEED_PROPERTY_NAME ;
298
291
299
292
public Random () {
300
293
}
@@ -306,28 +299,9 @@ public Random() {
306
299
@ Override
307
300
public void orderMethods (MethodOrdererContext context ) {
308
301
Collections .shuffle (context .getMethodDescriptors (),
309
- new java .util .Random (getCustomSeed ( context ). orElse ( DEFAULT_SEED )));
302
+ new java .util .Random (RandomOrdererUtils . getSeed ( context :: getConfigurationParameter , logger )));
310
303
}
311
304
312
- private Optional <Long > getCustomSeed (MethodOrdererContext context ) {
313
- return context .getConfigurationParameter (RANDOM_SEED_PROPERTY_NAME ).map (configurationParameter -> {
314
- Long seed = null ;
315
- try {
316
- seed = Long .valueOf (configurationParameter );
317
- logger .config (
318
- () -> String .format ("Using custom seed for configuration parameter [%s] with value [%s]." ,
319
- RANDOM_SEED_PROPERTY_NAME , configurationParameter ));
320
- }
321
- catch (NumberFormatException ex ) {
322
- logger .warn (ex ,
323
- () -> String .format (
324
- "Failed to convert configuration parameter [%s] with value [%s] to a long. "
325
- + "Using default seed [%s] as fallback." ,
326
- RANDOM_SEED_PROPERTY_NAME , configurationParameter , DEFAULT_SEED ));
327
- }
328
- return seed ;
329
- });
330
- }
331
305
}
332
306
333
307
}
0 commit comments