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

nl.hsac.fitnesse.fixture.slim.SlimFixtureWithMapHelper Maven / Gradle / Ivy

There is a newer version: 5.3.17
Show newest version
package nl.hsac.fitnesse.fixture.slim;

import nl.hsac.fitnesse.fixture.util.MapHelper;

import java.util.Map;

/**
 * Slim fixture base class allowing values to be set to a Map.
 */
public class SlimFixtureWithMapHelper extends SlimFixture {
    private MapHelper mapHelper;

    public SlimFixtureWithMapHelper() {
        expandPeriodsInNamesToNestedMaps(true);
    }

    public void expandPeriodsInNamesToNestedMaps(boolean expand) {
        MapHelper newMapHelper;
        if (expand) {
            newMapHelper = getDefaultMapHelper();
        } else {
            newMapHelper = new NoOpMapHelper();
        }
        setMapHelper(newMapHelper);
    }

    public boolean expandsPeriodsInNamesToNestedMaps() {
        return !(getMapHelper() instanceof NoOpMapHelper);
    }

    /**
     * @return helper to assist getting/setting (nested) values in a map.
     */
    public MapHelper getMapHelper() {
        return mapHelper;
    }

    /**
     * @param mapHelper helper to assist getting/setting (nested) values in a map.
     */
    public void setMapHelper(MapHelper mapHelper) {
        this.mapHelper = mapHelper;
    }

    protected MapHelper getDefaultMapHelper() {
        return getEnvironment().getMapHelper();
    }

    /**
     * Map helper that does not interpret periods in names to mean nested maps.
     */
    private static class NoOpMapHelper extends MapHelper {
        @Override
        public void setValueForIn(Object value, String name, Map map) {
            map.put(name, value);
        }

        @Override
        public boolean removeFrom(String key, Map map) {
            boolean result = map.containsKey(key);
            map.remove(key);
            return result;
        }

        @Override
        public Object getValue(Map map, String name) {
            String cleanName = htmlCleaner.cleanupValue(name);
            return map.get(cleanName);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy