From 836c3647f90675bce5e15e5579d0061a348c0b11 Mon Sep 17 00:00:00 2001 From: Andreas Schmid Date: Sun, 29 Jun 2014 13:53:31 +0200 Subject: [PATCH] futher minimal refactorings (#24) --- .../java/junit/dataprovider/internal/DataConverter.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/tngtech/java/junit/dataprovider/internal/DataConverter.java b/src/main/java/com/tngtech/java/junit/dataprovider/internal/DataConverter.java index 0b0d64ce..9a05af54 100644 --- a/src/main/java/com/tngtech/java/junit/dataprovider/internal/DataConverter.java +++ b/src/main/java/com/tngtech/java/junit/dataprovider/internal/DataConverter.java @@ -62,7 +62,6 @@ public boolean canConvert(Type type) { } } return false; - } /** @@ -122,7 +121,7 @@ public List convert(Object data, Class[] parameterTypes, Settings s *

* * @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 @@ -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)) { @@ -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); } @@ -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); }