KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.mockobjects.io;
2
3 import alt.java.io.File;
4 import alt.java.io.IOFactory;
5 import com.mockobjects.ExpectationValue;
6 import com.mockobjects.MockObject;
7 import com.mockobjects.ReturnValue;
8 import com.mockobjects.ReturnObjectBag;
9
10 import java.io.FileNotFoundException JavaDoc;
11 import java.io.InputStream JavaDoc;
12 import java.io.OutputStream JavaDoc;
13
14 public class MockIOFactory extends MockObject implements IOFactory {
15     private final ReturnObjectBag inputStream = new ReturnObjectBag("input stream");
16     private final ReturnObjectBag outputStream = new ReturnObjectBag("output stream");
17     private final ReturnValue file = new ReturnValue("file");
18     private final ExpectationValue fileName = new ExpectationValue("file name");
19
20
21     public void setupInputStream(File expectedFile, InputStream JavaDoc returnStream) {
22         this.inputStream.putObjectToReturn(expectedFile, returnStream);
23     }
24
25     public InputStream JavaDoc createInputStream(File aFile) throws FileNotFoundException JavaDoc {
26         return (InputStream JavaDoc)inputStream.getNextReturnObject(aFile);
27     }
28
29     public void setupOutputStream(File expectedFile, OutputStream JavaDoc returnStream) {
30         this.outputStream.putObjectToReturn(expectedFile, outputStream);
31     }
32
33     public OutputStream JavaDoc createOutputStream(File aFile) throws FileNotFoundException JavaDoc {
34         return (OutputStream JavaDoc)outputStream.getNextReturnObject(aFile);
35     }
36
37     public void setupCreateFile(File file) {
38         this.file.setValue(file);
39     }
40
41     public void setExpectedFileName(String JavaDoc fileName){
42         this.fileName.setExpected(fileName);
43     }
44
45     public File createFile(String JavaDoc fileName) {
46         this.fileName.setActual(fileName);
47         return (File)file.getValue();
48     }
49 }
50
Popular Tags