@Test public void invokeArrayLengthMethod() throws PropertyAccessException { Person peter = new Person("Peter"); String[] foreNames = new String[] { "Klaus", "Uwe" }; peter.setForeNames(foreNames); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("foreNames"); start.setPathToContinue(path); PropertyPath path2 = new PropertyPath(); path2.setName("length()"); path.setPathToContinue(path2); String result = propertyAccessor.getPropertyContent(start, peter, null, resultValueMock, false); assertThat(Integer.parseInt(result), is(2)); Mockito.verifyZeroInteractions(resultValueMock); }
@Override public String getPropertyContent(PropertyPathStart propertyPathStart, Object clazz, Object[] parameters, Object returnValue, boolean exception) throws PropertyAccessException { if (null == propertyPathStart) { throw new PropertyAccessException("Property path start cannot be null!"); } if (null == propertyPathStart.getContentType()) { throw new PropertyAccessException("Content type is not defined."); } switch (propertyPathStart.getContentType()) { case FIELD: if (null == clazz) { throw new PropertyAccessException("Class reference cannot be null!"); } return getPropertyContent(propertyPathStart.getPathToContinue(), clazz); case PARAM: if (null == parameters) { throw new PropertyAccessException("Parameter array reference cannot be null!"); } if (propertyPathStart.getSignaturePosition() >= parameters.length) { throw new PropertyAccessException("Signature position out of range!"); } return getPropertyContent(propertyPathStart.getPathToContinue(), parameters[propertyPathStart.getSignaturePosition()]); case RETURN: if (exception) { return NA; } else if (null == returnValue) { return NULL_VALUE; } else { return getPropertyContent(propertyPathStart.getPathToContinue(), returnValue); } default: throw new PropertyAccessException("Missing handler for type " + propertyPathStart.getContentType()); } }
PropertyAccessor implements IPropertyAccessor { @Override public String getPropertyContent(PropertyPathStart propertyPathStart, Object clazz, Object[] parameters, Object returnValue, boolean exception) throws PropertyAccessException { if (null == propertyPathStart) { throw new PropertyAccessException("Property path start cannot be null!"); } if (null == propertyPathStart.getContentType()) { throw new PropertyAccessException("Content type is not defined."); } switch (propertyPathStart.getContentType()) { case FIELD: if (null == clazz) { throw new PropertyAccessException("Class reference cannot be null!"); } return getPropertyContent(propertyPathStart.getPathToContinue(), clazz); case PARAM: if (null == parameters) { throw new PropertyAccessException("Parameter array reference cannot be null!"); } if (propertyPathStart.getSignaturePosition() >= parameters.length) { throw new PropertyAccessException("Signature position out of range!"); } return getPropertyContent(propertyPathStart.getPathToContinue(), parameters[propertyPathStart.getSignaturePosition()]); case RETURN: if (exception) { return NA; } else if (null == returnValue) { return NULL_VALUE; } else { return getPropertyContent(propertyPathStart.getPathToContinue(), returnValue); } default: throw new PropertyAccessException("Missing handler for type " + propertyPathStart.getContentType()); } } }
PropertyAccessor implements IPropertyAccessor { @Override public String getPropertyContent(PropertyPathStart propertyPathStart, Object clazz, Object[] parameters, Object returnValue, boolean exception) throws PropertyAccessException { if (null == propertyPathStart) { throw new PropertyAccessException("Property path start cannot be null!"); } if (null == propertyPathStart.getContentType()) { throw new PropertyAccessException("Content type is not defined."); } switch (propertyPathStart.getContentType()) { case FIELD: if (null == clazz) { throw new PropertyAccessException("Class reference cannot be null!"); } return getPropertyContent(propertyPathStart.getPathToContinue(), clazz); case PARAM: if (null == parameters) { throw new PropertyAccessException("Parameter array reference cannot be null!"); } if (propertyPathStart.getSignaturePosition() >= parameters.length) { throw new PropertyAccessException("Signature position out of range!"); } return getPropertyContent(propertyPathStart.getPathToContinue(), parameters[propertyPathStart.getSignaturePosition()]); case RETURN: if (exception) { return NA; } else if (null == returnValue) { return NULL_VALUE; } else { return getPropertyContent(propertyPathStart.getPathToContinue(), returnValue); } default: throw new PropertyAccessException("Missing handler for type " + propertyPathStart.getContentType()); } }  }
PropertyAccessor implements IPropertyAccessor { @Override public String getPropertyContent(PropertyPathStart propertyPathStart, Object clazz, Object[] parameters, Object returnValue, boolean exception) throws PropertyAccessException { if (null == propertyPathStart) { throw new PropertyAccessException("Property path start cannot be null!"); } if (null == propertyPathStart.getContentType()) { throw new PropertyAccessException("Content type is not defined."); } switch (propertyPathStart.getContentType()) { case FIELD: if (null == clazz) { throw new PropertyAccessException("Class reference cannot be null!"); } return getPropertyContent(propertyPathStart.getPathToContinue(), clazz); case PARAM: if (null == parameters) { throw new PropertyAccessException("Parameter array reference cannot be null!"); } if (propertyPathStart.getSignaturePosition() >= parameters.length) { throw new PropertyAccessException("Signature position out of range!"); } return getPropertyContent(propertyPathStart.getPathToContinue(), parameters[propertyPathStart.getSignaturePosition()]); case RETURN: if (exception) { return NA; } else if (null == returnValue) { return NULL_VALUE; } else { return getPropertyContent(propertyPathStart.getPathToContinue(), returnValue); } default: throw new PropertyAccessException("Missing handler for type " + propertyPathStart.getContentType()); } }  @Override String getPropertyContent(PropertyPathStart propertyPathStart, Object clazz, Object[] parameters, Object returnValue, boolean exception); @Override List<ParameterContentData> getParameterContentData(List<PropertyPathStart> propertyAccessorList, Object clazz, Object[] parameters, Object returnValue, boolean exception); }
PropertyAccessor implements IPropertyAccessor { @Override public String getPropertyContent(PropertyPathStart propertyPathStart, Object clazz, Object[] parameters, Object returnValue, boolean exception) throws PropertyAccessException { if (null == propertyPathStart) { throw new PropertyAccessException("Property path start cannot be null!"); } if (null == propertyPathStart.getContentType()) { throw new PropertyAccessException("Content type is not defined."); } switch (propertyPathStart.getContentType()) { case FIELD: if (null == clazz) { throw new PropertyAccessException("Class reference cannot be null!"); } return getPropertyContent(propertyPathStart.getPathToContinue(), clazz); case PARAM: if (null == parameters) { throw new PropertyAccessException("Parameter array reference cannot be null!"); } if (propertyPathStart.getSignaturePosition() >= parameters.length) { throw new PropertyAccessException("Signature position out of range!"); } return getPropertyContent(propertyPathStart.getPathToContinue(), parameters[propertyPathStart.getSignaturePosition()]); case RETURN: if (exception) { return NA; } else if (null == returnValue) { return NULL_VALUE; } else { return getPropertyContent(propertyPathStart.getPathToContinue(), returnValue); } default: throw new PropertyAccessException("Missing handler for type " + propertyPathStart.getContentType()); } }  @Override String getPropertyContent(PropertyPathStart propertyPathStart, Object clazz, Object[] parameters, Object returnValue, boolean exception); @Override List<ParameterContentData> getParameterContentData(List<PropertyPathStart> propertyAccessorList, Object clazz, Object[] parameters, Object returnValue, boolean exception);  }