Initial commit
[squelch.git] / src / test / java / net / jaekl / squelch / util / FileMock.java
1 package net.jaekl.squelch.util;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.File;
5 import java.io.FileNotFoundException;
6 import java.io.InputStream;
7
8 public class FileMock extends File {
9         private static final long serialVersionUID = 1L;
10         
11         private byte[] m_content;
12
13         public FileMock(String filename) {
14                 super(filename);
15                 
16                 m_content = null;
17         }
18         
19         @Override
20         public boolean canRead() {
21                 return FileUtilMock.mock_getInst().mock_canRead(this);
22         }
23         
24         public InputStream mock_openStream() throws FileNotFoundException {
25                 if (null == m_content) {
26                         throw new FileNotFoundException(this.getAbsolutePath());
27                 }
28                 return new ByteArrayInputStream(m_content);
29         }
30         
31         public void mock_setContent(byte[] content) {
32                 m_content = content;
33         }
34 }