KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > tools > mock > MockDriver


1 package org.objectweb.cjdbc.scenario.tools.mock;
2
3 import java.sql.Connection JavaDoc;
4 import java.sql.Driver JavaDoc;
5 import java.sql.DriverPropertyInfo JavaDoc;
6 import java.sql.SQLException JavaDoc;
7 import java.util.Properties JavaDoc;
8
9 import mockmaker.ExceptionalReturnValue;
10 import mockmaker.ReturnValues;
11
12 import com.mockobjects.ExpectationCounter;
13 import com.mockobjects.ExpectationList;
14
15 /**
16  * Mock driver generated by MockMaker (www.mockmaker.org).
17  */

18 public class MockDriver implements Driver JavaDoc
19 {
20   private ExpectationCounter myConnectCalls = new ExpectationCounter(
21                                                                      "java.sql.Driver ConnectCalls");
22   private ReturnValues myActualConnectReturnValues = new ReturnValues(
23                                                                      false);
24   private ExpectationList myConnectParameter0Values = new ExpectationList(
25                                                                      "java.sql.Driver java.lang.String");
26   private ExpectationList myConnectParameter1Values = new ExpectationList(
27                                                                      "java.sql.Driver java.util.Properties");
28   private ExpectationCounter myAcceptsURLCalls = new ExpectationCounter(
29                                                                      "java.sql.Driver AcceptsURLCalls");
30   private ReturnValues myActualAcceptsURLReturnValues = new ReturnValues(
31                                                                      false);
32   private ExpectationList myAcceptsURLParameter0Values = new ExpectationList(
33                                                                      "java.sql.Driver java.lang.String");
34   private ExpectationCounter myGetPropertyInfoCalls = new ExpectationCounter(
35                                                                      "java.sql.Driver GetPropertyInfoCalls");
36   private ReturnValues myActualGetPropertyInfoReturnValues = new ReturnValues(
37                                                                      false);
38   private ExpectationList myGetPropertyInfoParameter0Values = new ExpectationList(
39                                                                      "java.sql.Driver java.lang.String");
40   private ExpectationList myGetPropertyInfoParameter1Values = new ExpectationList(
41                                                                      "java.sql.Driver java.util.Properties");
42   private ExpectationCounter myGetMajorVersionCalls = new ExpectationCounter(
43                                                                      "java.sql.Driver GetMajorVersionCalls");
44   private ReturnValues myActualGetMajorVersionReturnValues = new ReturnValues(
45                                                                      false);
46   private ExpectationCounter myGetMinorVersionCalls = new ExpectationCounter(
47                                                                      "java.sql.Driver GetMinorVersionCalls");
48   private ReturnValues myActualGetMinorVersionReturnValues = new ReturnValues(
49                                                                      false);
50   private ExpectationCounter myJdbcCompliantCalls = new ExpectationCounter(
51                                                                      "java.sql.Driver JdbcCompliantCalls");
52   private ReturnValues myActualJdbcCompliantReturnValues = new ReturnValues(
53                                                                      false);
54
55   /**
56    * setExpectedConnected
57    *
58    * @param calls value
59    */

60   public void setExpectedConnectCalls(int calls)
61   {
62     myConnectCalls.setExpected(calls);
63   }
64
65   /**
66    * addExpectedConnect
67    *
68    * @param arg0 value
69    * @param arg1 value
70    */

71   public void addExpectedConnectValues(String JavaDoc arg0, Properties JavaDoc arg1)
72   {
73     myConnectParameter0Values.addExpected(arg0);
74     myConnectParameter1Values.addExpected(arg1);
75   }
76
77   /**
78    * Connect
79    *
80    * @param arg0 value
81    * @param arg1 value
82    * @return connection
83    * @throws SQLException if exception
84    */

85   public Connection JavaDoc connect(String JavaDoc arg0, Properties JavaDoc arg1) throws SQLException JavaDoc
86   {
87     myConnectCalls.inc();
88     myConnectParameter0Values.addActual(arg0);
89     myConnectParameter1Values.addActual(arg1);
90     Object JavaDoc nextReturnValue = myActualConnectReturnValues.getNext();
91     if (nextReturnValue instanceof ExceptionalReturnValue
92         && ((ExceptionalReturnValue) nextReturnValue).getException() instanceof SQLException JavaDoc)
93       throw (SQLException JavaDoc) ((ExceptionalReturnValue) nextReturnValue)
94           .getException();
95     if (nextReturnValue instanceof ExceptionalReturnValue
96         && ((ExceptionalReturnValue) nextReturnValue).getException() instanceof RuntimeException JavaDoc)
97       throw (RuntimeException JavaDoc) ((ExceptionalReturnValue) nextReturnValue)
98           .getException();
99     return (Connection JavaDoc) nextReturnValue;
100   }
101
102   /**
103    * setupExceptionConnect
104    *
105    * @param arg value
106    */

107   public void setupExceptionConnect(Throwable JavaDoc arg)
108   {
109     myActualConnectReturnValues.add(new ExceptionalReturnValue(arg));
110   }
111
112   /**
113    * setupConnect
114    *
115    * @param arg value
116    */

117   public void setupConnect(Connection JavaDoc arg)
118   {
119     myActualConnectReturnValues.add(arg);
120   }
121
122   /**
123    * setExpectedAcceptsURLCalls
124    *
125    * @param calls value
126    */

127   public void setExpectedAcceptsURLCalls(int calls)
128   {
129     myAcceptsURLCalls.setExpected(calls);
130   }
131
132   /**
133    * addExpectedAcceptsURLValues
134    *
135    * @param arg0 value
136    */

137   public void addExpectedAcceptsURLValues(String JavaDoc arg0)
138   {
139     myAcceptsURLParameter0Values.addExpected(arg0);
140   }
141
142   /**
143    * @see java.sql.Driver#acceptsURL(java.lang.String)
144    */

145   public boolean acceptsURL(String JavaDoc arg0) throws SQLException JavaDoc
146   {
147     myAcceptsURLCalls.inc();
148     myAcceptsURLParameter0Values.addActual(arg0);
149     Object JavaDoc nextReturnValue = myActualAcceptsURLReturnValues.getNext();
150     if (nextReturnValue instanceof ExceptionalReturnValue
151         && ((ExceptionalReturnValue) nextReturnValue).getException() instanceof SQLException JavaDoc)
152       throw (SQLException JavaDoc) ((ExceptionalReturnValue) nextReturnValue)
153           .getException();
154     if (nextReturnValue instanceof ExceptionalReturnValue
155         && ((ExceptionalReturnValue) nextReturnValue).getException() instanceof RuntimeException JavaDoc)
156       throw (RuntimeException JavaDoc) ((ExceptionalReturnValue) nextReturnValue)
157           .getException();
158     return ((Boolean JavaDoc) nextReturnValue).booleanValue();
159   }
160
161   /**
162    * setupExceptionAcceptsURL
163    *
164    * @param arg value
165    */

166   public void setupExceptionAcceptsURL(Throwable JavaDoc arg)
167   {
168     myActualAcceptsURLReturnValues.add(new ExceptionalReturnValue(arg));
169   }
170
171   /**
172    * setupAcceptsURL
173    *
174    * @param arg value
175    */

176   public void setupAcceptsURL(boolean arg)
177   {
178     myActualAcceptsURLReturnValues.add(new Boolean JavaDoc(arg));
179   }
180
181   /**
182    * setExpectedGetPropertyInfoCalls
183    *
184    * @param calls value
185    */

186   public void setExpectedGetPropertyInfoCalls(int calls)
187   {
188     myGetPropertyInfoCalls.setExpected(calls);
189   }
190
191   /**
192    * addExpectedGetPropertyInfoValues
193    *
194    * @param arg0 value
195    * @param arg1 value
196    */

197   public void addExpectedGetPropertyInfoValues(String JavaDoc arg0, Properties JavaDoc arg1)
198   {
199     myGetPropertyInfoParameter0Values.addExpected(arg0);
200     myGetPropertyInfoParameter1Values.addExpected(arg1);
201   }
202
203   /**
204    * @see java.sql.Driver#getPropertyInfo(java.lang.String,
205    * java.util.Properties)
206    */

207   public DriverPropertyInfo JavaDoc[] getPropertyInfo(String JavaDoc arg0, Properties JavaDoc arg1)
208       throws SQLException JavaDoc
209   {
210     myGetPropertyInfoCalls.inc();
211     myGetPropertyInfoParameter0Values.addActual(arg0);
212     myGetPropertyInfoParameter1Values.addActual(arg1);
213     Object JavaDoc nextReturnValue = myActualGetPropertyInfoReturnValues.getNext();
214     if (nextReturnValue instanceof ExceptionalReturnValue
215         && ((ExceptionalReturnValue) nextReturnValue).getException() instanceof SQLException JavaDoc)
216       throw (SQLException JavaDoc) ((ExceptionalReturnValue) nextReturnValue)
217           .getException();
218     if (nextReturnValue instanceof ExceptionalReturnValue
219         && ((ExceptionalReturnValue) nextReturnValue).getException() instanceof RuntimeException JavaDoc)
220       throw (RuntimeException JavaDoc) ((ExceptionalReturnValue) nextReturnValue)
221           .getException();
222     return (DriverPropertyInfo JavaDoc[]) nextReturnValue;
223   }
224
225   /**
226    * setupExceptionGetPropertyInfo
227    *
228    * @param arg value
229    */

230   public void setupExceptionGetPropertyInfo(Throwable JavaDoc arg)
231   {
232     myActualGetPropertyInfoReturnValues.add(new ExceptionalReturnValue(arg));
233   }
234
235   /**
236    * setupGetPropertyInfo
237    *
238    * @param arg value
239    */

240   public void setupGetPropertyInfo(DriverPropertyInfo JavaDoc[] arg)
241   {
242     myActualGetPropertyInfoReturnValues.add(arg);
243   }
244
245   /**
246    * setExpectedGetMajorVersionCalls
247    *
248    * @param calls value
249    */

250   public void setExpectedGetMajorVersionCalls(int calls)
251   {
252     myGetMajorVersionCalls.setExpected(calls);
253   }
254
255   /**
256    * @see java.sql.Driver#getMajorVersion()
257    */

258   public int getMajorVersion()
259   {
260     myGetMajorVersionCalls.inc();
261     Object JavaDoc nextReturnValue = myActualGetMajorVersionReturnValues.getNext();
262     if (nextReturnValue instanceof ExceptionalReturnValue
263         && ((ExceptionalReturnValue) nextReturnValue).getException() instanceof RuntimeException JavaDoc)
264       throw (RuntimeException JavaDoc) ((ExceptionalReturnValue) nextReturnValue)
265           .getException();
266     return ((Integer JavaDoc) nextReturnValue).intValue();
267   }
268
269   /**
270    * setupExceptionGetMajorVersion
271    *
272    * @param arg value
273    */

274   public void setupExceptionGetMajorVersion(Throwable JavaDoc arg)
275   {
276     myActualGetMajorVersionReturnValues.add(new ExceptionalReturnValue(arg));
277   }
278
279   /**
280    * setupGetMajorVersion
281    *
282    * @param arg value
283    */

284   public void setupGetMajorVersion(int arg)
285   {
286     myActualGetMajorVersionReturnValues.add(new Integer JavaDoc(arg));
287   }
288
289   /**
290    * setExpectedGetMinorVersionCalls
291    *
292    * @param calls value
293    */

294   public void setExpectedGetMinorVersionCalls(int calls)
295   {
296     myGetMinorVersionCalls.setExpected(calls);
297   }
298
299   /**
300    * @see java.sql.Driver#getMinorVersion()
301    */

302   public int getMinorVersion()
303   {
304     myGetMinorVersionCalls.inc();
305     Object JavaDoc nextReturnValue = myActualGetMinorVersionReturnValues.getNext();
306     if (nextReturnValue instanceof ExceptionalReturnValue
307         && ((ExceptionalReturnValue) nextReturnValue).getException() instanceof RuntimeException JavaDoc)
308       throw (RuntimeException JavaDoc) ((ExceptionalReturnValue) nextReturnValue)
309           .getException();
310     return ((Integer JavaDoc) nextReturnValue).intValue();
311   }
312
313   /**
314    * setupExceptionGetMinorVersion
315    *
316    * @param arg value
317    */

318   public void setupExceptionGetMinorVersion(Throwable JavaDoc arg)
319   {
320     myActualGetMinorVersionReturnValues.add(new ExceptionalReturnValue(arg));
321   }
322
323   /**
324    * setupGetMinorVersion
325    *
326    * @param arg value
327    */

328   public void setupGetMinorVersion(int arg)
329   {
330     myActualGetMinorVersionReturnValues.add(new Integer JavaDoc(arg));
331   }
332
333   /**
334    * setExpectedJdbcCompliantCalls
335    *
336    * @param calls value
337    */

338   public void setExpectedJdbcCompliantCalls(int calls)
339   {
340     myJdbcCompliantCalls.setExpected(calls);
341   }
342
343   /**
344    * jdbcCompliant
345    *
346    * @see java.sql.Driver#jdbcCompliant()
347    */

348   public boolean jdbcCompliant()
349   {
350     myJdbcCompliantCalls.inc();
351     Object JavaDoc nextReturnValue = myActualJdbcCompliantReturnValues.getNext();
352     if (nextReturnValue instanceof ExceptionalReturnValue
353         && ((ExceptionalReturnValue) nextReturnValue).getException() instanceof RuntimeException JavaDoc)
354       throw (RuntimeException JavaDoc) ((ExceptionalReturnValue) nextReturnValue)
355           .getException();
356     return ((Boolean JavaDoc) nextReturnValue).booleanValue();
357   }
358
359   /**
360    * setupExceptionJdbcCompliant
361    *
362    * @param arg value
363    */

364   public void setupExceptionJdbcCompliant(Throwable JavaDoc arg)
365   {
366     myActualJdbcCompliantReturnValues.add(new ExceptionalReturnValue(arg));
367   }
368
369   /**
370    * setupJdbcCompliant
371    *
372    * @param arg value
373    */

374   public void setupJdbcCompliant(boolean arg)
375   {
376     myActualJdbcCompliantReturnValues.add(new Boolean JavaDoc(arg));
377   }
378
379   /**
380    * verify
381    */

382   public void verify()
383   {
384     myConnectCalls.verify();
385     myConnectParameter0Values.verify();
386     myConnectParameter1Values.verify();
387     myAcceptsURLCalls.verify();
388     myAcceptsURLParameter0Values.verify();
389     myGetPropertyInfoCalls.verify();
390     myGetPropertyInfoParameter0Values.verify();
391     myGetPropertyInfoParameter1Values.verify();
392     myGetMajorVersionCalls.verify();
393     myGetMinorVersionCalls.verify();
394     myJdbcCompliantCalls.verify();
395   }
396 }
397
Popular Tags