VariableScopeElResolver extends ELResolver { @Override public Object getValue(ELContext context, Object base, Object property) { if (base == null) { String variable = (String) property; for (VariableScopeItemELResolver variableScopeItemELResolver : getVariableScopeItemELResolvers()) { if (variableScopeItemELResolver.canResolve(variable, variableScope)) { context.setPropertyResolved(true); return variableScopeItemELResolver.resolve(variable, variableScope); } } } return null; } VariableScopeElResolver(VariableScope variableScope); @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); @Override Class<?> getCommonPropertyType(ELContext arg0, Object arg1); @Override Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext arg0, Object arg1); @Override Class<?> getType(ELContext arg0, Object arg1, Object arg2);  }
@Test public void getValue_should_returnResolvedValueAndMarkContextAsResolved() { String property = "myVar"; ELContext elContext = mock(ELContext.class); given(firstItemResolver.canResolve(property, variableScope)).willReturn(false); given(secondItemResolver.canResolve(property, variableScope)).willReturn(true); given(secondItemResolver.resolve(property, variableScope)).willReturn("myValue"); Object result = variableScopeElResolver.getValue(elContext, null, property); assertThat(result).isEqualTo("myValue"); verify(elContext).setPropertyResolved(true); verifyZeroInteractions(thirdItemResolver); }
@Test public void getValue_should_returnNullWhenNoneOfItemResolversCanResolveTheProperty() { String property = "myVar"; ELContext elContext = mock(ELContext.class); given(firstItemResolver.canResolve(property, variableScope)).willReturn(false); given(secondItemResolver.canResolve(property, variableScope)).willReturn(false); given(secondItemResolver.canResolve(property, variableScope)).willReturn(false); Object result = variableScopeElResolver.getValue(elContext, null, property); assertThat(result).isNull(); verifyZeroInteractions(elContext); }