Class SettingBundleStub

  • All Implemented Interfaces:
    org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension

    public class SettingBundleStub
    extends Object
    implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback
    Provides easy stubbing on the SettingBundle in unit tests.
    Author:
    silveryocha
    • Constructor Detail

      • SettingBundleStub

        public SettingBundleStub​(SettingBundle settingBundle)
        Initializing the setting bundled by this way means that the setting could have already been accessed by another class or instance and the setting bundle instance is registered into a static attribute or an attribute that will be shared between all tests.

        It is not mandatory to the caller to fill all the keys if a default property file has been registered into context. The given keys just overrides the default one.
        If a null value is returned by the stub for a key, then it is looking for the key into the default property file.

        Parameters:
        settingBundle - the setting bundle to stub.
      • SettingBundleStub

        public SettingBundleStub​(String bundleName)
        Initializing the setting bundle by this way means that unit or integration test is looking for bundle registry at each test.

        In other words, the setting bundle MUST not be a static attribute (or an attribute) that will be shared between each test.

        The caller MUST register all the needed keys because there is no fallback onto a default property file.

        Parameters:
        bundleName - the bundle name to stub.
    • Method Detail

      • put

        public SettingBundleStub put​(String key,
                                     String value)
        Puts a couple key / value.
        Parameters:
        key - the key.
        value - the value.
        Returns:
        itself.
      • removeAll

        public SettingBundleStub removeAll()
        Removes all registered keys.
        Returns:
        itself.
      • beforeEach

        public void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext context)
                        throws Exception
        Specified by:
        beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
        Throws:
        Exception
      • afterEach

        public void afterEach​(org.junit.jupiter.api.extension.ExtensionContext context)
                       throws Exception
        Specified by:
        afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
        Throws:
        Exception