MockFs

FileSystem for simulating IOExceptions

Лицензия

Лицензия

Группа

Группа

com.aerse
Идентификатор

Идентификатор

mockfs
Последняя версия

Последняя версия

1.4
Дата

Дата

Тип

Тип

jar
Описание

Описание

MockFs
FileSystem for simulating IOExceptions
Ссылка на сайт

Ссылка на сайт

https://github.com/dernasherbrezon/mockfs
Система контроля версий

Система контроля версий

https://github.com/dernasherbrezon/mockfs

Скачать mockfs

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.aerse/mockfs/ -->
<dependency>
    <groupId>com.aerse</groupId>
    <artifactId>mockfs</artifactId>
    <version>1.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.aerse/mockfs/
implementation 'com.aerse:mockfs:1.4'
// https://jarcasting.com/artifacts/com.aerse/mockfs/
implementation ("com.aerse:mockfs:1.4")
'com.aerse:mockfs:jar:1.4'
<dependency org="com.aerse" name="mockfs" rev="1.4">
  <artifact name="mockfs" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.aerse', module='mockfs', version='1.4')
)
libraryDependencies += "com.aerse" % "mockfs" % "1.4"
[com.aerse/mockfs "1.4"]

Зависимости

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.10

Модули Проекта

Данный проект не имеет модулей.

About Build Status Quality Gate Status

Java FileSystem for simulating IOExceptions

Usage

  1. Add maven dependency:
<dependency>
  <groupId>com.aerse</groupId>
  <artifactId>mockfs</artifactId>
  <version>1.4</version>
</dependency>
  1. Ensure code is ready
  • Ensure java.nio.file.Path is used instead of java.io.File. FileSystem is available only for Path.
  • Ensure Path::resolve(...) is used instead of java.nio.file.Paths.get(...) or Path::of(...). The latter uses FileSystems.getDefault() instead of mocked
  • All Path should be created from the FileSystem using FileSystem::getPath(...) method.
  1. Setup the test

For example:

	@Test(expected = IOException.class)
	public void testFailingWrite() throws IOException {
		byte[] data = createSampleData();
		Path path = basePath.resolve(UUID.randomUUID().toString());
		mockFs.mock(path, new FailingByteChannelCallback(5));
		try (OutputStream w = Files.newOutputStream(path)) {
			w.write(data);
		}
	}

Features

  • MockFileSystem could transparently pass the data to the default FileSystem. Just use com.aerse.mockfs.NoOpByteChannelCallback:
   	FileSystem fs = FileSystems.getDefault();
   	MockFileSystem mockFs = new MockFileSystem(fs);
   	mockFs.mock(path, new NoOpByteChannelCallback());
  • Use com.aerse.mockfs.FailingByteChannelCallback for simulating IOExceptions after configurable number of bytes.
  • Mock read/write to every file in the directory. Just pass this directory to the com.aerse.mockfs.MockFileSystem::mock(directoryToMock, ...)

Версии библиотеки

Версия
1.4
1.2
1.1