<commit_before>package org.tinylog.core;

import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Locale;
import java.util.Map;

import javax.inject.Inject;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.tinylog.core.loader.ConfigurationLoader;
import org.tinylog.core.test.log.CaptureLogEntries;
import org.tinylog.core.test.log.Log;
import org.tinylog.core.test.service.RegisterService;

import static com.github.stefanbirkner.systemlambda.SystemLambda.restoreSystemProperties;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

@CaptureLogEntries
class ConfigurationTest {

	@Inject
	private Framework framework;

	@Inject
	private Log log;

	/**
	 * Tests for getting and setting values.
	 */
	@Nested
	class Values {

		/**
		 * Verifies that a new value can be set.
		 */
		@Test
		void setNewValue() {
			Configuration configuration = new Configuration();
			Configuration other = configuration.set("foo", "42");

			assertThat(configuration.getValue("foo")).isEqualTo("42");
			assertThat(other).isSameAs(configuration);
		}

		/**
		 * Verifies that an existing value can be overwritten.
		 */
		@Test
		void overwriteExistingValue() {
			Configuration configuration = new Configuration();
			Configuration other = configuration.set("foo", "1").set("foo", "2");

			assertThat(configuration.getValue("foo")).isEqualTo("2");
			assertThat(other).isSameAs(configuration);
		}

		/**
		 * Verifies that an empty value for property "locale" is interpreted as {@link Locale#ROOT}.
		 */
		@Test
		void getExistingEmptyLocale() {
			Configuration configuration = new Configuration().set("locale", "");
			assertThat(configuration.getLocale()).isEqualTo(Locale.ROOT);
		}

		/**
		 * Verifies that a locale that contains only the language can be created from property "locale".
		 */
		@Test
		void getExistingLocaleWithLanguageOnly() {
			Configuration configuration = new Configuration().set("locale", "de");
			assertThat(configuration.getLocale()).isEqualTo(new Locale("de"));
		}

		/**
		 * Verifies that a locale that contains language and country can be created from property "locale".
		 */
		@Test
		void getExistingLocaleWithLanguageAndCountry() {
			Configuration configuration = new Configuration().set("locale", "it_CH");
			assertThat(configuration.getLocale()).isEqualTo(new Locale("it", "CH"));
		}

		/**
		 * Verifies that a locale that contains language, country, and variant can be created from property "locale".
		 */
		@Test
		void getExistingFullLocale() {
			Configuration configuration = new Configuration().set("locale", "en_US_UNIX");
			assertThat(configuration.getLocale()).isEqualTo(new Locale("en", "US", "UNIX"));
		}

		/**
		 * Verifies that {@link Locale#getDefault()} will be returned if property "locale" is not set.
		 */
		@Test
		void getMissingLocale() {
			Configuration configuration = new Configuration();
			assertThat(configuration.getLocale()).isSameAs(Locale.getDefault());
		}

		/**
		 * Verifies that UTC can be set as time zone via property "zone".
		 */
		@Test
		void getUtcZone() {
			Configuration configuration = new Configuration().set("zone", "UTC");
			assertThat(configuration.getZone().normalized()).isEqualTo(ZoneOffset.UTC);
		}

		/**
		 * Verifies that an offset time zone can be set relative to UTC via property "zone".
		 */
		@Test
		void getOffsetZone() {
			Configuration configuration = new Configuration().set("zone", "UTC+01:30");
			assertThat(configuration.getZone().normalized()).isEqualTo(ZoneOffset.ofHoursMinutes(1, 30));
		}

		/**
		 * Verifies that Europe/London can be set as time zone via property "zone".
		 */
		@Test
		void getBritishZone() {
			Configuration configuration = new Configuration().set("zone", "Europe/London");
			assertThat(configuration.getZone()).isEqualTo(ZoneId.of("Europe/London"));
		}

		/**
		 * Verifies that Europe/Berlin can be set as time zone via property "zone".
		 */
		@Test
		void getGermanZone() {
			Configuration configuration = new Configuration().set("zone", "Europe/Berlin");
			assertThat(configuration.getZone()).isEqualTo(ZoneId.of("Europe/Berlin"));
		}

		/**
		 * Verifies that {@link ZoneOffset#systemDefault()} will be returned if property "zone" contains an invalid
		 * value.
		 */
		@Test
		void getInvalidZone() {
			Configuration configuration = new Configuration().set("zone", "Invalid/Foo");
			assertThat(configuration.getZone()).isSameAs(ZoneOffset.systemDefault());
			assertThat(log.consume())
				.isNotEmpty()
				.anySatisfy(entry -> {
					assertThat(entry.getLevel()).isEqualTo(Level.ERROR);
					assertThat(entry.getMessage()).contains("Invalid/Foo\"");
				});
		}

		/**
		 * Verifies that {@link ZoneOffset#systemDefault()} will be returned if property "zone" is not set.
		 */
		@Test
		void getMissingZone() {
			Configuration configuration = new Configuration();
			assertThat(configuration.getZone()).isSameAs(ZoneOffset.systemDefault());
		}

		/**
		 * Verifies that an existing value can be received.
		 */
		@Test
		void getExistingStringValue() {
			Configuration configuration = new Configuration().set("foo", "42");
			assertThat(configuration.getValue("foo")).isEqualTo("42");
		}

