org.junit.jupiter.params.provider.CsvFileArgumentsProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of junit-jupiter-params Show documentation
Show all versions of junit-jupiter-params Show documentation
Module "junit-jupiter-params" of JUnit 5.
/*
* Copyright 2015-2024 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/
package org.junit.jupiter.params.provider;
import static java.util.Spliterators.spliteratorUnknownSize;
import static java.util.stream.Collectors.toList;
import static java.util.stream.StreamSupport.stream;
import static org.junit.jupiter.params.provider.CsvArgumentsProvider.getHeaders;
import static org.junit.jupiter.params.provider.CsvArgumentsProvider.handleCsvException;
import static org.junit.jupiter.params.provider.CsvArgumentsProvider.processCsvRecord;
import static org.junit.jupiter.params.provider.CsvParserFactory.createParserFor;
import static org.junit.platform.commons.util.CollectionUtils.toSet;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Spliterator;
import java.util.stream.Stream;
import com.univocity.parsers.csv.CsvParser;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.platform.commons.JUnitException;
import org.junit.platform.commons.PreconditionViolationException;
import org.junit.platform.commons.util.Preconditions;
/**
* @since 5.0
*/
class CsvFileArgumentsProvider extends AnnotationBasedArgumentsProvider {
private final InputStreamProvider inputStreamProvider;
private Charset charset;
private int numLinesToSkip;
private CsvParser csvParser;
CsvFileArgumentsProvider() {
this(DefaultInputStreamProvider.INSTANCE);
}
CsvFileArgumentsProvider(InputStreamProvider inputStreamProvider) {
this.inputStreamProvider = inputStreamProvider;
}
@Override
protected Stream extends Arguments> provideArguments(ExtensionContext context, CsvFileSource csvFileSource) {
this.charset = getCharsetFrom(csvFileSource);
this.numLinesToSkip = csvFileSource.numLinesToSkip();
this.csvParser = createParserFor(csvFileSource);
Stream