diff --git a/README.md b/README.md index 659b3ae..5965d93 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ testImplementation("io.github.scordio:jimfs-junit-jupiter:${jimfsJunitJupiterVer ### JimfsTempDirFactory -The simplest possible usage is to set the +The simplest usage is to set the [`factory`](https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/io/TempDir.html#factory()) attribute of `@TempDir` to `JimfsTempDirFactory`: @@ -67,14 +67,13 @@ void test(@TempDir(factory = JimfsTempDirFactory.class) Path tempDir) { ``` `tempDir` is resolved into an in-memory temporary directory based on Jimfs, appropriately configured for the current -operating system. +platform. ### @JimfsTempDir `@JimfsTempDir`, a `@TempDir` [composed annotation](https://junit.org/junit5/docs/current/user-guide/#writing-tests-meta-annotations), -can be used as a drop-in replacement for -`@TempDir(factory = JimfsTempDirFactory.class)`: +can be used as a drop-in replacement for `@TempDir(factory = JimfsTempDirFactory.class)`: ```java @Test @@ -85,16 +84,17 @@ void test(@JimfsTempDir Path tempDir) { The default behavior of the annotation is equivalent to using `JimfsTempDirFactory` directly: `tempDir` is resolved into an in-memory temporary directory based on Jimfs, appropriately configured for the current -operating system. +platform. -For better control over the underlying in-memory file system, -`@JimfsTempDir` offers an optional `value` attribute that can be set to the desired configuration, one of: -* `FOR_CURRENT_PLATFORM`: appropriate to the current operating system (default) +For better control over the underlying in-memory file system, `@JimfsTempDir` offers an optional `value` attribute +that can be set to the desired configuration, one of: +* `DEFAULT`: based on the corresponding [configuration parameter](#default-jimfs-configuration) (default) +* `FOR_CURRENT_PLATFORM`: appropriate to the current platform * `OS_X`: for a Mac OS X-like file system * `UNIX`: for a UNIX-like file system * `WINDOWS`: for a Windows-like file system -For example, the following defines a Windows-like temporary directory regardless of the operating system the test +For example, the following defines a Windows-like temporary directory regardless of the platform the test is running on: ```java @@ -104,11 +104,16 @@ void test(@JimfsTempDir(WINDOWS) Path tempDir) { } ``` -### Default Configuration +### Configuration Parameters + +Jimfs JUnit Jupiter supports JUnit +[configuration parameters](https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params). + +#### Default `@TempDir` Factory + +The `junit.jupiter.tempdir.factory.default` configuration parameter sets the default factory to use, expecting its +fully qualified class name. -The `junit.jupiter.tempdir.factory.default` -[configuration parameter](https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params) -can be used to specify the fully qualified class name of the factory to be used by default. For example, the following configures `JimfsTempDirFactory`: ```properties @@ -118,6 +123,25 @@ junit.jupiter.tempdir.factory.default=io.github.scordio.jimfs.junit.jupiter.Jimf The factory will be used for all `@TempDir` annotations unless the `factory` attribute of the annotation specifies a different type. +#### Default Jimfs Configuration + +The `jimfs.junit.jupiter.tempdir.configuration.default` configuration parameter sets the default Jimfs configuration +to use, expecting one of the following (case-insensitive): +* `FOR_CURRENT_PLATFORM`: appropriate to the current platform (default) +* `OS_X`: for a Mac OS X-like file system +* `UNIX`: for a UNIX-like file system +* `WINDOWS`: for a Windows-like file system + +For example, the following defines a Windows-like temporary directory regardless of the platform the test +is running on: + +```properties +jimfs.junit.jupiter.tempdir.configuration.default=windows +``` + +All Jimfs-based temporary directories will be configured accordingly unless `@JimfsTempDir` is used and +its `value` attribute is set. + ### Limitations Jimfs JUnit Jupiter only supports annotated fields or parameters of type `Path`, as Jimfs is a non-default file diff --git a/pom.xml b/pom.xml index b760094..501c7eb 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ org.junit.jupiter - junit-jupiter-engine + junit-jupiter test diff --git a/src/main/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDir.java b/src/main/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDir.java index d97cf1a..dc7696f 100644 --- a/src/main/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDir.java +++ b/src/main/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDir.java @@ -40,6 +40,17 @@ @TempDir(factory = JimfsTempDirFactory.class) public @interface JimfsTempDir { + /** + * Configuration parameter to set the default {@link Configuration Configuration} for the + * in-memory file system. + * + *

If this configuration parameter is not set, the default is {@link + * Configuration#FOR_CURRENT_PLATFORM}. + * + * @since 0.2.0 + */ + String DEFAULT_CONFIGURATION_PARAMETER_NAME = "jimfs.junit.jupiter.tempdir.configuration.default"; + /** * Configuration for the in-memory file system. * @@ -47,7 +58,7 @@ * * @return the configuration to use for the in-memory file system */ - Configuration value() default Configuration.FOR_CURRENT_PLATFORM; + Configuration value() default Configuration.DEFAULT; /** * Enumeration of configurations for the in-memory file system. @@ -56,7 +67,14 @@ */ enum Configuration { /** - * Configuration appropriate to the current operating system. + * Default configuration. + * + * @see #DEFAULT_CONFIGURATION_PARAMETER_NAME + * @since 0.2.0 + */ + DEFAULT(com.google.common.jimfs.Configuration::forCurrentPlatform), + /** + * Configuration appropriate to the current platform. * * @see com.google.common.jimfs.Configuration#forCurrentPlatform() */ diff --git a/src/main/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirFactory.java b/src/main/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirFactory.java index 2c4f03e..8fac281 100644 --- a/src/main/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirFactory.java +++ b/src/main/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirFactory.java @@ -21,7 +21,9 @@ import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Locale; import java.util.Optional; +import java.util.function.Function; import java.util.function.Supplier; import org.junit.jupiter.api.extension.AnnotatedElementContext; import org.junit.jupiter.api.extension.ExtensionContext; @@ -31,28 +33,33 @@ * {@link TempDirFactory} implementation that creates an in-memory temporary directory via {@link * Jimfs}, using {@value DEFAULT_PREFIX} as the name prefix. * - *

If used as a standalone factory within the {@link org.junit.jupiter.api.io.TempDir} - * annotation, or set as value for the {@value DEFAULT_FACTORY_PROPERTY_NAME} configuration - * property, the factory configures the underlying file system {@link - * Configuration#forCurrentPlatform() appropriately for the current operating system}. + *

When used as a standalone factory within the {@link org.junit.jupiter.api.io.TempDir} + * annotation, or set as value for the {@value + * org.junit.jupiter.api.io.TempDir#DEFAULT_FACTORY_PROPERTY_NAME} configuration parameter, the + * factory configures the underlying file system appropriately for the {@link + * com.google.common.jimfs.Configuration#forCurrentPlatform() current platform}. * - *

For better control over the underlying in-memory file system, consider using the {@link - * JimfsTempDir} composed annotation and its {@link JimfsTempDir#value() value} attribute. + *

For better control over the underlying in-memory file system, consider using one of the + * following options: + * + *

* *

Please note that only annotated fields or parameters of type {@link java.nio.file.Path} are * supported as Jimfs is a non-default file system, and {@link java.io.File} instances are * associated with the default file system only. * - * @see Jimfs#newFileSystem(Configuration) - * @see Configuration#forCurrentPlatform() + * @see Jimfs#newFileSystem(com.google.common.jimfs.Configuration) + * @see com.google.common.jimfs.Configuration#forCurrentPlatform() */ public final class JimfsTempDirFactory implements TempDirFactory { private static final String DEFAULT_PREFIX = "junit-"; - - @SuppressWarnings("unused") - private static final String DEFAULT_FACTORY_PROPERTY_NAME = - org.junit.jupiter.api.io.TempDir.DEFAULT_FACTORY_PROPERTY_NAME; + private static final Function CONFIGURATION_TRANSFORMER = + value -> JimfsTempDir.Configuration.valueOf(value.trim().toUpperCase(Locale.ROOT)); private FileSystem fileSystem; @@ -69,14 +76,27 @@ public Path createTempDirectory( Supplier configuration = annotation .map(JimfsTempDir::value) + .filter(JimfsTempDirFactory::isNotDefaultConfiguration) .map(JimfsTempDir.Configuration::getConfiguration) - .orElse(Configuration::forCurrentPlatform); + .orElseGet( + () -> + extensionContext + .getConfigurationParameter( + JimfsTempDir.DEFAULT_CONFIGURATION_PARAMETER_NAME, + CONFIGURATION_TRANSFORMER) + .filter(JimfsTempDirFactory::isNotDefaultConfiguration) + .map(JimfsTempDir.Configuration::getConfiguration) + .orElse(Configuration::forCurrentPlatform)); fileSystem = Jimfs.newFileSystem(configuration.get()); Path root = fileSystem.getRootDirectories().iterator().next(); return Files.createTempDirectory(root, DEFAULT_PREFIX); } + private static boolean isNotDefaultConfiguration(JimfsTempDir.Configuration value) { + return value != JimfsTempDir.Configuration.DEFAULT; + } + /** {@inheritDoc} */ @Override public void close() throws IOException { diff --git a/src/test/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirFactoryTests.java b/src/test/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirFactoryTests.java index e57bdee..f67d970 100644 --- a/src/test/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirFactoryTests.java +++ b/src/test/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirFactoryTests.java @@ -22,7 +22,6 @@ import static io.github.scordio.jimfs.junit.jupiter.Requirements.windowsFileSystem; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.condition.OS.MAC; -import static org.junit.jupiter.api.condition.OS.WINDOWS; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request; @@ -32,18 +31,22 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.junit.platform.testkit.engine.EngineExecutionResults; +@DisplayName("JimfsTempDirFactory") class JimfsTempDirFactoryTests { @Nested - @DisplayName("with @TempDir factory attribute") - class with_TempDir_factory_attribute { + @DisplayName("with @TempDir factory (annotation attribute)") + class with_TempDir_factory_annotation_attribute { @EnabledOnOs(MAC) @Test - void should_use_os_x_configuration() { + void should_apply_OS_X_configuration_on_Mac_platform() { executeTestsForClass(OsXTestCase.class) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); @@ -57,9 +60,9 @@ void test(@TempDir(factory = JimfsTempDirFactory.class) Path tempDir) { } } - @DisabledOnOs({MAC, WINDOWS}) + @DisabledOnOs({MAC, OS.WINDOWS}) @Test - void should_use_unix_configuration() { + void should_apply_UNIX_configuration_on_Unix_platform() { executeTestsForClass(UnixTestCase.class) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); @@ -73,9 +76,9 @@ void test(@TempDir(factory = JimfsTempDirFactory.class) Path tempDir) { } } - @EnabledOnOs(WINDOWS) + @EnabledOnOs(OS.WINDOWS) @Test - void should_use_windows_configuration() { + void should_apply_WINDOWS_configuration_on_Windows_platform() { executeTestsForClass(WindowsTestCase.class) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); @@ -91,8 +94,8 @@ void test(@TempDir(factory = JimfsTempDirFactory.class) Path tempDir) { } @Nested - @DisplayName("with @TempDir default factory configuration property") - class with_TempDir_default_factory_configuration_property { + @DisplayName("with @TempDir default factory (configuration parameter)") + class with_TempDir_default_factory_config_parameter { private static EngineExecutionResults executeTestsForClass(Class testClass) { return executeTests( @@ -105,7 +108,7 @@ private static EngineExecutionResults executeTestsForClass(Class testClass) { @EnabledOnOs(MAC) @Test - void should_use_os_x_configuration() { + void should_apply_OS_X_configuration_on_Mac_platform() { executeTestsForClass(OsXTestCase.class) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); @@ -119,9 +122,9 @@ void test(@TempDir Path tempDir) { } } - @DisabledOnOs({MAC, WINDOWS}) + @DisabledOnOs({MAC, OS.WINDOWS}) @Test - void should_use_unix_configuration() { + void should_apply_UNIX_configuration_on_Unix_platform() { executeTestsForClass(UnixTestCase.class) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); @@ -135,9 +138,9 @@ void test(@TempDir Path tempDir) { } } - @EnabledOnOs(WINDOWS) + @EnabledOnOs(OS.WINDOWS) @Test - void should_use_windows_configuration() { + void should_apply_WINDOWS_configuration_on_Windows_platform() { executeTestsForClass(WindowsTestCase.class) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); @@ -151,4 +154,129 @@ void test(@TempDir Path tempDir) { } } } + + @Nested + @DisplayName("with Jimfs default configuration (configuration parameter)") + class with_Jimfs_default_configuration_config_parameter { + + private static EngineExecutionResults executeTestsForClass( + Class testClass, String configuration) { + return executeTests( + request() + .selectors(selectClass(testClass)) + .configurationParameter( + TempDir.DEFAULT_FACTORY_PROPERTY_NAME, JimfsTempDirFactory.class.getName()) + .configurationParameter( + JimfsTempDir.DEFAULT_CONFIGURATION_PARAMETER_NAME, configuration) + .build()); + } + + @EnabledOnOs(MAC) + @ParameterizedTest + @ValueSource(strings = {"DEFAULT", "default"}) + void should_apply_OS_X_configuration_with_DEFAULT_parameter_on_Mac_platform( + String configuration) { + executeTestsForClass(OsXTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + @EnabledOnOs(MAC) + @ParameterizedTest + @ValueSource(strings = {"FOR_CURRENT_PLATFORM", "for_current_platform"}) + void should_apply_OS_X_configuration_with_FOR_CURRENT_PLATFORM_parameter_on_Mac_platform( + String configuration) { + executeTestsForClass(OsXTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + @ParameterizedTest + @ValueSource(strings = {"OS_X", "os_x"}) + void should_apply_OS_X_configuration_with_OS_X_parameter(String configuration) { + executeTestsForClass(OsXTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class OsXTestCase { + + @Test + void test(@TempDir Path tempDir) { + assertThat(tempDir).satisfies(osXFileSystem()); + } + } + + @DisabledOnOs({MAC, OS.WINDOWS}) + @ParameterizedTest + @ValueSource(strings = {"DEFAULT", "default"}) + void should_apply_UNIX_configuration_with_DEFAULT_parameter_on_Unix_platform( + String configuration) { + executeTestsForClass(UnixTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + @DisabledOnOs({MAC, OS.WINDOWS}) + @ParameterizedTest + @ValueSource(strings = {"FOR_CURRENT_PLATFORM", "for_current_platform"}) + void should_apply_UNIX_configuration_with_FOR_CURRENT_PLATFORM_parameter_on_Unix_platform( + String configuration) { + executeTestsForClass(UnixTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + @ParameterizedTest + @ValueSource(strings = {"UNIX", "unix"}) + void should_apply_UNIX_configuration_with_UNIX_parameter(String configuration) { + executeTestsForClass(UnixTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class UnixTestCase { + + @Test + void test(@TempDir Path tempDir) { + assertThat(tempDir).satisfies(unixFileSystem()); + } + } + + @EnabledOnOs(OS.WINDOWS) + @ParameterizedTest + @ValueSource(strings = {"DEFAULT", "default"}) + void should_apply_WINDOWS_configuration_with_DEFAULT_parameter_on_Windows_platform( + String configuration) { + executeTestsForClass(WindowsTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + @EnabledOnOs(OS.WINDOWS) + @ParameterizedTest + @ValueSource(strings = {"FOR_CURRENT_PLATFORM", "for_current_platform"}) + void should_apply_WINDOWS_configuration_with_FOR_CURRENT_PLATFORM_parameter_on_Windows_platform( + String configuration) { + executeTestsForClass(WindowsTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + @ParameterizedTest + @ValueSource(strings = {"WINDOWS", "windows"}) + void should_apply_WINDOWS_configuration_with_WINDOWS_parameter(String configuration) { + executeTestsForClass(WindowsTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class WindowsTestCase { + + @Test + void test(@TempDir Path tempDir) { + assertThat(tempDir).satisfies(windowsFileSystem()); + } + } + } } diff --git a/src/test/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirTests.java b/src/test/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirTests.java index c2cb71d..d25d8d7 100644 --- a/src/test/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirTests.java +++ b/src/test/java/io/github/scordio/jimfs/junit/jupiter/JimfsTempDirTests.java @@ -15,183 +15,326 @@ */ package io.github.scordio.jimfs.junit.jupiter; +import static io.github.scordio.jimfs.junit.jupiter.JimfsTempDir.Configuration.DEFAULT; import static io.github.scordio.jimfs.junit.jupiter.JimfsTempDir.Configuration.FOR_CURRENT_PLATFORM; import static io.github.scordio.jimfs.junit.jupiter.JimfsTempDir.Configuration.OS_X; import static io.github.scordio.jimfs.junit.jupiter.JimfsTempDir.Configuration.UNIX; import static io.github.scordio.jimfs.junit.jupiter.JimfsTempDir.Configuration.WINDOWS; +import static io.github.scordio.jimfs.junit.jupiter.JimfsTempDir.DEFAULT_CONFIGURATION_PARAMETER_NAME; +import static io.github.scordio.jimfs.junit.jupiter.JupiterEngineTestKit.executeTests; import static io.github.scordio.jimfs.junit.jupiter.JupiterEngineTestKit.executeTestsForClass; import static io.github.scordio.jimfs.junit.jupiter.Requirements.osXFileSystem; import static io.github.scordio.jimfs.junit.jupiter.Requirements.unixFileSystem; import static io.github.scordio.jimfs.junit.jupiter.Requirements.windowsFileSystem; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.condition.OS.MAC; +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; +import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request; import java.nio.file.Path; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.condition.OS; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.junit.platform.testkit.engine.EngineExecutionResults; +@DisplayName("JimfsTempDir") class JimfsTempDirTests { @Nested - class With_Default_Configuration { + @DisplayName("without configuration parameters") + class without_config_parameters { - @EnabledOnOs(MAC) - @Test - void should_use_os_x_configuration() { - executeTestsForClass(OsXTestCase.class) - .testEvents() - .assertStatistics(stats -> stats.started(1).succeeded(1)); - } + @Nested + class with_DEFAULT_configuration { - static class OsXTestCase { + @EnabledOnOs(MAC) + @Test + void should_apply_OS_X_configuration_on_Mac_platform() { + executeTestsForClass(OsXTestCase.class) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class OsXTestCase { + + @Test + void test(@JimfsTempDir Path tempDir1, @JimfsTempDir(DEFAULT) Path tempDir2) { + assertThat(tempDir1).satisfies(osXFileSystem()); + assertThat(tempDir2).satisfies(osXFileSystem()); + } + } + + @DisabledOnOs({MAC, OS.WINDOWS}) + @Test + void should_apply_UNIX_configuration_on_Unix_platform() { + executeTestsForClass(UnixTestCase.class) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class UnixTestCase { + + @Test + void test(@JimfsTempDir Path tempDir1, @JimfsTempDir(DEFAULT) Path tempDir2) { + assertThat(tempDir1).satisfies(unixFileSystem()); + assertThat(tempDir2).satisfies(unixFileSystem()); + } + } + @EnabledOnOs(OS.WINDOWS) @Test - void test(@JimfsTempDir Path tempDir) { - assertThat(tempDir).satisfies(osXFileSystem()); + void should_apply_WINDOWS_configuration_on_Windows_platform() { + executeTestsForClass(WindowsTestCase.class) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class WindowsTestCase { + + @Test + void test(@JimfsTempDir Path tempDir1, @JimfsTempDir(DEFAULT) Path tempDir2) { + assertThat(tempDir1).satisfies(windowsFileSystem()); + assertThat(tempDir2).satisfies(windowsFileSystem()); + } } } - @DisabledOnOs({MAC, OS.WINDOWS}) - @Test - void should_use_unix_configuration() { - executeTestsForClass(UnixTestCase.class) - .testEvents() - .assertStatistics(stats -> stats.started(1).succeeded(1)); + @Nested + class with_FOR_CURRENT_PLATFORM_configuration { + + @EnabledOnOs(MAC) + @Test + void should_apply_OS_X_configuration_on_Mac_platform() { + executeTestsForClass(OsXTestCase.class) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class OsXTestCase { + + @Test + void test(@JimfsTempDir(FOR_CURRENT_PLATFORM) Path tempDir) { + assertThat(tempDir).satisfies(osXFileSystem()); + } + } + + @DisabledOnOs({MAC, OS.WINDOWS}) + @Test + void should_apply_UNIX_configuration_on_Unix_platform() { + executeTestsForClass(UnixTestCase.class) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class UnixTestCase { + + @Test + void test(@JimfsTempDir(FOR_CURRENT_PLATFORM) Path tempDir) { + assertThat(tempDir).satisfies(unixFileSystem()); + } + } + + @EnabledOnOs(OS.WINDOWS) + @Test + void should_apply_WINDOWS_configuration_on_Windows_platform() { + executeTestsForClass(WindowsTestCase.class) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class WindowsTestCase { + + @Test + void test(@JimfsTempDir(FOR_CURRENT_PLATFORM) Path tempDir) { + assertThat(tempDir).satisfies(windowsFileSystem()); + } + } } - static class UnixTestCase { + @Nested + class with_OS_X_configuration { @Test - void test(@JimfsTempDir Path tempDir) { - assertThat(tempDir).satisfies(unixFileSystem()); + void should_apply_OS_X_configuration() { + executeTestsForClass(TestCase.class) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class TestCase { + + @Test + void test(@JimfsTempDir(OS_X) Path tempDir) { + assertThat(tempDir).satisfies(osXFileSystem()); + } } } - @EnabledOnOs(OS.WINDOWS) - @Test - void should_use_windows_configuration() { - executeTestsForClass(WindowsTestCase.class) - .testEvents() - .assertStatistics(stats -> stats.started(1).succeeded(1)); + @Nested + class with_UNIX_configuration { + + @Test + void should_apply_UNIX_configuration() { + executeTestsForClass(TestCase.class) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class TestCase { + + @Test + void test(@JimfsTempDir(UNIX) Path tempDir) { + assertThat(tempDir).satisfies(unixFileSystem()); + } + } } - static class WindowsTestCase { + @Nested + class with_WINDOWS_configuration { @Test - void test(@JimfsTempDir Path tempDir) { - assertThat(tempDir).satisfies(windowsFileSystem()); + void should_apply_WINDOWS_configuration_with_WINDOWS_value() { + executeTestsForClass(TestCase.class) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); + } + + static class TestCase { + + @Test + void test(@JimfsTempDir(WINDOWS) Path tempDir) { + assertThat(tempDir).satisfies(windowsFileSystem()); + } } } } @Nested - class With_FOR_CURRENT_PLATFORM_Configuration { + @DisplayName("with Jimfs default configuration (configuration parameter)") + class with_Jimfs_default_configuration_config_parameter { + + private static EngineExecutionResults executeTestsForClass( + Class testClass, String configuration) { + return executeTests( + request() + .selectors(selectClass(testClass)) + .configurationParameter(DEFAULT_CONFIGURATION_PARAMETER_NAME, configuration) + .build()); + } @EnabledOnOs(MAC) - @Test - void should_use_os_x_configuration() { - executeTestsForClass(OsXTestCase.class) + @ParameterizedTest + @ValueSource(strings = {"DEFAULT", "default"}) + void should_apply_OS_X_configuration_with_DEFAULT_parameter_on_Mac_platform( + String configuration) { + executeTestsForClass(OsXTestCase.class, configuration) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); } - static class OsXTestCase { - - @Test - void test(@JimfsTempDir(FOR_CURRENT_PLATFORM) Path tempDir) { - assertThat(tempDir).satisfies(osXFileSystem()); - } + @EnabledOnOs(MAC) + @ParameterizedTest + @ValueSource(strings = {"FOR_CURRENT_PLATFORM", "for_current_platform"}) + void should_apply_OS_X_configuration_with_FOR_CURRENT_PLATFORM_parameter_on_Mac_platform( + String configuration) { + executeTestsForClass(OsXTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); } - @DisabledOnOs({MAC, OS.WINDOWS}) - @Test - void should_use_unix_configuration() { - executeTestsForClass(UnixTestCase.class) + @ParameterizedTest + @ValueSource(strings = {"OS_X", "os_x"}) + void should_apply_OS_X_configuration_with_OS_X_parameter(String configuration) { + executeTestsForClass(OsXTestCase.class, configuration) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); } - static class UnixTestCase { + static class OsXTestCase { @Test - void test(@JimfsTempDir(FOR_CURRENT_PLATFORM) Path tempDir) { - assertThat(tempDir).satisfies(unixFileSystem()); + void test(@JimfsTempDir Path tempDir1, @JimfsTempDir(DEFAULT) Path tempDir2) { + assertThat(tempDir1).satisfies(osXFileSystem()); + assertThat(tempDir2).satisfies(osXFileSystem()); } } - @EnabledOnOs(OS.WINDOWS) - @Test - void should_use_windows_configuration() { - executeTestsForClass(WindowsTestCase.class) + @DisabledOnOs({MAC, OS.WINDOWS}) + @ParameterizedTest + @ValueSource(strings = {"DEFAULT", "default"}) + void should_apply_UNIX_configuration_with_DEFAULT_parameter_on_Unix_platform( + String configuration) { + executeTestsForClass(UnixTestCase.class, configuration) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); } - static class WindowsTestCase { - - @Test - void test(@JimfsTempDir(FOR_CURRENT_PLATFORM) Path tempDir) { - assertThat(tempDir).satisfies(windowsFileSystem()); - } + @DisabledOnOs({MAC, OS.WINDOWS}) + @ParameterizedTest + @ValueSource(strings = {"FOR_CURRENT_PLATFORM", "for_current_platform"}) + void should_apply_UNIX_configuration_with_FOR_CURRENT_PLATFORM_parameter_on_Unix_platform( + String configuration) { + executeTestsForClass(UnixTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); } - } - @Nested - class With_OS_X_Configuration { - - @Test - void should_use_os_x_configuration() { - executeTestsForClass(TestCase.class) + @ParameterizedTest + @ValueSource(strings = {"UNIX", "unix"}) + void should_apply_UNIX_configuration_with_UNIX_parameter(String configuration) { + executeTestsForClass(UnixTestCase.class, configuration) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); } - static class TestCase { + static class UnixTestCase { @Test - void test(@JimfsTempDir(OS_X) Path tempDir) { - assertThat(tempDir).satisfies(osXFileSystem()); + void test(@JimfsTempDir Path tempDir1, @JimfsTempDir(DEFAULT) Path tempDir2) { + assertThat(tempDir1).satisfies(unixFileSystem()); + assertThat(tempDir2).satisfies(unixFileSystem()); } } - } - - @Nested - class With_UNIX_Configuration { - @Test - void should_use_os_x_configuration() { - executeTestsForClass(TestCase.class) + @EnabledOnOs(OS.WINDOWS) + @ParameterizedTest + @ValueSource(strings = {"DEFAULT", "default"}) + void should_apply_WINDOWS_configuration_with_DEFAULT_parameter_on_Windows_platform( + String configuration) { + executeTestsForClass(WindowsTestCase.class, configuration) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); } - static class TestCase { - - @Test - void test(@JimfsTempDir(UNIX) Path tempDir) { - assertThat(tempDir).satisfies(unixFileSystem()); - } + @EnabledOnOs(OS.WINDOWS) + @ParameterizedTest + @ValueSource(strings = {"FOR_CURRENT_PLATFORM", "for_current_platform"}) + void should_apply_WINDOWS_configuration_with_FOR_CURRENT_PLATFORM_parameter_on_Windows_platform( + String configuration) { + executeTestsForClass(WindowsTestCase.class, configuration) + .testEvents() + .assertStatistics(stats -> stats.started(1).succeeded(1)); } - } - @Nested - class With_WINDOWS_Configuration { - - @Test - void should_use_windows_configuration() { - executeTestsForClass(TestCase.class) + @ParameterizedTest + @ValueSource(strings = {"WINDOWS", "windows"}) + void should_apply_WINDOWS_configuration_with_WINDOWS_parameter(String configuration) { + executeTestsForClass(WindowsTestCase.class, configuration) .testEvents() .assertStatistics(stats -> stats.started(1).succeeded(1)); } - static class TestCase { + static class WindowsTestCase { @Test - void test(@JimfsTempDir(WINDOWS) Path tempDir) { - assertThat(tempDir).satisfies(windowsFileSystem()); + void test(@JimfsTempDir Path tempDir1, @JimfsTempDir(DEFAULT) Path tempDir2) { + assertThat(tempDir1).satisfies(windowsFileSystem()); + assertThat(tempDir2).satisfies(windowsFileSystem()); } } }