### Question:
UserPrefSubstituter implements Substituter { public void addSubstitutions(Substitutions substituter, GadgetContext context, GadgetSpec spec) { UserPrefs values = context.getUserPrefs(); for (UserPref pref : spec.getUserPrefs().values()) { String name = pref.getName(); String value = values.getPref(name); if (value == null) { value = pref.getDefaultValue(); if (value == null) { value = ""; } } substituter.addSubstitution(Substitutions.Type.USER_PREF, name, StringEscapeUtils .escapeHtml4(value)); } }  void addSubstitutions(Substitutions substituter, GadgetContext context, GadgetSpec spec);  }### Answer:
@Test public void testSubstitutions() throws Exception { Map<String, String> map = ImmutableMap.of(USER_NAME, USER_VALUE, OVERRIDE_NAME, OVERRIDE_VALUE); final UserPrefs prefs = new UserPrefs(map); GadgetContext context = new GadgetContext() { @Override public UserPrefs getUserPrefs() { return prefs; } }; new UserPrefSubstituter().addSubstitutions(substituter, context, spec); assertEquals(DEFAULT_VALUE, substituter.getSubstitution(Type.USER_PREF, DEFAULT_NAME)); assertEquals(USER_VALUE, substituter.getSubstitution(Type.USER_PREF, USER_NAME)); assertEquals(OVERRIDE_VALUE, substituter.getSubstitution(Type.USER_PREF, OVERRIDE_NAME)); }
@Test public void testEscaping() throws Exception { Map<String, String> map = ImmutableMap.of(USER_NAME, UNESCAPED_USER_VALUE); final UserPrefs prefs = new UserPrefs(map); GadgetContext context = new GadgetContext() { @Override public UserPrefs getUserPrefs() { return prefs; } }; new UserPrefSubstituter().addSubstitutions(substituter, context, spec); assertEquals(ESCAPED_USER_VALUE, substituter.getSubstitution(Type.USER_PREF, USER_NAME)); }