1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
32
33
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
78
79 public void verify()
80 {
81 _executeBatchCalls.verify();
82 _clearBatchCalls.verify();
83 _closeCalls.verify();
84 _batchStrings.verify();
85 }
86
87
88
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