private Object convertValue(String data, Class<?> targetType, DataProvider dataProvider) { String str = (dataProvider.trimValues()) ? data.trim() : data; if (dataProvider.convertNulls() && NULL.equals(str)) { return null;
private Object convertValue(String data, Class<?> targetType, DataProvider dataProvider) { String str = (dataProvider.trimValues()) ? data.trim() : data; if (dataProvider.convertNulls() && NULL.equals(str)) { return null;
@Test public void testConvertShouldParseNullValuesAsNullObjectIfSettingsConvertNullsIsTrue() { // Given: String data = "null,null,foo"; Class<?>[] parameterTypes = new Class<?>[] { String.class, String.class, String.class }; doReturn(",").when(dataProvider).splitBy(); doReturn(true).when(dataProvider).convertNulls(); // When: Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 71); // Then: assertThat(result).containsExactly(null, null, "foo"); }
@Test public void testConvertShouldCreateVarargsArrayForOneLastVarargsArguments() { // Given: String data = "a,2,1.0,null"; Class<?>[] parameterTypes = new Class<?>[] { char.class, byte.class, Double[].class }; doReturn(",").when(dataProvider).splitBy(); doReturn(true).when(dataProvider).convertNulls(); // When: Object[] result = underTest.convert(data, true, parameterTypes, dataProvider, 93); // Then: assertThat(result).containsExactly('a', (byte) 2, new Double[] { 1.0, null }); }
/** * Converts the given {@code data} to its corresponding arguments using the given {@code parameterTypes} and other * provided information. * * @param data regex-separated {@link String} of parameters for test method * @param isVarargs determines whether test method has a varargs parameter * @param parameterTypes target types of parameters to which corresponding values in regex-separated {@code data} * should be converted * @param dataProvider containing settings which should be used to convert given {@code data} * @param rowIdx index of current {@code data} (row) for better error messages * @return split, trimmed and converted {@code Object[]} of supplied regex-separated {@code data} * @throws IllegalArgumentException iif count of split data and parameter types does not match or argument cannot be * converted to required type */ public Object[] convert(String data, boolean isVarargs, Class<?>[] parameterTypes, DataProvider dataProvider, int rowIdx) { ConverterContext context = new ConverterContext(dataProvider.splitBy(), dataProvider.convertNulls(), dataProvider.trimValues(), dataProvider.ignoreEnumCase()); return super.convert(data, isVarargs, parameterTypes, context, rowIdx); }
/** * Converts the given {@code data} to its corresponding arguments using the given {@code parameterTypes} and other * provided information. * * @param data regex-separated {@link String} of parameters for test method * @param isVarargs determines whether test method has a varargs parameter * @param parameterTypes target types of parameters to which corresponding values in regex-separated {@code data} * should be converted * @param dataProvider containing settings which should be used to convert given {@code data} * @param rowIdx index of current {@code data} (row) for better error messages * @return split, trimmed and converted {@code Object[]} of supplied regex-separated {@code data} * @throws IllegalArgumentException iif count of split data and parameter types does not match or argument cannot be * converted to required type */ public Object[] convert(String data, boolean isVarargs, Class<?>[] parameterTypes, DataProvider dataProvider, int rowIdx) { ConverterContext context = new ConverterContext(dataProvider.splitBy(), dataProvider.convertNulls(), dataProvider.trimValues(), dataProvider.ignoreEnumCase()); return super.convert(data, isVarargs, parameterTypes, context, rowIdx); }
/** * Converts the given {@link Object} to a {@link List} of {@link Object}{@code []} with {@link Class}es correspond * to given {@code parameterTypes}. * <p> * For compatible types, see {@link #canConvert(Type)}. * * @param data to be converted * @param isVarargs determines whether test method has a varargs parameter * @param parameterTypes required types for {@code data} * @param dataProvider containing settings which should be used to convert given {@code data} * @return converted data as {@link List}{@code <}{@link Object}{@code []>} with the required {@code parameterTypes} * @throws NullPointerException iif given {@code parameterTypes} or {@code settings} are {@code null} * @throws IllegalArgumentException iif given {@code parameterTypes} is empty * @throws ClassCastException iif {@code data} is not a compatible type */ public List<Object[]> convert(Object data, boolean isVarargs, Class<?>[] parameterTypes, DataProvider dataProvider) { checkNotNull(dataProvider, "dataProvider must not be null"); ConverterContext context = new ConverterContext(objectArrayConverter, singleArgConverter, stringConverter, dataProvider.splitBy(), dataProvider.convertNulls(), dataProvider.trimValues(), dataProvider.ignoreEnumCase()); return super.convert(data, isVarargs, parameterTypes, context); }
/** * Converts the given {@link Object} to a {@link List} of {@link Object}{@code []} with {@link Class}es correspond * to given {@code parameterTypes}. * <p> * For compatible types, see {@link #canConvert(Type)}. * * @param data to be converted * @param isVarargs determines whether test method has a varargs parameter * @param parameterTypes required types for {@code data} * @param dataProvider containing settings which should be used to convert given {@code data} * @return converted data as {@link List}{@code <}{@link Object}{@code []>} with the required {@code parameterTypes} * @throws NullPointerException iif given {@code parameterTypes} or {@code settings} are {@code null} * @throws IllegalArgumentException iif given {@code parameterTypes} is empty * @throws ClassCastException iif {@code data} is not a compatible type */ public List<Object[]> convert(Object data, boolean isVarargs, Class<?>[] parameterTypes, DataProvider dataProvider) { checkNotNull(dataProvider, "dataProvider must not be null"); ConverterContext context = new ConverterContext(objectArrayConverter, singleArgConverter, stringConverter, dataProvider.splitBy(), dataProvider.convertNulls(), dataProvider.trimValues(), dataProvider.ignoreEnumCase()); return super.convert(data, isVarargs, parameterTypes, context); }