Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-318

Introduce a ComponentManagerRule to replace AbstractComponentTestCase

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Major
    • 4.3.1
    • 4.3
    • None

    Description

      See also XCOMMONS-317

      Usage example:

      @ComponentList({
          DefaultExtensionLicenseManager.class
      })
      public class DefaultExtensionLicenseManagerTest
      {
          @Rule
          public final ComponentManagerRule componentManager = new ComponentManagerRule();
      ...
          @Before
          public void setUp() throws Exception
          {
              this.licenseManager = this.componentManager.getInstance(ExtensionLicenseManager.class);
          }
      ...
      

      Another example (using the new @BeforeComponent annotation):

      @ComponentList({
          DefaultExtensionManagerConfiguration.class,
          DefaultLoggerManager.class,
          DefaultObservationManager.class
      })
      public class DefaultExtensionManagerConfigurationTest
      {
          @Rule
          public final MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule();
      
          private ExtensionManagerConfiguration configuration;
      
          private MemoryConfigurationSource source;
      
          @BeforeComponent
          public void registerComponents() throws Exception
          {
              // Register a Mocked Environment since we need to provide one.
              this.componentManager.registerMockComponent(Environment.class);
      
              // Register some in-memory Configuration Source for the test
              this.source = this.componentManager.registerMemoryConfigurationSource();
          }
      
          @Before
          public void setUp() throws Exception
          {
              this.configuration = this.componentManager.getInstance(ExtensionManagerConfiguration.class);
          }
      ...
      

      @BeforeComponent is used by ComponentManagerRule and methods annotated with it are called before other components are registered (ie before processing of @AllComponents and @ComponentList annotations).

      MockitoComponentManagerRule extends ComponentManagerRule and just adds some helper methods to register a mock component.

      Attachments

        Issue Links

          Activity

            People

              vmassol Vincent Massol
              vmassol Vincent Massol
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: