{"id":20332535,"url":"https://github.com/dernasherbrezon/mockfs","last_synced_at":"2025-04-11T21:33:01.335Z","repository":{"id":57716563,"uuid":"181366287","full_name":"dernasherbrezon/mockfs","owner":"dernasherbrezon","description":"Java FileSystem for simulating IOExceptions","archived":false,"fork":false,"pushed_at":"2021-06-21T20:04:49.000Z","size":46,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T17:23:27.503Z","etag":null,"topics":["filesystem","java","jdk7","junit","mock","unit-testing"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dernasherbrezon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-14T20:39:12.000Z","updated_at":"2023-12-05T11:51:12.000Z","dependencies_parsed_at":"2022-09-26T21:31:38.616Z","dependency_job_id":null,"html_url":"https://github.com/dernasherbrezon/mockfs","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dernasherbrezon%2Fmockfs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dernasherbrezon%2Fmockfs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dernasherbrezon%2Fmockfs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dernasherbrezon%2Fmockfs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dernasherbrezon","download_url":"https://codeload.github.com/dernasherbrezon/mockfs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248482950,"owners_count":21111408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filesystem","java","jdk7","junit","mock","unit-testing"],"created_at":"2024-11-14T20:27:09.278Z","updated_at":"2025-04-11T21:33:01.299Z","avatar_url":"https://github.com/dernasherbrezon.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## About [![Build Status](https://travis-ci.com/dernasherbrezon/mockfs.svg?branch=master)](https://travis-ci.com/dernasherbrezon/mockfs) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=com.aerse%3Amockfs\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=com.aerse%3Amockfs)\n\nJava FileSystem for simulating IOExceptions\n\n## Usage\n\n1. Add maven dependency:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.aerse\u003c/groupId\u003e\n  \u003cartifactId\u003emockfs\u003c/artifactId\u003e\n  \u003cversion\u003e1.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n2. Ensure code is ready\n\n* Ensure `java.nio.file.Path` is used instead of `java.io.File`. FileSystem is available only for `Path`.\n* Ensure `Path::resolve(...)` is used instead of `java.nio.file.Paths.get(...)` or `Path::of(...)`. The latter uses `FileSystems.getDefault()` instead of mocked\n* All `Path` should be created from the FileSystem using `FileSystem::getPath(...)` method.\n\n3. Setup the test\n\nFor example:\n\n```java\n\t@Test(expected = IOException.class)\n\tpublic void testFailingWrite() throws IOException {\n\t\tbyte[] data = createSampleData();\n\t\tPath path = basePath.resolve(UUID.randomUUID().toString());\n\t\tmockFs.mock(path, new FailingByteChannelCallback(5));\n\t\ttry (OutputStream w = Files.newOutputStream(path)) {\n\t\t\tw.write(data);\n\t\t}\n\t}\n```\n\n## Features\n\n * MockFileSystem could transparently pass the data to the default FileSystem. Just use `com.aerse.mockfs.NoOpByteChannelCallback`:\n ```java\n\t\tFileSystem fs = FileSystems.getDefault();\n\t\tMockFileSystem mockFs = new MockFileSystem(fs);\n\t\tmockFs.mock(path, new NoOpByteChannelCallback());\n ```\n * Use `com.aerse.mockfs.FailingByteChannelCallback` for simulating IOExceptions after configurable number of bytes.\n * Mock read/write to every file in the directory. Just pass this directory to the `com.aerse.mockfs.MockFileSystem::mock(directoryToMock, ...)`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdernasherbrezon%2Fmockfs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdernasherbrezon%2Fmockfs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdernasherbrezon%2Fmockfs/lists"}