ListenerRepo { public void refreshLastCheck(Listener listener, Connection connection) throws DataAccessException { try ( PreparedStatement stmt = connection.prepareStatement(REFRESH_QUERY) ) { stmt.setLong(1, listener.getId()); stmt.executeUpdate(); listener.setLastCheck(findById(listener.getId(), connection).getLastCheck()); } catch (SQLException e) { throw new DataAccessException("Couldn't refresh last check for listener with id " + listener.getId(), e); } }  Listener insert(Listener listener, Connection connection); void refreshLastCheck(Listener listener, Connection connection); void remove(Listener listener, Connection connection); void update(Listener listener, Connection connection); Listener findById(long id, Connection connection); List<Listener> findByTableName(String tableName, Connection connection);  }
@Test(groups = SMALL, expectedExceptions = DataAccessException.class) public void testRefreshThrowsDataAccessExceptionWhenSQLExceptionOccures() throws SQLException { Connection mockedConnection = mock(Connection.class); when(mockedConnection.prepareStatement(anyString())).thenThrow(new SQLException()); MysqlConnectionProvider mockedProvider = mock(MysqlConnectionProvider.class); when(mockedProvider.getConnection()).thenReturn(mockedConnection); ListenerRepo mockedRepo = new ListenerRepo(); mockedRepo.refreshLastCheck(mock(Listener.class), mockedConnection); }