Package org.dbunit.database.statement
Class MockStatementFactory
java.lang.Object
org.dbunit.database.statement.MockStatementFactory
- All Implemented Interfaces:
IStatementFactory
Mock implementation of
IStatementFactory for use in unit tests.
Tracks the number of statement creation calls and delegates to a configured
IBatchStatement.
Use forSingleBatch(String...) to create a fully-wired factory
expecting exactly one batch execution of the given SQL statements, reducing
per-test setup boilerplate.
- Since:
- Mar 16, 2002
- Version:
- $Revision$
- Author:
- Manuel Laflamme
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateBatchStatement(IDatabaseConnection connection) createPreparedBatchStatement(String sql, IDatabaseConnection connection) static MockStatementFactoryforSingleBatch(String... expectedSql) Creates aMockStatementFactorypre-wired with aMockBatchStatementexpecting exactly the given SQL statements in a single batch execution.Returns theMockBatchStatementconfigured viasetupStatement(IBatchStatement).voidsetExpectedCreatePreparedStatementCalls(int callsCount) voidsetExpectedCreateStatementCalls(int callsCount) voidsetupStatement(IBatchStatement batchStatement) voidverify()
-
Constructor Details
-
MockStatementFactory
public MockStatementFactory()
-
-
Method Details
-
forSingleBatch
Creates aMockStatementFactorypre-wired with aMockBatchStatementexpecting exactly the given SQL statements in a single batch execution. Equivalent to manually creating and configuring both aMockBatchStatementand aMockStatementFactory, but in one call.Call
getBatchStatement()on the returned factory to access the underlyingMockBatchStatementfor additional assertions such asMockBatchStatement.getCapturedSql().- Parameters:
expectedSql- the SQL strings expected to be batched, in order- Returns:
- a fully configured factory ready for use in a test
-
getBatchStatement
Returns theMockBatchStatementconfigured viasetupStatement(IBatchStatement). Useful after usingforSingleBatch(String...)to access the underlying statement for pattern-based assertions viaMockBatchStatement.getCapturedSql().- Returns:
- the configured batch statement, or
nullif none was set
-
setupStatement
-
setExpectedCreateStatementCalls
public void setExpectedCreateStatementCalls(int callsCount) -
setExpectedCreatePreparedStatementCalls
public void setExpectedCreatePreparedStatementCalls(int callsCount) -
verify
public void verify() -
createBatchStatement
- Specified by:
createBatchStatementin interfaceIStatementFactory- Throws:
SQLException
-
createPreparedBatchStatement
public IPreparedBatchStatement createPreparedBatchStatement(String sql, IDatabaseConnection connection) throws SQLException - Specified by:
createPreparedBatchStatementin interfaceIStatementFactory- Throws:
SQLException
-