01: /**
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */package com.tc.config.schema.repository;
04:
05: import org.apache.xmlbeans.XmlObject;
06:
07: import java.util.ArrayList;
08: import java.util.List;
09:
10: /**
11: * A mock {@link ChildBeanFetcher}, for use in tests.
12: */
13: public class MockChildBeanFetcher implements ChildBeanFetcher {
14:
15: private int numGetChilds;
16: private XmlObject[] returnedChildren;
17: private int returnedChildrenPos;
18: private List lastParents;
19:
20: public MockChildBeanFetcher() {
21: this .returnedChildren = new XmlObject[] { null };
22: this .lastParents = new ArrayList();
23:
24: reset();
25: }
26:
27: public void reset() {
28: this .numGetChilds = 0;
29: this .returnedChildrenPos = 0;
30: this .lastParents.clear();
31: }
32:
33: public XmlObject getChild(XmlObject parent) {
34: ++this .numGetChilds;
35: this .lastParents.add(parent);
36: XmlObject out = this .returnedChildren[this .returnedChildrenPos++];
37: if (this .returnedChildrenPos >= this .returnedChildren.length)
38: this .returnedChildrenPos = 0;
39: return out;
40: }
41:
42: public XmlObject getLastParent() {
43: return (XmlObject) this .lastParents
44: .get(this .lastParents.size() - 1);
45: }
46:
47: public XmlObject[] getLastParents() {
48: return (XmlObject[]) this .lastParents
49: .toArray(new XmlObject[this .lastParents.size()]);
50: }
51:
52: public int getNumGetChilds() {
53: return numGetChilds;
54: }
55:
56: public void setReturnedChild(XmlObject returnedChild) {
57: setReturnedChildren(new XmlObject[] { returnedChild });
58: }
59:
60: public void setReturnedChildren(XmlObject[] returnedChildren) {
61: this.returnedChildren = returnedChildren;
62: }
63:
64: }
|