@@ -361,72 +361,84 @@ public void handleTestResults(TestResults testResults) {
361
361
}
362
362
363
363
public void addComponent (String name , Object component ) {
364
+ if (component == null ) {
365
+ return ;
366
+ }
367
+
368
+ if (component instanceof ReferenceResolverAware referenceResolverAware ) {
369
+ referenceResolverAware .setReferenceResolver (referenceResolver );
370
+ }
371
+
364
372
if (component instanceof InitializingPhase c ) {
365
373
c .initialize ();
366
374
}
375
+
367
376
referenceResolver .bind (name , component );
368
377
369
- if (component instanceof MessageValidator <?> messageValidator ) {
370
- messageValidatorRegistry .addMessageValidator (name , messageValidator );
371
- testContextFactory .getMessageValidatorRegistry ().addMessageValidator (name , messageValidator );
372
- }
378
+ synchronized (this ) {
379
+ if (component instanceof MessageValidator <?> messageValidator ) {
380
+ messageValidatorRegistry .addMessageValidator (name , messageValidator );
381
+ testContextFactory .getMessageValidatorRegistry ().addMessageValidator (name , messageValidator );
382
+ }
373
383
374
- if (component instanceof MessageProcessor messageProcessor ) {
375
- messageProcessors .addMessageProcessor (messageProcessor );
376
- testContextFactory .getMessageProcessors ().addMessageProcessor (messageProcessor );
377
- }
384
+ if (component instanceof MessageProcessor messageProcessor ) {
385
+ messageProcessors .addMessageProcessor (messageProcessor );
386
+ testContextFactory .getMessageProcessors ().addMessageProcessor (messageProcessor );
387
+ }
378
388
379
- if (component instanceof TestSuiteListener suiteListener ) {
380
- testSuiteListeners .addTestSuiteListener (suiteListener );
381
- }
389
+ if (component instanceof TestSuiteListener suiteListener ) {
390
+ testSuiteListeners .addTestSuiteListener (suiteListener );
391
+ }
382
392
383
- if (component instanceof TestListener testListener ) {
384
- testListeners .addTestListener (testListener );
385
- testContextFactory .getTestListeners ().addTestListener (testListener );
386
- }
393
+ if (component instanceof TestListener testListener ) {
394
+ testListeners .addTestListener (testListener );
395
+ testContextFactory .getTestListeners ().addTestListener (testListener );
396
+ }
387
397
388
- if (component instanceof TestReporter testReporter ) {
389
- testReporters .addTestReporter (testReporter );
390
- }
398
+ if (component instanceof TestReporter testReporter ) {
399
+ testReporters .addTestReporter (testReporter );
400
+ }
391
401
392
- if (component instanceof TestActionListener testActionListener ) {
393
- testActionListeners .addTestActionListener (testActionListener );
394
- testContextFactory .getTestActionListeners ().addTestActionListener (testActionListener );
395
- }
402
+ if (component instanceof TestActionListener testActionListener ) {
403
+ testActionListeners .addTestActionListener (testActionListener );
404
+ testContextFactory .getTestActionListeners ().addTestActionListener (testActionListener );
405
+ }
396
406
397
- if (component instanceof MessageListener messageListener ) {
398
- messageListeners .addMessageListener (messageListener );
399
- testContextFactory .getMessageListeners ().addMessageListener (messageListener );
400
- }
407
+ if (component instanceof MessageListener messageListener ) {
408
+ messageListeners .addMessageListener (messageListener );
409
+ testContextFactory .getMessageListeners ().addMessageListener (messageListener );
410
+ }
401
411
402
- if (component instanceof BeforeTest beforeTest ) {
403
- testContextFactory .getBeforeTest ().add (beforeTest );
404
- }
412
+ if (component instanceof BeforeTest beforeTest ) {
413
+ testContextFactory .getBeforeTest ().add (beforeTest );
414
+ }
405
415
406
- if (component instanceof AfterTest afterTest ) {
407
- testContextFactory .getAfterTest ().add (afterTest );
408
- }
416
+ if (component instanceof AfterTest afterTest ) {
417
+ testContextFactory .getAfterTest ().add (afterTest );
418
+ }
409
419
410
- if (component instanceof BeforeSuite beforeSuiteComponent ) {
411
- beforeSuite .add (beforeSuiteComponent );
412
- }
420
+ if (component instanceof BeforeSuite beforeSuiteComponent ) {
421
+ beforeSuite .add (beforeSuiteComponent );
422
+ }
413
423
414
- if (component instanceof AfterSuite afterSuiteComponent ) {
415
- afterSuite .add (afterSuiteComponent );
416
- }
424
+ if (component instanceof AfterSuite afterSuiteComponent ) {
425
+ afterSuite .add (afterSuiteComponent );
426
+ }
417
427
418
- if (component instanceof FunctionLibrary library ) {
419
- functionRegistry .addFunctionLibrary (library );
420
- testContextFactory .getFunctionRegistry ().addFunctionLibrary (library );
421
- }
428
+ if (component instanceof FunctionLibrary library ) {
429
+ functionRegistry .addFunctionLibrary (library );
430
+ testContextFactory .getFunctionRegistry ().addFunctionLibrary (library );
431
+ }
422
432
423
- if (component instanceof ValidationMatcherLibrary library ) {
424
- validationMatcherRegistry .addValidationMatcherLibrary (library );
425
- testContextFactory .getValidationMatcherRegistry ().addValidationMatcherLibrary (library );
426
- }
433
+ if (component instanceof ValidationMatcherLibrary library ) {
434
+ validationMatcherRegistry .addValidationMatcherLibrary (library );
435
+ testContextFactory .getValidationMatcherRegistry ().addValidationMatcherLibrary (library );
436
+ }
427
437
428
- if (component instanceof ReferenceResolverAware referenceResolverAware ) {
429
- referenceResolverAware .setReferenceResolver (referenceResolver );
438
+ if (component instanceof GlobalVariables vars ) {
439
+ globalVariables .getVariables ().putAll (vars .getVariables ());
440
+ testContextFactory .getGlobalVariables ().getVariables ().putAll (vars .getVariables ());
441
+ }
430
442
}
431
443
}
432
444
0 commit comments