This change will generate full fakefeatureflagsimpl in prod mode. FakeFeatureFlagsImp will be the same in test mode and the prod mode. FeatureFlagsImpl will be all unimplemented in test mode. setFlag, resetAll are added into the interface FeatureFlags. The reason to make this change is for project using injection pattern, the project doesn't have to use test mode to test the flag guarded code. The project can directly use the FakeFeatureFlagsImpl for testing. Bug: 294838180 Test: atest AconfigJavaHostTest --host AND atest aconfig.test.java Change-Id: Ib6d40fd3a9ef872e01594fd4f8d6c4cb10bb173a
46 lines
1.2 KiB
Plaintext
46 lines
1.2 KiB
Plaintext
package {package_name};
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class FakeFeatureFlagsImpl implements FeatureFlags \{
|
|
public FakeFeatureFlagsImpl() \{
|
|
resetAll();
|
|
}
|
|
|
|
{{ for item in class_elements}}
|
|
@Override
|
|
public boolean {item.method_name}() \{
|
|
return getFlag(Flags.FLAG_{item.flag_name_constant_suffix});
|
|
}
|
|
{{ endfor}}
|
|
public void setFlag(String flagName, boolean value) \{
|
|
if (!this.mFlagMap.containsKey(flagName)) \{
|
|
throw new IllegalArgumentException("no such flag " + flagName);
|
|
}
|
|
this.mFlagMap.put(flagName, value);
|
|
}
|
|
|
|
public void resetAll() \{
|
|
for (Map.Entry entry : mFlagMap.entrySet()) \{
|
|
entry.setValue(null);
|
|
}
|
|
}
|
|
|
|
private boolean getFlag(String flagName) \{
|
|
Boolean value = this.mFlagMap.get(flagName);
|
|
if (value == null) \{
|
|
throw new IllegalArgumentException(flagName + " is not set");
|
|
}
|
|
return value;
|
|
}
|
|
|
|
private Map<String, Boolean> mFlagMap = new HashMap<>(
|
|
Map.of(
|
|
{{-for item in class_elements}}
|
|
Flags.FLAG_{item.flag_name_constant_suffix}, false{{ if not @last }},{{ endif }}
|
|
{{ -endfor }}
|
|
)
|
|
);
|
|
}
|