Class SettingBundleStub
java.lang.Object
org.silverpeas.kernel.test.extension.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. This class is to declare as a
field of the unit test class a SettingBundle that will be used by the tests and with
which some settings can be preconfigured or modified without having to use a set of physical
properties files (a SettingBundle is mapped to a properties file). By annotating the
field with the RegisterExtension annotation, the required
resources initialization is performed before the execution of a unit test and the resource
cleanup is applied once the unit test resumed.- Author:
- silveryocha
-
Constructor Summary
ConstructorsConstructorDescriptionSettingBundleStub(Class<?> cls, String fieldName) SettingBundleStub(String bundleName) Initializing the setting bundle by this way means that unit or integration test is looking for bundle registry at each test.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. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterEach(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) protected voidclear()Puts a couple key / value.Removes all registered keys.
-
Constructor Details
-
SettingBundleStub
- Parameters:
cls- the static class containing the setting attribute.fieldName- the name of setting attribute.- Throws:
IllegalAccessException- if the setting attribute can not be manipulated.- See Also:
-
SettingBundleStub
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
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 Details
-
put
Puts a couple key / value.- Parameters:
key- the key.value- the value.- Returns:
- itself.
-
removeAll
Removes all registered keys.- Returns:
- itself.
-
beforeEach
- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Throws:
Exception
-
afterEach
- Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback- Throws:
Exception
-
clear
- Throws:
IllegalAccessException
-