Merge "FakeFeatureFlagsImpl optionally takes defaults via a FeatureFlags." into main am: 80c40c4d91
am: 6e52bccbe7
Original change: https://android-review.googlesource.com/c/platform/build/+/3062045 Change-Id: I58b62c69636c337d661ccc09921daa7fb0ad85d6 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -428,10 +428,16 @@ mod tests {
|
|||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public class FakeFeatureFlagsImpl extends CustomFeatureFlags {
|
public class FakeFeatureFlagsImpl extends CustomFeatureFlags {
|
||||||
private Map<String, Boolean> mFlagMap = new HashMap<>();
|
private final Map<String, Boolean> mFlagMap = new HashMap<>();
|
||||||
|
private final FeatureFlags mDefaults;
|
||||||
|
|
||||||
public FakeFeatureFlagsImpl() {
|
public FakeFeatureFlagsImpl() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeFeatureFlagsImpl(FeatureFlags defaults) {
|
||||||
super(null);
|
super(null);
|
||||||
|
mDefaults = defaults;
|
||||||
// Initialize the map with null values
|
// Initialize the map with null values
|
||||||
for (String flagName : getFlagNames()) {
|
for (String flagName : getFlagNames()) {
|
||||||
mFlagMap.put(flagName, null);
|
mFlagMap.put(flagName, null);
|
||||||
@@ -441,10 +447,13 @@ mod tests {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean getValue(String flagName, Predicate<FeatureFlags> getter) {
|
protected boolean getValue(String flagName, Predicate<FeatureFlags> getter) {
|
||||||
Boolean value = this.mFlagMap.get(flagName);
|
Boolean value = this.mFlagMap.get(flagName);
|
||||||
if (value == null) {
|
if (value != null) {
|
||||||
throw new IllegalArgumentException(flagName + " is not set");
|
return value;
|
||||||
}
|
}
|
||||||
return value;
|
if (mDefaults != null) {
|
||||||
|
return getter.test(mDefaults);
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException(flagName + " is not set");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFlag(String flagName, boolean value) {
|
public void setFlag(String flagName, boolean value) {
|
||||||
|
@@ -6,10 +6,16 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public class FakeFeatureFlagsImpl extends CustomFeatureFlags \{
|
public class FakeFeatureFlagsImpl extends CustomFeatureFlags \{
|
||||||
private Map<String, Boolean> mFlagMap = new HashMap<>();
|
private final Map<String, Boolean> mFlagMap = new HashMap<>();
|
||||||
|
private final FeatureFlags mDefaults;
|
||||||
|
|
||||||
public FakeFeatureFlagsImpl() \{
|
public FakeFeatureFlagsImpl() \{
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeFeatureFlagsImpl(FeatureFlags defaults) \{
|
||||||
super(null);
|
super(null);
|
||||||
|
mDefaults = defaults;
|
||||||
// Initialize the map with null values
|
// Initialize the map with null values
|
||||||
for (String flagName : getFlagNames()) \{
|
for (String flagName : getFlagNames()) \{
|
||||||
mFlagMap.put(flagName, null);
|
mFlagMap.put(flagName, null);
|
||||||
@@ -19,10 +25,13 @@ public class FakeFeatureFlagsImpl extends CustomFeatureFlags \{
|
|||||||
@Override
|
@Override
|
||||||
protected boolean getValue(String flagName, Predicate<FeatureFlags> getter) \{
|
protected boolean getValue(String flagName, Predicate<FeatureFlags> getter) \{
|
||||||
Boolean value = this.mFlagMap.get(flagName);
|
Boolean value = this.mFlagMap.get(flagName);
|
||||||
if (value == null) \{
|
if (value != null) \{
|
||||||
throw new IllegalArgumentException(flagName + " is not set");
|
return value;
|
||||||
}
|
}
|
||||||
return value;
|
if (mDefaults != null) \{
|
||||||
|
return getter.test(mDefaults);
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException(flagName + " is not set");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFlag(String flagName, boolean value) \{
|
public void setFlag(String flagName, boolean value) \{
|
||||||
|
Reference in New Issue
Block a user