View Javadoc
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.ExpectationList;
26  import com.mockobjects.Verifiable;
27  
28  import java.sql.SQLException;
29  
30  /**
31   * @author Manuel Laflamme
32   * @version $Revision$
33   * @since Mar 16, 2002
34   */
35  public class MockBatchStatement implements IBatchStatement, Verifiable
36  {
37      private ExpectationCounter _executeBatchCalls =
38              new ExpectationCounter("MockBatchStatement.executeBatch");;
39      private ExpectationCounter _clearBatchCalls =
40              new ExpectationCounter("MockBatchStatement.clearBatch");;
41      private ExpectationCounter _closeCalls =
42              new ExpectationCounter("MockBatchStatement.close");;
43      private ExpectationList _batchStrings =
44              new ExpectationList("MockBatchStatement.batchStrings");
45      private int _addBatchCalls = 0;
46  
47      public MockBatchStatement()
48      {
49      }
50  
51      public void addExpectedBatchString(String sql)
52      {
53          _batchStrings.addExpected(sql);
54      }
55  
56      public void addExpectedBatchStrings(String[] sql)
57      {
58          _batchStrings.addExpectedMany(sql);
59      }
60  
61      public void setExpectedExecuteBatchCalls(int callsCount)
62      {
63          _executeBatchCalls.setExpected(callsCount);
64      }
65  
66      public void setExpectedClearBatchCalls(int callsCount)
67      {
68          _clearBatchCalls.setExpected(callsCount);
69      }
70  
71      public void setExpectedCloseCalls(int callsCount)
72      {
73          _closeCalls.setExpected(callsCount);
74      }
75  
76      ////////////////////////////////////////////////////////////////////////////
77      // Verifiable interface
78  
79      public void verify()
80      {
81          _executeBatchCalls.verify();
82          _clearBatchCalls.verify();
83          _closeCalls.verify();
84          _batchStrings.verify();
85      }
86  
87      ////////////////////////////////////////////////////////////////////////////
88      // IBatchStatement interface
89  
90      public void addBatch(String sql) throws SQLException
91      {
92          _batchStrings.addActual(sql);
93          _addBatchCalls++;
94      }
95  
96      public int executeBatch() throws SQLException
97      {
98          _executeBatchCalls.inc();
99          return _addBatchCalls;
100     }
101 
102     public void clearBatch() throws SQLException
103     {
104         _clearBatchCalls.inc();
105         _addBatchCalls = 0;
106     }
107 
108     public void close() throws SQLException
109     {
110         _closeCalls.inc();
111     }
112 }
113 
114 
115