@SuppressWarnings({ "unchecked", "rawtypes" }) Class<Enum> enumType = (Class<Enum>) targetType; return convertToEnumValue(str, enumType, dataProvider.ignoreEnumCase());
@SuppressWarnings({ "unchecked", "rawtypes" }) Class<Enum> enumType = (Class<Enum>) targetType; return convertToEnumValue(str, enumType, dataProvider.ignoreEnumCase());
@Test public void testConvertShouldCorrectlyParseEnumIgnoringCase() { // Given: String data = "Val1,val2"; Class<?>[] parameterTypes = new Class<?>[] { TestEnum.class, TestEnum.class }; doReturn(",").when(dataProvider).splitBy(); doReturn(true).when(dataProvider).ignoreEnumCase(); // When: Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 50); // Then: assertThat(result).containsExactly(TestEnum.VAL1, TestEnum.VAL2); }
/** * 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); }