All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.testing.ConfigOverrideValue Maven / Gradle / Ivy

There is a newer version: 5.0.0-alpha.4
Show newest version
package io.dropwizard.testing;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.function.Supplier;

public class ConfigOverrideValue extends ConfigOverride {

    private final String key;
    private final Supplier value;
    private final String propertyPrefix;
    @Nullable
    private String originalValue = null;

    ConfigOverrideValue(String propertyPrefix, String key, Supplier value) {
        this.key = key;
        this.value = value;
        this.propertyPrefix = propertyPrefix.endsWith(".") ? propertyPrefix : propertyPrefix + ".";
    }

    @Override
    public void addToSystemProperties() {
        this.originalValue = System.setProperty(propertyPrefix + key, value.get());
    }

    @Override
    public void removeFromSystemProperties() {
        if (originalValue != null) {
            System.setProperty(propertyPrefix + key, originalValue);
        } else {
            System.clearProperty(propertyPrefix + key);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy