Polishing
This commit is contained in:
parent
b1ca18e0dc
commit
7beff7b40a
|
@ -164,27 +164,26 @@ public class ReflectionTestUtils {
|
||||||
Assert.isTrue(targetObject != null || targetClass != null,
|
Assert.isTrue(targetObject != null || targetClass != null,
|
||||||
"Either targetObject or targetClass for the field must be specified");
|
"Either targetObject or targetClass for the field must be specified");
|
||||||
|
|
||||||
Object ultimateTargetObject = (targetObject == null ? null
|
Object ultimateTarget = (targetObject != null ? AopTestUtils.getUltimateTargetObject(targetObject) : null);
|
||||||
: AopTestUtils.getUltimateTargetObject(targetObject));
|
|
||||||
|
|
||||||
if (targetClass == null) {
|
if (targetClass == null) {
|
||||||
targetClass = ultimateTargetObject.getClass();
|
targetClass = ultimateTarget.getClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
Field field = ReflectionUtils.findField(targetClass, name, type);
|
Field field = ReflectionUtils.findField(targetClass, name, type);
|
||||||
if (field == null) {
|
if (field == null) {
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new IllegalArgumentException(String.format(
|
||||||
"Could not find field '%s' of type [%s] on target object [%s] or target class [%s]", name, type,
|
"Could not find field '%s' of type [%s] on target object [%s] or target class [%s]", name, type,
|
||||||
targetObject, targetClass));
|
ultimateTarget, targetClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(String.format(
|
logger.debug(String.format(
|
||||||
"Setting field '%s' of type [%s] on target object [%s] or target class [%s] to value [%s]", name, type,
|
"Setting field '%s' of type [%s] on target object [%s] or target class [%s] to value [%s]", name, type,
|
||||||
targetObject, targetClass, value));
|
ultimateTarget, targetClass, value));
|
||||||
}
|
}
|
||||||
ReflectionUtils.makeAccessible(field);
|
ReflectionUtils.makeAccessible(field);
|
||||||
ReflectionUtils.setField(field, ultimateTargetObject, value);
|
ReflectionUtils.setField(field, ultimateTarget, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -245,26 +244,25 @@ public class ReflectionTestUtils {
|
||||||
Assert.isTrue(targetObject != null || targetClass != null,
|
Assert.isTrue(targetObject != null || targetClass != null,
|
||||||
"Either targetObject or targetClass for the field must be specified");
|
"Either targetObject or targetClass for the field must be specified");
|
||||||
|
|
||||||
Object ultimateTargetObject = (targetObject == null ? null
|
Object ultimateTarget = (targetObject != null ? AopTestUtils.getUltimateTargetObject(targetObject) : null);
|
||||||
: AopTestUtils.getUltimateTargetObject(targetObject));
|
|
||||||
|
|
||||||
if (targetClass == null) {
|
if (targetClass == null) {
|
||||||
targetClass = ultimateTargetObject.getClass();
|
targetClass = ultimateTarget.getClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
Field field = ReflectionUtils.findField(targetClass, name);
|
Field field = ReflectionUtils.findField(targetClass, name);
|
||||||
if (field == null) {
|
if (field == null) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
String.format("Could not find field '%s' on target object [%s] or target class [%s]", name,
|
String.format("Could not find field '%s' on target object [%s] or target class [%s]", name,
|
||||||
targetObject, targetClass));
|
ultimateTarget, targetClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(String.format("Getting field '%s' from target object [%s] or target class [%s]", name,
|
logger.debug(String.format("Getting field '%s' from target object [%s] or target class [%s]", name,
|
||||||
targetObject, targetClass));
|
ultimateTarget, targetClass));
|
||||||
}
|
}
|
||||||
ReflectionUtils.makeAccessible(field);
|
ReflectionUtils.makeAccessible(field);
|
||||||
return ReflectionUtils.getField(field, ultimateTargetObject);
|
return ReflectionUtils.getField(field, ultimateTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue