1- # Jimfs JUnit Jupiter [ ![ Maven Central] ( https://img.shields.io/maven-central/v/io.github.scordio/jimfs-junit-jupiter?label=Maven%20Central )] ( https://mvnrepository .com/artifact/io.github.scordio/jimfs-junit-jupiter ) [ ![ javadoc] ( https://javadoc.io/badge2/io.github.scordio/jimfs-junit-jupiter/javadoc.svg )] ( https://javadoc.io/doc/io.github.scordio/jimfs-junit-jupiter )
1+ # Jimfs JUnit Jupiter [ ![ Maven Central] ( https://img.shields.io/maven-central/v/io.github.scordio/jimfs-junit-jupiter?label=Maven%20Central )] ( https://central.sonatype .com/artifact/io.github.scordio/jimfs-junit-jupiter ) [ ![ javadoc] ( https://javadoc.io/badge2/io.github.scordio/jimfs-junit-jupiter/javadoc.svg )] ( https://javadoc.io/doc/io.github.scordio/jimfs-junit-jupiter )
22
33[ ![ CI] ( https://github.com/scordio/jimfs-junit-jupiter/actions/workflows/main.yml/badge.svg?branch=main )] ( https://github.com/scordio/jimfs-junit-jupiter/actions/workflows/main.yml?query=branch%3Amain )
44
5- This project provides a [ JUnit Jupiter] [ ] extension for in-memory
6- [ ` @TempDir ` ] ( https://junit.org/junit5/docs/ current/api/org.junit.jupiter.api/org/junit/jupiter/api/io/TempDir.html )
7- directories using the [ Jimfs] [ ] file system.
5+ This project provides a [ JUnit Jupiter] ( https://junit.org/ ) extension for in-memory
6+ [ ` @TempDir ` ] ( https://docs. junit.org/current/api/org.junit.jupiter.api/org/junit/jupiter/api/io/TempDir.html ) directories
7+ using the [ Jimfs] ( https://github.com/google/jimfs ) file system.
88
9- ## Getting Started
9+ ## Documentation
1010
11- ### Compatibility
12-
13- Jimfs JUnit Jupiter is based on JUnit Jupiter 5 and requires Java 8 or higher.
14-
15- Compatibility is guaranteed only with the JUnit Jupiter versions from
16- [ 5.10.0] ( https://junit.org/junit5/docs/5.10.0/release-notes/index.html )
17- to the
18- [ latest] ( https://junit.org/junit5/docs/current/release-notes/index.html ) .
19-
20- ### Maven
21-
22- ``` xml
23- <dependency >
24- <groupId >io.github.scordio</groupId >
25- <artifactId >jimfs-junit-jupiter</artifactId >
26- <version >${jimfs-junit-jupiter.version}</version >
27- <scope >test</scope >
28- </dependency >
29- ```
30-
31- ### Gradle
32-
33- ``` kotlin
34- testImplementation(" io.github.scordio:jimfs-junit-jupiter:${jimfsJunitJupiterVersion} " )
35- ```
36-
37- ## JimfsTempDirFactory
38-
39- The simplest usage is to set the
40- [ ` factory ` ] ( https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/io/TempDir.html#factory() )
41- attribute of ` @TempDir ` to ` JimfsTempDirFactory ` :
42-
43- ``` java
44- @Test
45- void test(@TempDir (factory = JimfsTempDirFactory . class) Path tempDir) {
46- assertThat(tempDir. getFileSystem(). provider(). getScheme()). isEqualTo(" jimfs" );
47- }
48- ```
49-
50- ` tempDir ` is resolved to an in-memory temporary directory based on Jimfs, configured appropriately for the current
51- platform.
52-
53- ## @JimfsTempDir
54-
55- ` @JimfsTempDir ` is an annotation that can be used as a drop-in replacement for
56- ` @TempDir(factory = JimfsTempDirFactory.class) ` :
57-
58- ``` java
59- @Test
60- void test(@JimfsTempDir Path tempDir) {
61- assertThat(tempDir. getFileSystem(). provider(). getScheme()). isEqualTo(" jimfs" );
62- }
63- ```
64-
65- The default behavior of the annotation is equivalent to using ` JimfsTempDirFactory ` directly: ` tempDir ` is resolved to
66- an in-memory temporary directory based on Jimfs, configured appropriately for the current platform.
67-
68- For better control over the underlying in-memory file system, ` @JimfsTempDir ` offers an optional ` value ` attribute
69- that can be set to the desired configuration, one of:
70- * ` DEFAULT ` : based on the corresponding [ configuration parameter] ( #default-jimfs-configuration ) (default)
71- * ` FOR_CURRENT_PLATFORM ` : appropriate to the current platform
72- * ` OS_X ` : for a Mac OS X-like file system
73- * ` UNIX ` : for a UNIX-like file system
74- * ` WINDOWS ` : for a Windows-like file system
75-
76- For example, the following defines a Windows-like temporary directory, regardless of the platform on which the test is
77- running:
78-
79- ``` java
80- @Test
81- void test(@JimfsTempDir (WINDOWS ) Path tempDir) {
82- assertThat(tempDir. getFileSystem(). getSeparator()). isEqualTo(" \\ " );
83- }
84- ```
85-
86- ## Configuration Parameters
87-
88- Jimfs JUnit Jupiter supports JUnit
89- [ configuration parameters] ( https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params ) .
90-
91- ### Default ` @TempDir ` Factory
92-
93- The ` junit.jupiter.tempdir.factory.default ` configuration parameter sets the default factory to use, expecting a fully
94- qualified class name.
95-
96- For example, the following configures ` JimfsTempDirFactory ` :
97-
98- ``` properties
99- junit.jupiter.tempdir.factory.default =io.github.scordio.jimfs.junit.jupiter.JimfsTempDirFactory
100- ```
101-
102- The factory will be used for all ` @TempDir ` annotations unless the annotation's ` factory ` attribute specifies a
103- different type.
104-
105- ### Default Jimfs Configuration
106-
107- The ` jimfs.junit.jupiter.tempdir.configuration.default ` configuration parameter sets the default Jimfs configuration to
108- use. It expects one of the following values (case-insensitive):
109- * ` FOR_CURRENT_PLATFORM ` : appropriate to the current platform (default)
110- * ` OS_X ` : for a Mac OS X-like file system
111- * ` UNIX ` : for a UNIX-like file system
112- * ` WINDOWS ` : for a Windows-like file system
113-
114- For example, the following defines a Windows-like temporary directory, regardless of the platform on which the test is
115- running:
116-
117- ``` properties
118- jimfs.junit.jupiter.tempdir.configuration.default =windows
119- ```
120-
121- All Jimfs-based temporary directories will be configured accordingly unless ` @JimfsTempDir ` is used with
122- its ` value ` attribute set.
123-
124- ## Limitations
125-
126- Jimfs JUnit Jupiter only supports annotated fields or parameters of type ` Path ` , since Jimfs is a non-default file
127- system and ` File ` instances can only be associated with the default file system.
128-
129- In addition, compared to the configuration options that Jimfs provides, Jimfs JUnit Jupiter offers a simplified
130- interface to keep usage straightforward.
131-
132- In case something is missing for your use case, please [ raise an issue] ( ../../issues/new ) !
11+ - [ User Guide] ( https://scordio.github.io/jimfs-junit-jupiter/ )
12+ - [ Release Notes] ( ../../releases )
13313
13414## Motivation
13515
13616It is currently possible to use Jimfs and JUnit Jupiter together to create in-memory temporary directories for testing.
137- However, this requires Jimfs in-memory file system handling to be integrated with JUnit Jupiter test lifecycle callbacks,
138- boilerplate code that users must implement themselves.
17+ However, this requires Jimfs in-memory file system handling to be integrated with JUnit Jupiter test lifecycle
18+ callbacks, boilerplate code that users must implement themselves.
13919
14020Starting from version 5.10, JUnit Jupiter offers a
14121[ ` TempDirFactory ` SPI] ( https://junit.org/junit5/docs/5.10.0/user-guide/#writing-tests-built-in-extensions-TempDirectory )
@@ -149,8 +29,4 @@ likely be discontinued if Google ever provides official support for this integra
14929
15030## License
15131
152- Jimfs JUnit Jupiter is released under version 2.0 of the [ Apache License] [ ] .
153-
154- [ Apache License ] : https://www.apache.org/licenses/LICENSE-2.0
155- [ Jimfs ] : https://github.com/google/jimfs
156- [ JUnit Jupiter ] : https://github.com/junit-team/junit-framework
32+ Jimfs JUnit Jupiter is released under version 2.0 of the [ Apache License] ( https://www.apache.org/licenses/LICENSE-2.0 ) .
0 commit comments