KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > ozoneDB > tools > OPP > srcgen > streamfactory > MockInputStreamFactory


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by Joakim Ohlrogge are
5
// Copyright (C) 1997-@year@ by Joakim Ohlrogge. All rights reserved.
6
//
7
// $Id$
8
package test.ozoneDB.tools.OPP.srcgen.streamfactory;
9
10 import com.mockobjects.Verifiable;
11 import com.mockobjects.ExpectationMap;
12 import com.mockobjects.util.Verifier;
13 import org.ozoneDB.tools.OPP.srcgen.streamfactory.InputStreamFactory;
14
15 import java.io.InputStream JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.io.ByteArrayInputStream JavaDoc;
18
19 /**
20  * User: Jocke
21  * Date: 2004-jan-03
22  * Time: 14:28:16
23  */

24 public class MockInputStreamFactory implements InputStreamFactory, Verifiable {
25     ExpectationMap instanceReturnValues = new ExpectationMap("expected data");
26
27     /**
28      * Use this method to setup each expected return value for the given class name.
29      * The values are returned by key in the order they are added for each key. If you want a value to
30      * be returned twice, set it up twice.
31      * @param className The name of the class that the data is for
32      * @param data The data to return
33      */

34     public void setupNewInstanceReturnValue(String JavaDoc className, byte data[]) {
35         instanceReturnValues.addExpected(className, data);
36     }
37
38     /**
39      * Use this method to setup each expected return value for the given class name.
40      * The values are returned by key in the order they are added for each key. If you want a value to
41      * be returned twice, set it up twice.
42      * @param className The name of the class that the data is for
43      * @param data The data to return
44      */

45     public void setupNewInstanceReturnValue(String JavaDoc className, String JavaDoc data) {
46         setupNewInstanceReturnValue(className, data.getBytes());
47     }
48
49     public InputStream JavaDoc newInstance(String JavaDoc className) throws IOException JavaDoc {
50         InputStream JavaDoc is = new ByteArrayInputStream JavaDoc((byte[]) instanceReturnValues.get(className));
51         return is;
52     }
53
54     public void verify() {
55         Verifier.verifyObject(this);
56     }
57 }
58
Popular Tags