ninja icon indicating copy to clipboard operation
ninja copied to clipboard

MockNinjaProperties do not handle default values

Open christiangroth opened this issue 6 years ago • 1 comments

Default values in methods getWithDefault, getIntegerWithDefault and getBooleanWithDefault are not implemented correctly. If the value is not present, null is returned and not the default. If the value is present, the default is returned and not the configured / mocked value.

Code snip:

@Override
public String getWithDefault(String key, String defaultValue) {
        String value = get(key);
        if (value == null) {
            return null;
        } else {
            return defaultValue;
        }
}

@Override
public Integer getIntegerWithDefault(String key, Integer defaultValue) {
        Integer value = getInteger(key);
        if (value == null) {
            return null;
        } else {
            return defaultValue;
        }
}

@Override
public Boolean getBooleanWithDefault(String key, Boolean defaultValue) {
        Boolean value = getBoolean(key);
        if (value == null) {
            return null;
        } else {
            return defaultValue;
        }
} 

I'm using version 6.4.0. If this is somewhat intended behavior, then it would be good to have javadocs pointing to this.

christiangroth avatar Nov 19 '18 20:11 christiangroth

I just stumbled upon this as well.. can anyone fix this please? Happy to create the MR, but it would probably be faster if the author (@raphaelbauer) just copy/pates the code form the NinjaPropertiesImpl class (or changes == null to != null)

davidgiga1993 avatar Jun 01 '22 12:06 davidgiga1993