KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > io > MockFile


1 package com.mockobjects.io;
2
3 import com.mockobjects.MockObject;
4 import com.mockobjects.ExpectationValue;
5 import com.mockobjects.ReturnValue;
6 import com.mockobjects.ExpectationCounter;
7
8 import java.io.IOException JavaDoc;
9 import java.io.FilenameFilter JavaDoc;
10 import java.io.FileFilter JavaDoc;
11 import java.net.URL JavaDoc;
12 import java.net.MalformedURLException JavaDoc;
13
14 import alt.java.io.File;
15
16 public class MockFile extends MockObject implements File {
17
18     private final ExpectationValue myFilenameFilter =
19         new ExpectationValue("filename filter");
20     private final ReturnValue myParent = new ReturnValue("parent");
21     private final ReturnValue fileName = new ReturnValue("file name");
22     private final ReturnValue exists = new ReturnValue("exists");
23     private final ReturnValue mkdirs = new ReturnValue("mkdirs");
24     private final ReturnValue parentFile = new ReturnValue("parent file");
25     private final ExpectationCounter mkdirsCounter = new ExpectationCounter("mkdirs counter");
26     private final ReturnValue myFilesToReturn = new ReturnValue("files");
27     private final ReturnValue file = new ReturnValue("real file");
28     private final ReturnValue myPath = new ReturnValue("path");
29     private final ReturnValue absolutePath = new ReturnValue("absolute path");
30
31     public void setupGetName(final String JavaDoc name) {
32         this.fileName.setValue(name);
33     }
34
35     public String JavaDoc getName() {
36         return (String JavaDoc) fileName.getValue();
37     }
38
39     public void setupGetParent(final String JavaDoc aParent) {
40         myParent.setValue(aParent);
41     }
42
43     public String JavaDoc getParent() {
44         return (String JavaDoc) myParent.getValue();
45     }
46
47     public void setupGetParentFile(File parentFile) {
48         this.parentFile.setValue(parentFile);
49     }
50
51     public File getParentFile() {
52         return (File) parentFile.getValue();
53     }
54
55     public File createTempFile(String JavaDoc prefix, String JavaDoc suffix, File directory) throws IOException JavaDoc {
56         notImplemented();
57         return null;
58     }
59
60     public File createTempFile(String JavaDoc prefix, String JavaDoc suffix) throws IOException JavaDoc {
61         notImplemented();
62         return null;
63     }
64
65     public File[] listRoots() {
66         notImplemented();
67         return new File[0];
68     }
69
70     public void setupGetPath(String JavaDoc aPath) {
71         myPath.setValue(aPath);
72     }
73
74     public String JavaDoc getPath() {
75         return (String JavaDoc)myPath.getValue();
76     }
77
78     public boolean isAbsolute() {
79         notImplemented();
80         return false;
81     }
82
83     public void setupGetAbsolutePath(String JavaDoc absolutePath) {
84         this.absolutePath.setValue(absolutePath);
85     }
86
87     public String JavaDoc getAbsolutePath() {
88         return (String JavaDoc)absolutePath.getValue();
89     }
90
91     public File getAbsoluteFile() {
92         notImplemented();
93         return null;
94     }
95
96     public String JavaDoc getCanonicalPath() throws IOException JavaDoc {
97         notImplemented();
98         return null;
99     }
100
101     public File getCanonicalFile() throws IOException JavaDoc {
102         notImplemented();
103         return null;
104     }
105
106     public URL JavaDoc toURL() throws MalformedURLException JavaDoc {
107         notImplemented();
108         return null;
109     }
110
111     public boolean canRead() {
112         notImplemented();
113         return false;
114     }
115
116     public boolean canWrite() {
117         notImplemented();
118         return false;
119     }
120
121     public void setupExists(boolean exists) {
122         this.exists.setValue(exists);
123     }
124
125     public boolean exists() {
126         return exists.getBooleanValue();
127     }
128
129     public boolean isDirectory() {
130         notImplemented();
131         return false;
132     }
133
134     public boolean isFile() {
135         notImplemented();
136         return false;
137     }
138
139     public boolean isHidden() {
140         notImplemented();
141         return false;
142     }
143
144     public long lastModified() {
145         notImplemented();
146         return 0;
147     }
148
149     public long length() {
150         notImplemented();
151         return 0;
152     }
153
154     public boolean createNewFile() throws IOException JavaDoc {
155         notImplemented();
156         return false;
157     }
158
159     public boolean delete() {
160         notImplemented();
161         return false;
162     }
163
164     public void deleteOnExit() {
165         notImplemented();
166     }
167
168     public String JavaDoc[] list() {
169         notImplemented();
170         return new String JavaDoc[0];
171     }
172
173     public String JavaDoc[] list(FilenameFilter JavaDoc filter) {
174         notImplemented();
175         return new String JavaDoc[0];
176     }
177
178     public File[] listFiles() {
179         notImplemented();
180         return new File[0];
181     }
182
183     public void setExpectedFilenameFilter(FilenameFilter JavaDoc aFilenameFilter) {
184         myFilenameFilter.setExpected(aFilenameFilter);
185     }
186
187     public void setupListFile(File[] aFilesToReturn) {
188         myFilesToReturn.setValue(aFilesToReturn);
189     }
190
191     public File[] listFiles(FilenameFilter JavaDoc aFilenameFilter) {
192         myFilenameFilter.setActual(aFilenameFilter);
193         return (File[]) myFilesToReturn.getValue();
194     }
195
196     public File[] listFiles(FileFilter JavaDoc filter) {
197         notImplemented();
198         return new File[0];
199     }
200
201     public boolean mkdir() {
202         notImplemented();
203         return false;
204     }
205
206     public void setupMkdirs(boolean mkdirs, int count) {
207         mkdirsCounter.setExpected(count);
208         this.mkdirs.setValue(mkdirs);
209     }
210
211     public boolean mkdirs() {
212         mkdirsCounter.inc();
213         return mkdirs.getBooleanValue();
214     }
215
216     public boolean renameTo(File dest) {
217         notImplemented();
218         return false;
219     }
220
221     public boolean setLastModified(long time) {
222         notImplemented();
223         return false;
224     }
225
226     public boolean setReadOnly() {
227         notImplemented();
228         return false;
229     }
230
231     public int compareTo(File pathname) {
232         notImplemented();
233         return 0;
234     }
235
236     public int compareTo(Object JavaDoc o) {
237         notImplemented();
238         return 0;
239     }
240
241     public void setupGetRealFile(java.io.File JavaDoc file) {
242         this.file.setValue(file);
243     }
244
245     public java.io.File JavaDoc getRealFile() {
246         return (java.io.File JavaDoc)file.getValue();
247     }
248
249 }
250
Popular Tags