BoltNeo4jStatement extends Neo4jStatement { public static Statement newInstance(boolean debug, BoltNeo4jConnectionImpl connection, int... rsParams) { Statement statement = new BoltNeo4jStatement(connection, rsParams); ((Neo4jStatement) statement).setDebug(debug); return (Statement) Proxy.newProxyInstance(BoltNeo4jStatement.class.getClassLoader(), new Class[] { Statement.class }, new Neo4jInvocationHandler(statement, debug)); } private  BoltNeo4jStatement(BoltNeo4jConnectionImpl connection, int... rsParams); static Statement newInstance(boolean debug, BoltNeo4jConnectionImpl connection, int... rsParams); @Override ResultSet executeQuery(String sql); @Override int executeUpdate(String sql); @Override boolean execute(String sql); @Override int[] executeBatch();  }
@Test public void clearBatchShouldThrowExceptionIfClosedStatement() throws SQLException { expectedEx.expect(SQLException.class); Statement stmt = BoltNeo4jStatement.newInstance(false, Mocker.mockConnectionOpen()); stmt.close(); stmt.clearBatch(); }
@Test public void getConnectionShouldWork() throws SQLException { Statement stmt = BoltNeo4jStatement.newInstance(false, Mocker.mockConnectionOpen()); assertNotNull(stmt.getConnection()); assertEquals(Mocker.mockConnectionOpen().getClass(), stmt.getConnection().getClass()); }
@Test public void getConnectionShouldThrowExceptionOnClosedStatement() throws SQLException { expectedEx.expect(SQLException.class); Statement stmt = BoltNeo4jStatement.newInstance(false, Mocker.mockConnectionClosed()); stmt.close(); stmt.getConnection(); }
@Test public void closeShouldNotCallCloseOnAnyResultSet() throws Exception { Statement statement = BoltNeo4jStatement.newInstance(false, mockConnectionOpenWithTransactionThatReturns(null)); statement.close(); verify(mockedRS, never()).close(); }
@Test public void closeShouldNotTouchTheTransaction() throws Exception { Transaction mockTransaction = mock(Transaction.class); BoltNeo4jConnectionImpl mockConnection = mockConnectionOpen(); when(mockConnection.getTransaction()).thenReturn(mockTransaction); Statement statement = BoltNeo4jStatement.newInstance(false, mockConnection); statement.close(); verify(mockTransaction, never()).failure(); verify(mockTransaction, never()).success(); verify(mockTransaction, never()).close(); }
@Test public void isClosedShouldReturnFalseWhenCreated() throws SQLException { Statement statement = BoltNeo4jStatement.newInstance(false, mockConnectionOpen()); assertFalse(statement.isClosed()); }
@Test public void getResultSetConcurrencyShouldThrowExceptionWhenCalledOnClosedStatement() throws SQLException { expectedEx.expect(SQLException.class); Statement statement = BoltNeo4jStatement.newInstance(false, mockConnectionClosed()); statement.close(); statement.getResultSetConcurrency(); }
@Test public void getResultSetHoldabilityShouldThrowExceptionWhenCalledOnClosedStatement() throws SQLException { expectedEx.expect(SQLException.class); Statement statement = BoltNeo4jStatement.newInstance(false, mockConnectionClosed()); statement.close(); statement.getResultSetHoldability(); }
@Test public void getResultSetTypeShouldThrowExceptionWhenCalledOnClosedStatement() throws SQLException { expectedEx.expect(SQLException.class); Statement statement = BoltNeo4jStatement.newInstance(false, mockConnectionClosed()); statement.close(); statement.getResultSetType(); }
@Test public void getUpdateCountShouldThrowExceptionOnClosedStatement() throws SQLException { expectedEx.expect(SQLException.class); Statement statement = BoltNeo4jStatement.newInstance(false, mockConnectionOpen()); statement.close(); statement.getUpdateCount(); }
@Test public void getResultSetShouldThrowExceptionOnClosedStatement() throws SQLException { expectedEx.expect(SQLException.class); Statement statement = BoltNeo4jStatement.newInstance(false, mockConnectionOpen()); statement.close(); statement.getResultSet(); }
@Test public void addBatchShouldThrowExceptionIfClosedStatement() throws SQLException { expectedEx.expect(SQLException.class); Statement stmt = BoltNeo4jStatement.newInstance(false, Mocker.mockConnectionOpen()); stmt.close(); stmt.addBatch(""); }