AnyScopePropertyAccessor implements PropertyAccessor { @Override public void setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name, Object value) { Request request = (Request) target; String attributeName = (String) name; String[] availableScopes = request.getAvailableScopes().toArray(new String[0]); for (String scopeName : availableScopes) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { scope.put(attributeName, value); return; } } if (availableScopes.length > 0) { request.getContext(availableScopes[0]).put(attributeName, value); } }  @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);  }
@SuppressWarnings("unchecked") @Test public void testSetProperty() { 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.put("name1", "otherValue1")).andReturn("value1"); expect(oneScope.containsKey("name2")).andReturn(false); expect(oneScope.containsKey("name3")).andReturn(false); expect(twoScope.containsKey("name2")).andReturn(true); expect(twoScope.put("name2", "otherValue2")).andReturn("value2"); expect(twoScope.containsKey("name3")).andReturn(false); expect(oneScope.put("name3", "otherValue3")).andReturn(null); replay(request, oneScope, twoScope); accessor.setProperty(null, request, "name1", "otherValue1"); accessor.setProperty(null, request, "name2", "otherValue2"); accessor.setProperty(null, request, "name3", "otherValue3"); verify(request, oneScope, twoScope); }