AttributeDescriptor { public Object read(Object target, ExecutionContext executionContext) throws NameNotFoundException, QueryInvocationTargetException { if (target == null || target == QueryService.UNDEFINED) { return QueryService.UNDEFINED; } if (target instanceof InternalPdxInstance) { return readPdx((InternalPdxInstance) target, executionContext); } return readReflection(target, executionContext); } AttributeDescriptor(TypeRegistry pdxRegistry, String name); boolean validateReadType(Class targetType); Object read(Object target, ExecutionContext executionContext);  }
@Test public void readShouldReturnUndefinedForNullOrUndefinedTargetObject() throws NameNotFoundException, QueryInvocationTargetException { AttributeDescriptor attributeDescriptor = new AttributeDescriptor(typeRegistry, "whatever"); assertThat(attributeDescriptor.read(null, queryExecutionContext)) .isEqualTo(QueryService.UNDEFINED); assertThat(attributeDescriptor.read(QueryService.UNDEFINED, queryExecutionContext)) .isEqualTo(QueryService.UNDEFINED); }
@Test @Parameters({PUBLIC_NO_ACCESSORS, PUBLIC_ACCESSOR_BY_NAME, PUBLIC_ACCESSOR_BY_GETTER, PRIVATE_ACCESSOR_BY_NAME, PRIVATE_ACCESSOR_BY_GETTER}) public void readShouldReturnCorrectlyForAccessibleAuthorizedNonPdxMembers(String attributeName) throws NameNotFoundException, QueryInvocationTargetException { doReturn(true).when(methodInvocationAuthorizer).authorize(any(), any()); AttributeDescriptor attributeDescriptor = new AttributeDescriptor(typeRegistry, attributeName); Object result = attributeDescriptor.read(testBean, queryExecutionContext); assertThat(result).isInstanceOf(String.class); assertThat(result).isEqualTo(attributeName); }