### Question:
GadgetELResolver extends ELResolver { @Override public Object getValue(ELContext context, Object base, Object property) { if (base == null) { if (VIEW_PARAMS_PROPERTY.equals(property)) { context.setPropertyResolved(true); String params = gadgetContext.getParameter("view-params"); if (params != null && !"".equals(params)) { try { return new JSONObject(params); } catch (JSONException e) { throw new ELException(e); } } return ImmutableMap.of(); } else if (USER_PREFS_PROPERTY.equals(property)) { context.setPropertyResolved(true); return gadgetContext.getUserPrefs().getPrefs(); } } return null; } GadgetELResolver(GadgetContext context); @Override Class<?> getCommonPropertyType(ELContext context, Object base); @Override Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
      Object base); @Override Class<?> getType(ELContext context, Object base, Object property); @Override Object getValue(ELContext context, Object base, Object property); @Override boolean isReadOnly(ELContext context, Object base, Object property); @Override void setValue(ELContext context, Object base, Object property, Object value); static final String USER_PREFS_PROPERTY; static final String VIEW_PARAMS_PROPERTY; }### Answer:
@Test public void getPrefs() { userPrefs = new UserPrefs(ImmutableMap.of("foo", "bar")); ValueExpression expression = expressions.parse("${UserPrefs.foo}", String.class); assertEquals("bar", expression.getValue(context)); expression = expressions.parse("${UserPrefs.wrongKey}", String.class); assertEquals("", expression.getValue(context)); }
@Test public void getPrefsEmpty() { userPrefs = UserPrefs.EMPTY; ValueExpression expression = expressions.parse("${UserPrefs.foo}", String.class); assertEquals("", expression.getValue(context)); }
@Test public void testViewParams() { viewParams = "{foo: 'bar'}"; ValueExpression expression = expressions.parse("${ViewParams.foo}", String.class); assertEquals("bar", expression.getValue(context)); expression = expressions.parse("${ViewParams.wrongKey}", String.class); assertEquals("", expression.getValue(context)); }
@Test public void testViewParamsEmpty() { ValueExpression expression = expressions.parse("${ViewParams.foo}", String.class); assertEquals("", expression.getValue(context)); }