001package de.cuioss.test.jsf.mocks;
002
003import static de.cuioss.tools.collect.CollectionLiterals.mutableMap;
004
005import java.util.Map;
006
007import javax.faces.component.UIComponent;
008import javax.faces.component.UIViewRoot;
009
010/**
011 * Mock variant of {@link UIViewRoot} providing a heloer for adding a
012 * {@link UIComponent} at runtime
013 *
014 * @author Oliver Wolff
015 *
016 */
017public class CuiMockUIViewRoot extends UIViewRoot {
018
019    private final Map<String, UIComponent> componentMap = mutableMap();
020
021    /**
022     * @param expr      must not be null
023     * @param component must not be null
024     */
025    public void addUiComponent(String expr, UIComponent component) {
026        componentMap.put(expr, component);
027    }
028
029    @Override
030    public UIComponent findComponent(String expr) {
031        if (componentMap.containsKey(expr)) {
032            return componentMap.get(expr);
033        }
034        return super.findComponent(expr);
035    }
036}