How can I create a class MockFile mimicking java.io.File w.r.t. file read and write? I using everywhere my own methods instead of new FileInputStream(....) and new FileOutputStream(....), so this part is no problem (I always delegate to the appropriate stream). The non-trivila part is the implementation of my MockFileInputStream and MockFileOutputStream in more complicated cases.
There's is no problem, when I first write to a file and then read it, I can simply use a ByteArrayOutputStream and so on. That's simple, but with interleaving reads and writes it can't work. Any better idea than writing my own version of ByteArrayOutputStream?
解决方案
I would use a real file and a real FileInputStream and FileOutputStream. Otherwise you're just exercising test code: pretty pointless really.