KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > database > statement > MockStatementFactory


1 /*
2  *
3  * The DbUnit Database Testing Framework
4  * Copyright (C)2002-2004, DbUnit.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */

21
22 package org.dbunit.database.statement;
23
24 import com.mockobjects.ExpectationCounter;
25 import com.mockobjects.Verifiable;
26 import org.dbunit.database.IDatabaseConnection;
27
28 import java.sql.SQLException JavaDoc;
29
30 /**
31  * @author Manuel Laflamme
32  * @version $Revision: 1.6 $
33  * @since Mar 16, 2002
34  */

35 public class MockStatementFactory implements IStatementFactory, Verifiable
36 {
37     private IBatchStatement _batchStatement = null;
38 // private IPreparedBatchStatement _preparedBatchStatement = null;
39
private ExpectationCounter _createStatementCalls =
40             new ExpectationCounter("MockStatementFactory.createBatchStatement");;
41     private ExpectationCounter _createPreparedStatementCalls =
42             new ExpectationCounter("MockStatementFactory.createPreparedBatchStatement");;
43
44     public void setupStatement(IBatchStatement batchStatement)
45     {
46         _batchStatement = batchStatement;
47     }
48
49 // public void setupPreparedStatement(IPreparedBatchStatement preparedBatchStatement)
50
// {
51
// _preparedBatchStatement = preparedBatchStatement;
52
// }
53

54     public void setExpectedCreateStatementCalls(int callsCount)
55     {
56         _createStatementCalls.setExpected(callsCount);
57     }
58
59     public void setExpectedCreatePreparedStatementCalls(int callsCount)
60     {
61         _createPreparedStatementCalls.setExpected(callsCount);
62     }
63
64
65     ////////////////////////////////////////////////////////////////////////////
66
// Verifiable interface
67

68     public void verify()
69     {
70         _createStatementCalls.verify();
71         _createPreparedStatementCalls.verify();
72     }
73
74     ////////////////////////////////////////////////////////////////////////////
75
// IStatementFactory interface
76

77     public IBatchStatement createBatchStatement(IDatabaseConnection connection)
78             throws SQLException JavaDoc
79     {
80         _createStatementCalls.inc();
81         return _batchStatement;
82     }
83
84     public IPreparedBatchStatement createPreparedBatchStatement(String JavaDoc sql,
85             IDatabaseConnection connection) throws SQLException JavaDoc
86     {
87         _createPreparedStatementCalls.inc();
88         return new BatchStatementDecorator(sql, _batchStatement);
89     }
90 }
91
92
93
94
Popular Tags