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 ; 11 import java.io.InputStream ; 12 import java.io.OutputStream ; 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 returnStream) { 22 this.inputStream.putObjectToReturn(expectedFile, returnStream); 23 } 24 25 public InputStream createInputStream(File aFile) throws FileNotFoundException { 26 return (InputStream )inputStream.getNextReturnObject(aFile); 27 } 28 29 public void setupOutputStream(File expectedFile, OutputStream returnStream) { 30 this.outputStream.putObjectToReturn(expectedFile, outputStream); 31 } 32 33 public OutputStream createOutputStream(File aFile) throws FileNotFoundException { 34 return (OutputStream )outputStream.getNextReturnObject(aFile); 35 } 36 37 public void setupCreateFile(File file) { 38 this.file.setValue(file); 39 } 40 41 public void setExpectedFileName(String fileName){ 42 this.fileName.setExpected(fileName); 43 } 44 45 public File createFile(String fileName) { 46 this.fileName.setActual(fileName); 47 return (File)file.getValue(); 48 } 49 } 50 | Popular Tags |