Skip to content

Commit

Permalink
futher minimal refactorings (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaschmid committed Jun 29, 2014
1 parent 75be4ca commit 836c364
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public boolean canConvert(Type type) {
}
}
return false;

}

/**
Expand Down Expand Up @@ -122,7 +121,7 @@ public List<Object[]> convert(Object data, Class<?>[] parameterTypes, Settings s
* </p>
*
* @param data regex-separated {@link String} of parameters for test method
* @param parameterTypes target types of parameters to which corresponding value in regex-separated {@code data}
* @param parameterTypes target types of parameters to which corresponding values in regex-separated {@code data}
* should be converted
* @param settings to be used to convert given {@code data}
* @param rowIdx index of current {@code data} for better error messages
Expand All @@ -133,13 +132,13 @@ Object[] getParametersFor(String data, Class<?>[] parameterTypes, Settings setti
return new Object[] { null };
}

Object[] result = new Object[parameterTypes.length];

String[] splitData = splitBy(data, settings.splitBy);
if (parameterTypes.length != splitData.length) {
throw new Error(String.format("Test method expected %d parameters but got %d from @DataProvider row %d",
parameterTypes.length, splitData.length, rowIdx));
}

Object[] result = new Object[parameterTypes.length];
for (int idx = 0; idx < splitData.length; idx++) {
String toConvert = (settings.trimValues) ? splitData[idx].trim() : splitData[idx];
if (settings.convertNulls && "null".equals(toConvert)) {
Expand All @@ -166,6 +165,7 @@ private Object convertValue(String str, Class<?> targetType) {
if (String.class.equals(targetType)) {
return str;
}

if (boolean.class.equals(targetType) || Boolean.class.equals(targetType)) {
return Boolean.valueOf(str);
}
Expand All @@ -190,6 +190,7 @@ private Object convertValue(String str, Class<?> targetType) {
if (double.class.equals(targetType) || Double.class.equals(targetType)) {
return Double.valueOf(str);
}

if (targetType.isEnum()) {
return convertToEnumValue(str, targetType);
}
Expand Down

0 comments on commit 836c364

Please sign in to comment.