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

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

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

import java.util.function.Supplier;

public class ConfigOverride {

    public static final String DEFAULT_PREFIX = "dw.";
    private final String key;
    private final Supplier value;
    private final String propertyPrefix;

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

    public static ConfigOverride config(String key, String value) {
        return new ConfigOverride(DEFAULT_PREFIX, key, () -> value);
    }

    public static ConfigOverride config(String propertyPrefix, String key, String value) {
        return new ConfigOverride(propertyPrefix, key, () -> value);
    }

    public static ConfigOverride config(String key, Supplier value) {
        return new ConfigOverride(DEFAULT_PREFIX, key, value);
    }

    public static ConfigOverride config(String propertyPrefix, String key, Supplier value) {
        return new ConfigOverride(propertyPrefix, key, value);
    }

    public void addToSystemProperties() {
        System.setProperty(propertyPrefix + key, value.get());
    }

    public void removeFromSystemProperties() {
        System.clearProperty(propertyPrefix + key);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy