<commit_before>/*
 * Copyright 2015-2017 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
 *
 * http://www.eclipse.org/legal/epl-v20.html
 */

package org.junit.jupiter.params.provider;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.stream.Stream;

import org.junit.jupiter.api.Test;
import org.junit.platform.commons.JUnitException;

/**
 * @since 5.0
 */
class CsvArgumentsProviderTests {

	@Test
	void providesSingleArgument() {
		Stream<Object[]> arguments = provideArguments(',', "foo");

		assertThat(arguments).containsExactly(new String[] { "foo" });
	}

	@Test
	void providesMultipleArguments() {
		Stream<Object[]> arguments = provideArguments(',', "foo", "bar");

		assertThat(arguments).containsExactly(new String[] { "foo" }, new String[] { "bar" });
	}

	@Test
	void splitsAndTrimsArguments() {
		Stream<Object[]> arguments = provideArguments('|', " foo | bar ");

		assertThat(arguments).containsExactly(new String[] { "foo", "bar" });
	}

	@Test
	void understandsQuotes() {
		Stream<Object[]> arguments = provideArguments(',', "'foo, bar'");

		assertThat(arguments).containsExactly(new String[] { "foo, bar" });
	}

	@Test
	void understandsEscapeCharacters() {
		Stream<Object[]> arguments = provideArguments(',', "'foo or ''bar''', baz");

		assertThat(arguments).containsExactly(new String[] { "foo or 'bar'", "baz" });
	}

	@Test
	void throwsExceptionOnInvalidCsv() {
		JUnitException exception = assertThrows(JUnitException.class,
			() -> provideArguments(',', "foo", "bar", "").toArray());

		assertThat(exception).hasMessage("Line at index 2 contains invalid CSV: \"\"");
	}

	@Test
	void emptyValueIsAnEmptyString() {
		Stream<Object[]> arguments = provideArguments(',', "null , , empty , ''");

		assertThat(arguments).containsExactly(new String[] { "null", null, "empty", "" });
	}

	@Test
	void leadingSpacesAreTrimmed() {
		Stream<Object[]> arguments = provideArguments(',', "'', 1", " '', 2", "'' , 3", " '' , 4");

		assertThat(arguments).containsExactly(new String[][] { { "", "1" }, { "", "2" }, { "", "3" }, { "", "4" } });
	}

	@Test
	void trailingSpacesAreTrimmed() {
		Stream<Object[]> arguments = provideArguments(',', "1,''", "2, ''", "3,'' ", "4, '' ");

		assertThat(arguments).containsExactly(new String[][] { { "1", "" }, { "2", "" }, { "3", "" }, { "4", "" } });
	}

	private Stream<Object[]> provideArguments(char delimiter, String... value) {
		CsvSource annotation = mock(CsvSource.class);<commit_msg>Clean up warnings<commit_after>/*
 * Copyright 2015-2017 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
 *
 * http://www.eclipse.org/legal/epl-v20.html
 */

package org.junit.jupiter.params.provider;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.stream.Stream;

import org.junit.jupiter.api.Test;
import org.junit.platform.commons.JUnitException;

/**
 * @since 5.0
 */
class CsvArgumentsProviderTests {

	@Test
	void providesSingleArgument() {
		Stream<Object[]> arguments = provideArguments(',', "foo");

		assertThat(arguments).containsExactly(new String[] { "foo" });
	}

	@Test
	void providesMultipleArguments() {
		Stream<Object[]> arguments = provideArguments(',', "foo", "bar");

		assertThat(arguments).containsExactly(new String[] { "foo" }, new String[] { "bar" });
	}

	@Test
	void splitsAndTrimsArguments() {
		Stream<Object[]> arguments = provideArguments('|', " foo | bar ");

		assertThat(arguments).containsExactly(new String[] { "foo", "bar" });
	}

	@Test
	void understandsQuotes() {
		Stream<Object[]> arguments = provideArguments(',', "'foo, bar'");

		assertThat(arguments).containsExactly(new String[] { "foo, bar" });
	}

	@Test
	void understandsEscapeCharacters() {
		Stream<Object[]> arguments = provideArguments(',', "'foo or ''bar''', baz");

		assertThat(arguments).containsExactly(new String[] { "foo or 'bar'", "baz" });
	}

	@Test
	void throwsExceptionOnInvalidCsv() {
		JUnitException exception = assertThrows(JUnitException.class,
			() -> provideArguments(',', "foo", "bar", "").toArray());

		assertThat(exception).hasMessage("Line at index 2 contains invalid CSV: \"\"");
	}

	@Test
	void emptyValueIsAnEmptyString() {
		Stream<Object[]> arguments = provideArguments(',', "null , , empty , ''");

		assertThat(arguments).containsExactly(new String[] { "null", null, "empty", "" });
	}

	@Test
	void leadingSpacesAreTrimmed() {
		Stream<Object[]> arguments = provideArguments(',', "'', 1", " '', 2", "'' , 3", " '' , 4");

		assertThat(arguments).containsExactly(new Object[][] { { "", "1" }, { "", "2" }, { "", "3" }, { "", "4" } });
	}

	@Test
	void trailingSpacesAreTrimmed() {
		Stream<Object[]> arguments = provideArguments(',', "1,''", "2, ''", "3,'' ", "4, '' ");

		assertThat(arguments).containsExactly(new Object[][] { { "1", "" }, { "2", "" }, { "3", "" }, { "4", "" } });
	}

	private Stream<Object[]> provideArguments(char delimiter, String... value) {
		CsvSource annotation = mock(CsvSource.class);
{'fraction_non_alphanumeric': 0.18881368008550053, 'fraction_numerical': 0.0110438190238689, 'mean_word_length': 4.941798941798941, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2659300', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1734, 'n_words': 395}