Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 80c40c4d authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "FakeFeatureFlagsImpl optionally takes defaults via a FeatureFlags." into main

parents d4758185 23fbd1e2
Loading
Loading
Loading
Loading
+13 −4
Original line number Original line Diff line number Diff line
@@ -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,11 +447,14 @@ 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) {
            if (!this.mFlagMap.containsKey(flagName)) {
            if (!this.mFlagMap.containsKey(flagName)) {
+13 −4
Original line number Original line Diff line number Diff line
@@ -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,11 +25,14 @@ 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) \{
        if (!this.mFlagMap.containsKey(flagName)) \{
        if (!this.mFlagMap.containsKey(flagName)) \{