diff --git a/README b/README.md similarity index 85% rename from README rename to README.md index 644b5a2..b9d2ddd 100644 --- a/README +++ b/README.md @@ -1,13 +1,13 @@ +#HitchFS + +##FakeFile The purpose of FakeFile is to provide an easy way to test file system operations in Java (particularly those in java.io.File) as safely as possible. The primary benefits are: - - Dangerous file operations, such as delete, are limited to the behavior - that you define in your tests. This helps prevent bugs from performing - accidental damage, and is especially useful when working with someone else's - code or library. - + * Dangerous file operations, such as delete, are limited to the behavior that you define in your tests. This helps prevent bugs from performing accidental damage, and is especially useful when working with someone else's code or library. + ```java // Example StubFileSystem fs = new StubFileSystem() { @Override @@ -17,14 +17,16 @@ The primary benefits are: }; FakeFile fake = fs.file("something-critical.txt"); fake.delete(); // causes the RuntimeException to be thrown. + ``` - - I/O operations are costly, and wasteful in tests. The should be avoided as + * I/O operations are costly, and wasteful in tests. The should be avoided as much as possible, but at the same time, reading/writing files is likely one of the most critical operations for your application to do correctly, and requires significant testing. FakeFile allows you to test while redirecting to in-memory objects such as ByteArrayInputStream or writing to a MessageDigestOutputStream and just verifying an md5 sum in your test: - + + ```java // Reading Example final String expected = "this is some text in memory."; StubFileSystem fs = new StubFileSystem() { @@ -53,7 +55,7 @@ The primary benefits are: writer.write("fake file with text."); writer.close(); assertEquals("9d2110c9a94894f10cfee35afaf8ceb2", md5.getDigestAsHex()); - + ``` Then, when you're in your real application, just use DefaultFileSystem to get the real Java implementations of File, File Streams, and File Reader/Writers.