@SuppressWarnings("unchecked") @Test public void testGetProperty() { Request request = createMock(Request.class); Map<String, Object> oneScope = createMock(Map.class); Map<String, Object> twoScope = createMock(Map.class); expect(request.getAvailableScopes()).andReturn(Arrays.asList(new String[] {"one", "two"})).anyTimes(); expect(request.getContext("one")).andReturn(oneScope).anyTimes(); expect(request.getContext("two")).andReturn(twoScope).anyTimes(); expect(oneScope.containsKey("name1")).andReturn(true); expect(oneScope.get("name1")).andReturn("value1"); expect(oneScope.containsKey("name2")).andReturn(false); expect(oneScope.containsKey("name3")).andReturn(false); expect(twoScope.containsKey("name2")).andReturn(true); expect(twoScope.get("name2")).andReturn("value2"); expect(twoScope.containsKey("name3")).andReturn(false); replay(request, oneScope, twoScope); assertEquals("value1", accessor.getProperty(null, request, "name1")); assertEquals("value2", accessor.getProperty(null, request, "name2")); assertNull(accessor.getProperty(null, request, "name3")); verify(request, oneScope, twoScope); }
@Override public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) { Request request = (Request) target; String attributeName = (String) name; for (String scopeName : request.getAvailableScopes()) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return scope.get(attributeName); } } return null; }
AnyScopePropertyAccessor implements PropertyAccessor { @Override public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) { Request request = (Request) target; String attributeName = (String) name; for (String scopeName : request.getAvailableScopes()) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return scope.get(attributeName); } } return null; } }
AnyScopePropertyAccessor implements PropertyAccessor { @Override public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) { Request request = (Request) target; String attributeName = (String) name; for (String scopeName : request.getAvailableScopes()) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return scope.get(attributeName); } } return null; }  }
AnyScopePropertyAccessor implements PropertyAccessor { @Override public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) { Request request = (Request) target; String attributeName = (String) name; for (String scopeName : request.getAvailableScopes()) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return scope.get(attributeName); } } return null; }  @Override Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name); @Override String getSourceAccessor(OgnlContext context, Object target,
            Object index); @Override String getSourceSetter(OgnlContext context, Object target,
            Object index); @Override void setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name,
            Object value); }
AnyScopePropertyAccessor implements PropertyAccessor { @Override public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) { Request request = (Request) target; String attributeName = (String) name; for (String scopeName : request.getAvailableScopes()) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return scope.get(attributeName); } } return null; }  @Override Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name); @Override String getSourceAccessor(OgnlContext context, Object target,
            Object index); @Override String getSourceSetter(OgnlContext context, Object target,
            Object index); @Override void setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name,
            Object value);  }