com.tngtech.junit.dataprovider.convert.DataConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of junit-dataprovider-core Show documentation
Show all versions of junit-dataprovider-core Show documentation
The common core for a TestNG like dataprovider runner for JUnit.
The newest version!
/*
* Copyright 2019 TNG Technology Consulting GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.tngtech.junit.dataprovider.convert;
import static com.tngtech.junit.dataprovider.Preconditions.checkArgument;
import static com.tngtech.junit.dataprovider.Preconditions.checkNotNull;
import static com.tngtech.junit.dataprovider.Preconditions.checkState;
import java.util.ArrayList;
import java.util.List;
/**
* Class to convert dataprovider data (= arguments) to its corresponding parameters.
*/
public class DataConverter {
/**
* Converts the given {@link Object} to a {@link List} of {@link Object}{@code []} with {@link Class}es correspond
* to given {@code parameterTypes}.
*
* Supported types are :
*
* - Object[][]
* - Iterable<Iterable<?>>
* - Iterable<?>
* - Object[]
* - String[]
*
*
* Note: {@link Iterable} can be replaced by any valid subtype. As well as an arbitrary inner type is also accepted.
*
* @param data to be converted
* @param isVarargs determines whether test method has a varargs parameter
* @param parameterTypes required types for {@code data}
* @param context containing settings which should be used to convert given {@code data} (only required for
* converting {@code String[]})
* @return converted data as {@link List}{@code <}{@link Object}{@code []>} with the required {@code parameterTypes}
* @throws NullPointerException if and only if given {@code parameterTypes} are {@code null}
* @throws IllegalArgumentException if and only if given {@code parameterTypes} are empty
* @throws IllegalStateException if and only if given {@code context} is {@code null} but data is {@code String[]}
* @throws ClassCastException if and only if {@code data} is not a compatible type
*/
public List