For unit testing, I’d like to use an in-memory filesystem (like jimfs) to setup the test environment. For this purpose, I registered a custom Converter<String, Path>
with @ConfigurationPropertiesBinding, but it does not work.
In my sample project I’m using Spring Boot 3.3.1 and Kotlin 2.0.0.
A Git-Repo with MRE can be found here: https://github.com/woolph/spring-boot-path-converter
For my purpose, I register a Converter<String, Path>
to return a Path
object created by the in-memory filesystem like this:
@Configuration
class TestFileSystemConfiguration {
@Bean
fun fileSystem(): FileSystem = Jimfs.newFileSystem(com.google.common.jimfs.Configuration.unix())
@Bean
@ConfigurationPropertiesBinding
fun fileSystemPathConverter(fileSystem: FileSystem): Converter<String, Path>
= FileSystemPathConverter(fileSystem)
class FileSystemPathConverter(
val fileSystem: FileSystem,
) : Converter<String, Path> {
override fun convert(source: String): Path {
return fileSystem.getPath(source)
}
}
}
I’d expect that a configuration resolving properities of type Path
would be assigned with an Path
object referring to the in-memory filesystem (instead of the FileSystems.getDefault()
)
@Configuration
@ConfigurationProperties("test.filesystem")
class TestConfiguration {
lateinit var path: Path
}
But this is not the case. Some other converter seems to take precedence over my custom one.
Researching the topic I stumbled upon similar issues, which apparently should be solved in Spring Boot 3.3.1. But this specific issue still persist. Can anybody tell me, how to do this?
WolfgangMayer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.