Class FilesystemExtension
java.lang.Object
nl.pim16aap2.testing.extensions.FilesystemExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.TestInstantiationAwareExtension, org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
public class FilesystemExtension
extends Object
implements org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider, org.junit.jupiter.api.extension.ParameterResolver
A JUnit 5 extension to run filesystem tests across multiple platform configurations.
This extension automatically runs tests against Unix, Windows, and macOS filesystem configurations using Google's
Jimfs in-memory filesystem. Each test method annotated with FileSystemTest will be executed once for each
platform configuration.
To use this extension, annotated your test method with FileSystemTest. The extension can inject either a
FileSystem or Path parameter into your test methods:
FileSystem- provides access to the configured filesystem for that test invocationPath- provides a root path within the configured filesystem
Example usage:
class MyFileSystemTest {
@FileSystemTest
void testWithFileSystem(FileSystem fs) {
Path testDir = fs.getPath("test");
Files.createDirectory(testDir);
assertTrue(Files.exists(testDir));
}
@FileSystemTest
void testWithPath(Path rootPath) {
...
}
@FileSystemTest
void testWithBoth(FileSystem fs, Path rootPath) {
...
}
}
The filesystem is automatically created before each test invocation and closed after each test to ensure test isolation.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionStream<org.junit.jupiter.api.extension.TestTemplateInvocationContext> provideTestTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext context) resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) booleansupportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) booleansupportsTestTemplate(org.junit.jupiter.api.extension.ExtensionContext context) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScopeMethods inherited from interface org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
mayReturnZeroTestTemplateInvocationContexts
-
Constructor Details
-
FilesystemExtension
public FilesystemExtension()
-
-
Method Details
-
supportsTestTemplate
public boolean supportsTestTemplate(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
supportsTestTemplatein interfaceorg.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
-
provideTestTemplateInvocationContexts
public Stream<org.junit.jupiter.api.extension.TestTemplateInvocationContext> provideTestTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
provideTestTemplateInvocationContextsin interfaceorg.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
supportsParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-