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 ; 9 import java.io.FilenameFilter ; 10 import java.io.FileFilter ; 11 import java.net.URL ; 12 import java.net.MalformedURLException ; 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 name) { 32 this.fileName.setValue(name); 33 } 34 35 public String getName() { 36 return (String ) fileName.getValue(); 37 } 38 39 public void setupGetParent(final String aParent) { 40 myParent.setValue(aParent); 41 } 42 43 public String getParent() { 44 return (String ) 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 prefix, String suffix, File directory) throws IOException { 56 notImplemented(); 57 return null; 58 } 59 60 public File createTempFile(String prefix, String suffix) throws IOException { 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 aPath) { 71 myPath.setValue(aPath); 72 } 73 74 public String getPath() { 75 return (String )myPath.getValue(); 76 } 77 78 public boolean isAbsolute() { 79 notImplemented(); 80 return false; 81 } 82 83 public void setupGetAbsolutePath(String absolutePath) { 84 this.absolutePath.setValue(absolutePath); 85 } 86 87 public String getAbsolutePath() { 88 return (String )absolutePath.getValue(); 89 } 90 91 public File getAbsoluteFile() { 92 notImplemented(); 93 return null; 94 } 95 96 public String getCanonicalPath() throws IOException { 97 notImplemented(); 98 return null; 99 } 100 101 public File getCanonicalFile() throws IOException { 102 notImplemented(); 103 return null; 104 } 105 106 public URL toURL() throws MalformedURLException { 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 { 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 [] list() { 169 notImplemented(); 170 return new String [0]; 171 } 172 173 public String [] list(FilenameFilter filter) { 174 notImplemented(); 175 return new String [0]; 176 } 177 178 public File[] listFiles() { 179 notImplemented(); 180 return new File[0]; 181 } 182 183 public void setExpectedFilenameFilter(FilenameFilter aFilenameFilter) { 184 myFilenameFilter.setExpected(aFilenameFilter); 185 } 186 187 public void setupListFile(File[] aFilesToReturn) { 188 myFilesToReturn.setValue(aFilesToReturn); 189 } 190 191 public File[] listFiles(FilenameFilter aFilenameFilter) { 192 myFilenameFilter.setActual(aFilenameFilter); 193 return (File[]) myFilesToReturn.getValue(); 194 } 195 196 public File[] listFiles(FileFilter 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 o) { 237 notImplemented(); 238 return 0; 239 } 240 241 public void setupGetRealFile(java.io.File file) { 242 this.file.setValue(file); 243 } 244 245 public java.io.File getRealFile() { 246 return (java.io.File )file.getValue(); 247 } 248 249 } 250 | Popular Tags |