Class TestFeatureManager
java.lang.Object
cloud.opencode.base.feature.testing.TestFeatureManager
- All Implemented Interfaces:
AutoCloseable
Test Feature Manager
测试功能管理器
Convenience class for managing features in tests.
用于在测试中管理功能的便捷类。
Features | 主要功能:
- Simple feature registration - 简单功能注册
- Enable/disable all features - 启用/禁用所有功能
- AutoCloseable for try-with-resources - 支持AutoCloseable以使用try-with-resources
- Delegates to OpenFeature - 委托给OpenFeature
Usage Examples | 使用示例:
try (TestFeatureManager manager = new TestFeatureManager()) {
manager.withFeature("dark-mode", true)
.withFeature("beta-feature", false);
assertTrue(manager.isEnabled("dark-mode"));
assertFalse(manager.isEnabled("beta-feature"));
}
Security | 安全性:
- Thread-safe: Yes (delegates to thread-safe OpenFeature) - 线程安全: 是(委托给线程安全的OpenFeature)
- Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
- Since:
- JDK 25, opencode-base-feature V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close and clear all features 关闭并清除所有功能voidDisable a feature, registering it if it does not exist 禁用功能,如果不存在则注册voidDisable all registered features 禁用所有已注册的功能voidEnable a feature, registering it if it does not exist 启用功能,如果不存在则注册voidEnable all registered features 启用所有已注册的功能Get the underlying OpenFeature delegate 获取底层OpenFeature委托booleanCheck if a feature is enabled 检查功能是否启用booleanisEnabled(String key, FeatureContext context) Check if a feature is enabled with context 使用上下文检查功能是否启用withFeature(Feature feature) Register a feature with full definition 使用完整定义注册功能withFeature(String key, boolean enabled) Register a feature as enabled or disabled 将功能注册为启用或禁用
-
Constructor Details
-
TestFeatureManager
public TestFeatureManager()Create a new test feature manager 创建新的测试功能管理器
-
-
Method Details
-
withFeature
Register a feature as enabled or disabled 将功能注册为启用或禁用- Parameters:
key- the feature key | 功能键enabled- whether the feature is enabled | 功能是否启用- Returns:
- this manager for fluent API | 此管理器以支持流式API
-
withFeature
Register a feature with full definition 使用完整定义注册功能- Parameters:
feature- the feature | 功能- Returns:
- this manager for fluent API | 此管理器以支持流式API
-
enable
Enable a feature, registering it if it does not exist 启用功能,如果不存在则注册- Parameters:
key- the feature key | 功能键
-
disable
Disable a feature, registering it if it does not exist 禁用功能,如果不存在则注册- Parameters:
key- the feature key | 功能键
-
enableAll
public void enableAll()Enable all registered features 启用所有已注册的功能 -
disableAll
public void disableAll()Disable all registered features 禁用所有已注册的功能 -
isEnabled
Check if a feature is enabled 检查功能是否启用- Parameters:
key- the feature key | 功能键- Returns:
- true if enabled | 如果启用返回true
-
isEnabled
Check if a feature is enabled with context 使用上下文检查功能是否启用- Parameters:
key- the feature key | 功能键context- the evaluation context | 评估上下文- Returns:
- true if enabled | 如果启用返回true
-
getDelegate
Get the underlying OpenFeature delegate 获取底层OpenFeature委托- Returns:
- the delegate | 委托
-
close
public void close()Close and clear all features 关闭并清除所有功能- Specified by:
closein interfaceAutoCloseable
-