mirror of https://github.com/apache/activemq.git
Allows the class to set a field that isn't public but has a setter method. Fixes the compile warnings as well.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1153701 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
eee1a60126
commit
84a16161be
|
@ -64,7 +64,7 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport {
|
|||
|
||||
private HashMap<String, ComboOption> comboOptions = new HashMap<String, ComboOption>();
|
||||
private boolean combosEvaluated;
|
||||
private Map options;
|
||||
private Map<String, Object> options;
|
||||
|
||||
static class ComboOption {
|
||||
final String attribute;
|
||||
|
@ -99,16 +99,35 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
private void setOptions(Map options) throws NoSuchFieldException, IllegalAccessException {
|
||||
private void setOptions(Map<String, Object> options) throws NoSuchFieldException, IllegalAccessException {
|
||||
this.options = options;
|
||||
for (Iterator iterator = options.keySet().iterator(); iterator.hasNext();) {
|
||||
String attribute = (String)iterator.next();
|
||||
for (Iterator<String> iterator = options.keySet().iterator(); iterator.hasNext();) {
|
||||
String attribute = iterator.next();
|
||||
Object value = options.get(attribute);
|
||||
try {
|
||||
Field field = getClass().getField(attribute);
|
||||
field.set(this, value);
|
||||
} catch (Throwable e) {
|
||||
LOG.info("Could not set field '" + attribute + "' to value '" + value + "', make sure the field exists and is public.");
|
||||
try {
|
||||
boolean found = false;
|
||||
String setterName = "set" + attribute.substring(0, 1).toUpperCase() +
|
||||
attribute.substring(1);
|
||||
for(Method method : getClass().getMethods()) {
|
||||
if (method.getName().equals(setterName)) {
|
||||
method.invoke(this, value);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
throw new NoSuchMethodError("No setter found for field: " + attribute);
|
||||
}
|
||||
|
||||
} catch(Throwable ex) {
|
||||
LOG.info("Could not set field '" + attribute + "' to value '" + value +
|
||||
"', make sure the field exists and is public or has a setter.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,8 +232,8 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport {
|
|||
|
||||
private static boolean isTestMethod(Method m) {
|
||||
String name = m.getName();
|
||||
Class[] parameters = m.getParameterTypes();
|
||||
Class returnType = m.getReturnType();
|
||||
Class<?>[] parameters = m.getParameterTypes();
|
||||
Class<?> returnType = m.getReturnType();
|
||||
return parameters.length == 0 && name.startsWith("test") && returnType.equals(Void.TYPE);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue