<commit_before>package org.tinylog.impl.path.segments;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Locale;
import java.util.stream.Stream;

import javax.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.tinylog.core.Level;
import org.tinylog.core.test.log.CaptureLogEntries;
import org.tinylog.core.test.log.Log;

import static org.assertj.core.api.Assertions.assertThat;

@CaptureLogEntries
class DateTimeSegmentTest {

	@TempDir
	private Path folder;

	@Inject
	private Log log;

	/**
	 * Verifies that null is returned if there are no matching files.
	 */
	@Test
	void findLatestOfNone() throws IOException {
		Files.createFile(folder.resolve("foo_BAR.log"));
		Files.createFile(folder.resolve("bar_01-01-2000.log"));

		String latest = new DateTimeSegment("dd-MM-yyyy", Locale.ENGLISH).findLatest(folder, "foo_");
		assertThat(latest).isNull();
	}

	/**
	 * Verifies that the date of the only matching file is used.<commit_msg>add test if findLatest is called with non-existing folder<commit_after>package org.tinylog.impl.path.segments;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Locale;
import java.util.stream.Stream;

import javax.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.tinylog.core.Level;
import org.tinylog.core.test.log.CaptureLogEntries;
import org.tinylog.core.test.log.Log;

import static org.assertj.core.api.Assertions.assertThat;

@CaptureLogEntries
class DateTimeSegmentTest {

	@TempDir
	private Path folder;

	@Inject
	private Log log;

	/**
	 * Verifies that null is returned if the folder does not exist.
	 */
	@Test
	void findLatestOfNoneExisting() throws IOException {
		Path nonExistingFolder = folder.resolve("non-existing");

		String latest = new DateTimeSegment("dd-MM-yyyy", Locale.ENGLISH).findLatest(nonExistingFolder, "foo_");
		assertThat(latest).isNull();
	}

	/**
	 * Verifies that null is returned if there are no matching files.
	 */
	@Test
	void findLatestOfNone() throws IOException {
		Files.createFile(folder.resolve("foo_BAR.log"));
		Files.createFile(folder.resolve("bar_01-01-2000.log"));

		String latest = new DateTimeSegment("dd-MM-yyyy", Locale.ENGLISH).findLatest(folder, "foo_");
		assertThat(latest).isNull();
	}

	/**
	 * Verifies that the date of the only matching file is used.
{'fraction_non_alphanumeric': 0.11803381340012524, 'fraction_numerical': 0.005009392611145898, 'mean_word_length': 5.15606936416185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2408548', 'n_tokens_mistral': 1050, 'n_tokens_neox': 1015, 'n_words': 213}