targets = new ArrayList<Object>(targetNames.length); for (String targetName : targetNames) { Field field = getFieldWithName(test.getClass(), targetName, false); if (field == null) { throw new UnitilsException(getSituatedErrorMessage(annotationClass, annotatedField, "Target with name " + targetNames + " does not exist"));
/** * Sets the given value on the static property of the given targetClass * * @param targetClass The class on which the static property value should be set * @param staticProperty The name of the property (simple name, not a composite expression) * @param value The value to set */ private static void setValueStatic(Class<?> targetClass, String staticProperty, Object value) { Method staticSetter = ReflectionUtils.getSetter(targetClass, staticProperty, true); if (staticSetter != null) { try { invokeMethod(targetClass, staticSetter, value); } catch (InvocationTargetException e) { throw new UnitilsException("Exception thrown by target", e); } } else { Field staticField = getFieldWithName(targetClass, staticProperty, true); if (staticField == null) { throw new UnitilsException("Static property named " + staticProperty + " not found on class " + targetClass.getSimpleName()); } setFieldValue(targetClass, staticField, value); } } }
/** * Retrieves the value of the static property from the given class * * @param targetClass The class from which the static property value is retrieved * @param staticProperty The name of the property (simple name, not a composite expression) * @return The value of the static property from the given class */ private static Object getValueStatic(Class<?> targetClass, String staticProperty) { Method staticGetter = getGetter(targetClass, staticProperty, true); if (staticGetter != null) { try { return invokeMethod(targetClass, staticGetter); } catch (InvocationTargetException e) { throw new UnitilsException("Exception thrown by target", e); } } else { Field staticField = getFieldWithName(targetClass, staticProperty, true); if (staticField != null) { return getFieldValue(targetClass, staticField); } else { throw new UnitilsException("Static property named " + staticProperty + " not found on class " + targetClass.getSimpleName()); } } }