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 invocation
  • Path - 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Stream<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)
     
    boolean
    supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     
    boolean
    supportsTestTemplate(org.junit.jupiter.api.extension.ExtensionContext context)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    getTestInstantiationExtensionContextScope

    Methods 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:
      supportsTestTemplate in interface org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
    • provideTestTemplateInvocationContexts

      public Stream<org.junit.jupiter.api.extension.TestTemplateInvocationContext> provideTestTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      provideTestTemplateInvocationContexts in interface org.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:
      supportsParameter in interface org.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:
      resolveParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException