From 2def128c0ad247f0e58d6c0d55eb1d3f7b7706fb Mon Sep 17 00:00:00 2001 From: Matt Baker Date: Mon, 24 Nov 2014 17:25:50 -0800 Subject: [PATCH] Make the README pretty --- README => README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) rename README => README.md (85%) 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.