Module org.jooq

Class MockConnection

  • All Implemented Interfaces:
    AutoCloseable, Connection, Wrapper

    public class MockConnection
    extends JDBC41Connection
    implements Connection
    A mock connection.

    Mock connections can be used to supply jOOQ with unit test data, avoiding the round-trip of using an actual in-memory test database, such as Derby, H2 or HSQLDB. A usage example:

     MockDataProvider provider = new MockDataProvider() {
         public MockResult[] execute(MockExecuteContext context) throws SQLException {
             Result<MyTableRecord> result = executor.newResult(MY_TABLE);
             return new MockResult[] {
                 new MockResult(1, result)
     Connection connection = new MockConnection(provider);
     DSLContext create = DSL.using(connection, dialect);
     assertEquals(1, create.selectOne().fetch().size());

    While this MockConnection can be used independently of jOOQ, it has been optimised for usage with jOOQ. JDBC features that are not used by jOOQ (e.g. procedure bind value access by parameter name) are not supported in this mock framework

    Lukas Eder