PreparedStatementWrapperFactory { public PreparedStatementWrapper preparedStatementWrapperOf(final DataSource dataSource, final String query) throws SQLException { return valueOf(dataSource.getConnection(), query); }  PreparedStatementWrapper preparedStatementWrapperOf(final DataSource dataSource, final String query);  }
@Test public void shouldCreatePreparedStatementWrapper() throws Exception { final String query = "SELECT something FROM somewhere"; final DataSource dataSource = mock(DataSource.class); final Connection connection = mock(Connection.class); final PreparedStatement preparedStatement = mock(PreparedStatement.class); when(dataSource.getConnection()).thenReturn(connection); when(connection.prepareStatement(query)).thenReturn(preparedStatement); final PreparedStatementWrapper preparedStatementWrapper = preparedStatementWrapperFactory.preparedStatementWrapperOf( dataSource, query); assertThat(getValueOfField(preparedStatementWrapper, "preparedStatement", PreparedStatement.class), is(preparedStatement)); final LinkedList<AutoCloseable> closeables = getValueOfField(preparedStatementWrapper, "closeables", LinkedList.class); assertThat(closeables, hasItems(connection, preparedStatement)); }