		/**
		 * Verifies that {@code null} is returned for a missing value.
		 */
		@Test
		void getMissingStringValue() {
			Configuration configuration = new Configuration();
			assertThat(configuration.getValue("foo")).isNull();
		}<commit_msg>Simplify configuration test for invalid time zone<commit_after>package org.tinylog.core;

import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Locale;
import java.util.Map;

import javax.inject.Inject;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.tinylog.core.loader.ConfigurationLoader;
import org.tinylog.core.test.log.CaptureLogEntries;
import org.tinylog.core.test.log.Log;
import org.tinylog.core.test.service.RegisterService;

import static com.github.stefanbirkner.systemlambda.SystemLambda.restoreSystemProperties;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

@CaptureLogEntries
class ConfigurationTest {

	@Inject
	private Framework framework;

	@Inject
	private Log log;

	/**
	 * Tests for getting and setting values.
	 */
	@Nested
	class Values {

		/**
		 * Verifies that a new value can be set.
		 */
		@Test
		void setNewValue() {
			Configuration configuration = new Configuration();
			Configuration other = configuration.set("foo", "42");

			assertThat(configuration.getValue("foo")).isEqualTo("42");
			assertThat(other).isSameAs(configuration);
		}

		/**
		 * Verifies that an existing value can be overwritten.
		 */
		@Test
		void overwriteExistingValue() {
			Configuration configuration = new Configuration();
			Configuration other = configuration.set("foo", "1").set("foo", "2");

			assertThat(configuration.getValue("foo")).isEqualTo("2");
			assertThat(other).isSameAs(configuration);
		}

		/**
		 * Verifies that an empty value for property "locale" is interpreted as {@link Locale#ROOT}.
		 */
		@Test
		void getExistingEmptyLocale() {
			Configuration configuration = new Configuration().set("locale", "");
			assertThat(configuration.getLocale()).isEqualTo(Locale.ROOT);
		}

		/**
		 * Verifies that a locale that contains only the language can be created from property "locale".
		 */
		@Test
		void getExistingLocaleWithLanguageOnly() {
			Configuration configuration = new Configuration().set("locale", "de");
			assertThat(configuration.getLocale()).isEqualTo(new Locale("de"));
		}

		/**
		 * Verifies that a locale that contains language and country can be created from property "locale".
		 */
		@Test
		void getExistingLocaleWithLanguageAndCountry() {
			Configuration configuration = new Configuration().set("locale", "it_CH");
			assertThat(configuration.getLocale()).isEqualTo(new Locale("it", "CH"));
		}

		/**
		 * Verifies that a locale that contains language, country, and variant can be created from property "locale".
		 */
		@Test
		void getExistingFullLocale() {
			Configuration configuration = new Configuration().set("locale", "en_US_UNIX");
			assertThat(configuration.getLocale()).isEqualTo(new Locale("en", "US", "UNIX"));
		}

		/**
		 * Verifies that {@link Locale#getDefault()} will be returned if property "locale" is not set.
		 */
		@Test
		void getMissingLocale() {
			Configuration configuration = new Configuration();
			assertThat(configuration.getLocale()).isSameAs(Locale.getDefault());
		}

		/**
		 * Verifies that UTC can be set as time zone via property "zone".
		 */
		@Test
		void getUtcZone() {
			Configuration configuration = new Configuration().set("zone", "UTC");
			assertThat(configuration.getZone().normalized()).isEqualTo(ZoneOffset.UTC);
		}

		/**
		 * Verifies that an offset time zone can be set relative to UTC via property "zone".
		 */
		@Test
		void getOffsetZone() {
			Configuration configuration = new Configuration().set("zone", "UTC+01:30");
			assertThat(configuration.getZone().normalized()).isEqualTo(ZoneOffset.ofHoursMinutes(1, 30));
		}

		/**
		 * Verifies that Europe/London can be set as time zone via property "zone".
		 */
		@Test
		void getBritishZone() {
			Configuration configuration = new Configuration().set("zone", "Europe/London");
			assertThat(configuration.getZone()).isEqualTo(ZoneId.of("Europe/London"));
		}

		/**
		 * Verifies that Europe/Berlin can be set as time zone via property "zone".
		 */
		@Test
		void getGermanZone() {
			Configuration configuration = new Configuration().set("zone", "Europe/Berlin");
			assertThat(configuration.getZone()).isEqualTo(ZoneId.of("Europe/Berlin"));
		}

		/**
		 * Verifies that {@link ZoneOffset#systemDefault()} will be returned if property "zone" contains an invalid
		 * value.
		 */
		@Test
		void getInvalidZone() {
			Configuration configuration = new Configuration().set("zone", "Invalid/Foo");
			assertThat(configuration.getZone()).isSameAs(ZoneOffset.systemDefault());
			assertThat(log.consume()).anySatisfy(entry -> {
				assertThat(entry.getLevel()).isEqualTo(Level.ERROR);
				assertThat(entry.getMessage()).contains("Invalid/Foo");
			});
		}

		/**
		 * Verifies that {@link ZoneOffset#systemDefault()} will be returned if property "zone" is not set.
		 */
		@Test
		void getMissingZone() {
			Configuration configuration = new Configuration();
			assertThat(configuration.getZone()).isSameAs(ZoneOffset.systemDefault());
		}

		/**
		 * Verifies that an existing value can be received.
		 */
		@Test
		void getExistingStringValue() {
			Configuration configuration = new Configuration().set("foo", "42");
			assertThat(configuration.getValue("foo")).isEqualTo("42");
		}

		/**
		 * Verifies that {@code null} is returned for a missing value.
		 */
		@Test
		void getMissingStringValue() {
			Configuration configuration = new Configuration();
			assertThat(configuration.getValue("foo")).isNull();
		}
{'fraction_non_alphanumeric': 0.13433237616654703, 'fraction_numerical': 0.003230437903804738, 'mean_word_length': 4.342761265580058, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '680529', 'n_tokens_mistral': 3531, 'n_tokens_neox': 3096, 'n_words': 788}