@PostConstruct void populateCache() { LOG.info("Populating merchants cache..."); String sql = "select * " + "from MERCHANT"; try (Connection connection = dataSource.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) { try (ResultSet resultSet = statement.executeQuery()) { if (resultSet.next()) { Merchant merchant = readMerchantFrom(resultSet); cache.put(merchant.getNumber(), merchant); } } } catch (SQLException e) { throw new RuntimeException("Error in findByNumber!", e); } }
@Before public void setUp() throws Exception { // simulate Spring bean initialization lifecycle // create the bean first repository = new JdbcMerchantRepository(); // deliver its dependencies repository.setDataSource(createDataSource()); // FIXME 1: initialize the bean repository.populateCache(); }
@After public void tearDown() { // simulate Spring bean destruction lifecycle // FIXME 2: destroy the bean repository.clearCache(); }
@Before public void setUp() throws Exception { repository = new JdbcMerchantRepository(new JdbcTemplate(createDataSource())); repository.populateCache(); }
@Before public void setUp() throws Exception { // simulate Spring bean initialization lifecycle // create the bean first repository = new JdbcMerchantRepository(); // deliver its dependencies repository.setDataSource(createDataSource()); // FIXME 1: initialize the bean }
@Test public void shouldThrowWhenMerchantNotFound() { catchException(repository, EmptyResultDataAccessException.class).findByNumber("111111111"); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenMerchantNotFound() { catchException(repository, EmptyResultDataAccessException.class).findByNumber("111111111"); assertThat(caughtException()).isNotNull(); }
@Before public void setUp() throws Exception { repository = new JdbcMerchantRepository(new JdbcTemplate(createDataSource())); repository.populateCache(); }
@Before public void setUp() throws Exception { repository = new JdbcMerchantRepository(); repository.setDataSource(createDataSource()); repository.populateCache(); }
@Test public void shouldThrowWhenMerchantNotFound() { catchException(repository, EmptyResultDataAccessException.class).findByNumber("111111111"); assertThat(caughtException()).isNotNull(); }
void populateCache() { LOG.info("Populating merchants cache..."); String sql = "select * " + "from MERCHANT"; try (Connection connection = dataSource.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) { try (ResultSet resultSet = statement.executeQuery()) { if (resultSet.next()) { Merchant merchant = readMerchantFrom(resultSet); cache.put(merchant.getNumber(), merchant); } } } catch (SQLException e) { throw new RuntimeException("Error in findByNumber!", e); } }
@After public void tearDown() { repository.clearCache(); }
@Before public void setUp() throws Exception { repository = new JdbcMerchantRepository(); repository.setDataSource(createDataSource()); repository.populateCache(); }
@Test public void shouldThrowWhenMerchantNotFound() { catchException(repository, EmptyResultDataAccessException.class).findByNumber("111111111"); assertThat(caughtException()).isNotNull(); }
@PostConstruct void populateCache() { LOG.info("Populating merchants cache..."); String sql = "select * " + "from MERCHANT"; try (Connection connection = dataSource.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) { try (ResultSet resultSet = statement.executeQuery()) { if (resultSet.next()) { Merchant merchant = readMerchantFrom(resultSet); cache.put(merchant.getNumber(), merchant); } } } catch (SQLException e) { throw new RuntimeException("Error in findByNumber!", e); } }
@After public void tearDown() { repository.clearCache(); }
@Test public void shouldThrowWhenMerchantNotFound() { catchException(repository, EmptyResultDataAccessException.class).findByNumber("111111111"); assertThat(caughtException()).isNotNull(); }
@PostConstruct void populateCache() { LOG.info("Populating merchants cache..."); String sql = "select * " + "from MERCHANT"; try (Connection connection = dataSource.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) { try (ResultSet resultSet = statement.executeQuery()) { if (resultSet.next()) { Merchant merchant = readMerchantFrom(resultSet); cache.put(merchant.getNumber(), merchant); } } } catch (SQLException e) { throw new RuntimeException("Error in findByNumber!", e); } }
@After public void tearDown() { repository.clearCache(); }
@Test public void shouldThrowWhenMerchantNotFound() { catchException(repository, EmptyResultDataAccessException.class).findByNumber("111111111"); assertThat(caughtException()).isNotNull(); }