From 21fe1b4439e5b2b686f2b290f91bdbed90c5d1bc Mon Sep 17 00:00:00 2001 From: Brett Wooldridge <brett.wooldridge@gmail.com> Date: Wed, 9 Oct 2013 07:59:37 +0900 Subject: [PATCH] Fix up the mock datasource --- .../zaxxer/hikari/mocks/MockDataSource.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/zaxxer/hikari/mocks/MockDataSource.java b/src/test/java/com/zaxxer/hikari/mocks/MockDataSource.java index 208ea7bd..8e7338e9 100644 --- a/src/test/java/com/zaxxer/hikari/mocks/MockDataSource.java +++ b/src/test/java/com/zaxxer/hikari/mocks/MockDataSource.java @@ -108,10 +108,17 @@ public class MockDataSource implements DataSource when(mockConnection.prepareStatement(anyString(), (String[]) anyObject())).thenReturn(mockPreparedStatement); when(mockConnection.prepareStatement(anyString(), anyInt(), anyInt())).thenReturn(mockPreparedStatement); when(mockConnection.prepareStatement(anyString(), anyInt(), anyInt(), anyInt())).thenReturn(mockPreparedStatement); + doAnswer(new Answer<Void>() { + public Void answer(InvocationOnMock invocation) throws Throwable + { + return null; + } + }).doNothing().when(mockPreparedStatement).setInt(anyInt(), anyInt()); ResultSet mockResultSet = mock(ResultSet.class); when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet); when(mockResultSet.getString(anyInt())).thenReturn("aString"); + when(mockResultSet.next()).thenReturn(true); // Handle Connection.prepareCall() CallableStatement mockCallableStatement = mock(CallableStatement.class); @@ -120,25 +127,25 @@ public class MockDataSource implements DataSource when(mockConnection.prepareCall(anyString(), anyInt(), anyInt(), anyInt())).thenReturn(mockCallableStatement); // Handle Connection.close() - doAnswer(new Answer<Void>() { - public Void answer(InvocationOnMock invocation) throws Throwable { - return null; - } - }).doThrow(new SQLException("Connection is already closed")).when(mockConnection).close(); +// doAnswer(new Answer<Void>() { +// public Void answer(InvocationOnMock invocation) throws Throwable { +// return null; +// } +// }).doThrow(new SQLException("Connection is already closed")).when(mockConnection).close(); // Handle Connection.commit() - doAnswer(new Answer<Void>() { - public Void answer(InvocationOnMock invocation) throws Throwable { - return null; - } - }).doThrow(new SQLException("Transaction already commited")).when(mockConnection).commit(); +// doAnswer(new Answer<Void>() { +// public Void answer(InvocationOnMock invocation) throws Throwable { +// return null; +// } +// }).doThrow(new SQLException("Transaction already commited")).when(mockConnection).commit(); // Handle Connection.rollback() - doAnswer(new Answer<Void>() { - public Void answer(InvocationOnMock invocation) throws Throwable { - return null; - } - }).doThrow(new SQLException("Transaction already rolledback")).when(mockConnection).rollback(); +// doAnswer(new Answer<Void>() { +// public Void answer(InvocationOnMock invocation) throws Throwable { +// return null; +// } +// }).doThrow(new SQLException("Transaction already rolledback")).when(mockConnection).rollback(); return mockConnection; }