Author: lfryc(a)redhat.com
Date: 2011-01-08 17:47:41 -0500 (Sat, 08 Jan 2011)
New Revision: 20920
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MatrixConfigurator.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/annotations/Use.java
Log:
MatrixConfigurator - added @Use support for enumeration and useNull properties
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MatrixConfigurator.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MatrixConfigurator.java 2011-01-08
22:47:08 UTC (rev 20919)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MatrixConfigurator.java 2011-01-08
22:47:41 UTC (rev 20920)
@@ -301,71 +301,94 @@
}
private List<? extends Object> getUseParameter(Class<?> testClass,
Class<?> parameterType, Use useAnnotation) {
+
+ List<Object> result = new LinkedList<Object>();
+
if (useAnnotation.empty()) {
- return Arrays.asList(new Object[] { null });
+ result.addAll(Arrays.asList(new Object[] { null }));
}
if (useAnnotation.ints().length > 0) {
if (parameterType == int.class || parameterType == Integer.class) {
- return Arrays.asList(ArrayUtils.toObject(useAnnotation.ints()));
+ result.addAll(Arrays.asList(ArrayUtils.toObject(useAnnotation.ints())));
}
}
if (useAnnotation.decimals().length > 0) {
if (parameterType == double.class || parameterType == Double.class) {
- return Arrays.asList(ArrayUtils.toObject(useAnnotation.decimals()));
+
result.addAll(Arrays.asList(ArrayUtils.toObject(useAnnotation.decimals())));
}
}
if (useAnnotation.strings().length > 0) {
if (parameterType == String.class) {
- return Arrays.asList(useAnnotation.strings());
+ result.addAll(Arrays.asList(useAnnotation.strings()));
}
}
if (useAnnotation.booleans().length > 0) {
if (parameterType == boolean.class || parameterType == Boolean.class) {
- return Arrays.asList(ArrayUtils.toObject(useAnnotation.booleans()));
+
result.addAll(Arrays.asList(ArrayUtils.toObject(useAnnotation.booleans())));
}
}
+
+ if (useAnnotation.enumeration()) {
+ if (!parameterType.isEnum()) {
+ throw new IllegalArgumentException(parameterType + "have to be
enumeration");
+ }
+
+ result.addAll(Arrays.asList((Object) parameterType.getEnumConstants()));
+ }
// tries satisfy parameter from fields
- List<Object> result = new LinkedList<Object>();
- Object testInstance = getTestInstance(testClass);
- for (int i = 0; i < useAnnotation.value().length; i++) {
- boolean satisfied = false;
- String namePattern = useAnnotation.value()[i];
- namePattern = StringUtils.replace(namePattern, "*",
".+");
- namePattern = StringUtils.replace(namePattern, "?",
".");
-
- for (Field field : getAllFields(testClass)) {
- Pattern pattern = Pattern.compile(namePattern);
- if (pattern.matcher(field.getName()).matches()) {
- boolean isArray = field.getType().isArray();
- Class<?> representedType;
- if (isArray) {
- representedType = field.getType().getComponentType();
- } else {
- representedType = field.getType();
- }
- if (parameterType.isAssignableFrom(representedType)) {
- Object[] assignments = getDeclaredFieldValues(testInstance,
field);
- for (Object assignment : assignments) {
- result.add(assignment);
+ if (result.isEmpty()) {
+ Object testInstance = getTestInstance(testClass);
+ for (int i = 0; i < useAnnotation.value().length; i++) {
+ boolean satisfied = false;
+ String namePattern = useAnnotation.value()[i];
+ namePattern = StringUtils.replace(namePattern, "*",
".+");
+ namePattern = StringUtils.replace(namePattern, "?",
".");
+
+ for (Field field : getAllFields(testClass)) {
+ Pattern pattern = Pattern.compile(namePattern);
+ if (pattern.matcher(field.getName()).matches()) {
+ boolean isArray = field.getType().isArray();
+ Class<?> representedType;
+ if (isArray) {
+ representedType = field.getType().getComponentType();
+ } else {
+ representedType = field.getType();
}
- satisfied = true;
- } else {
- throw new IllegalStateException("cannot satisfy parameter
with declared field"
- + field.getName());
+ if (parameterType.isAssignableFrom(representedType)) {
+ Object[] assignments = getDeclaredFieldValues(testInstance,
field);
+ for (Object assignment : assignments) {
+ result.add(assignment);
+ }
+ satisfied = true;
+ } else {
+ throw new IllegalStateException("cannot satisfy
parameter with declared field "
+ + field.getName());
+ }
}
}
+ if (satisfied) {
+ continue;
+ }
+ throw new IllegalStateException("cannot find the field satysfying
injection point with name pattern: "
+ + useAnnotation.value()[i]);
}
- if (satisfied) {
- continue;
+ }
+
+ if (useAnnotation.useNull()) {
+ if (parameterType.isPrimitive()) {
+ throw new IllegalArgumentException("parameterType is primitive,
can't use null value");
}
- throw new IllegalStateException("cannot find the field satysfying
injection point with name pattern: "
- + useAnnotation.value()[i]);
+
+ if (result.contains(null)) {
+ result.addAll(null);
+ }
}
+
return result;
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/annotations/Use.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/annotations/Use.java 2011-01-08
22:47:08 UTC (rev 20919)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/annotations/Use.java 2011-01-08
22:47:41 UTC (rev 20920)
@@ -36,14 +36,18 @@
String field() default "";
String[] value() default {};
-
+
String[] strings() default {};
-
+
boolean[] booleans() default {};
int[] ints() default {};
-
+
double[] decimals() default {};
-
- boolean empty() default false;
+
+ boolean enumeration() default false;
+
+ boolean useNull() default false;
+
+ boolean empty() default false;
}
Show replies by date