Class SettingBundleStub
- java.lang.Object
-
- org.silverpeas.core.test.extention.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 theSettingBundle
in unit tests.- Author:
- silveryocha
-
-
Constructor Summary
Constructors Constructor Description SettingBundleStub(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
void
beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
protected void
clear()
SettingBundleStub
put(String key, String value)
Puts a couple key / value.SettingBundleStub
removeAll()
Removes all registered keys.
-
-
-
Constructor Detail
-
SettingBundleStub
public SettingBundleStub(Class<?> cls, String fieldName) throws IllegalAccessException
- 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(SettingBundle)
-
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 interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
- Throws:
Exception
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
- Specified by:
afterEach
in interfaceorg.junit.jupiter.api.extension.AfterEachCallback
- Throws:
Exception
-
clear
protected void clear() throws IllegalAccessException
- Throws:
IllegalAccessException
-
-