@Test public void getAllSubscriptionsWithExceptionTest() throws SubscriptionPersistenceException { thrown.expect(SubscriptionPersistenceException.class); Instant expirationDate = Instant.now().plus(1, ChronoUnit.DAYS); jdbcTemplate.update("insert into t_subscriptions(id,expirationDate,subscribeContext) values(?,?,?)", "12345", expirationDate.toString(), "aaaaaa"); Map<String, Subscription> subscriptions = subscriptionsRepository.getAllSubscriptions(); }
public Map<String, Subscription> getAllSubscriptions() throws SubscriptionPersistenceException { Map<String, Subscription> subscriptions = new ConcurrentHashMap<>(); try { List<Subscription> subscriptionList = jdbcTemplate.query("select id, expirationDate, subscribeContext from t_subscriptions", (ResultSet rs, int rowNum) -> { Subscription subscription = new Subscription(); try { subscription.setSubscriptionId(rs.getString("id")); subscription.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); subscription.setSubscribeContext(mapper.readValue(rs.getString("subscribeContext"), SubscribeContext.class)); } catch (IOException e) { throw new SQLException(e); } return subscription; }); subscriptionList.forEach(subscription -> subscriptions.put(subscription.getSubscriptionId(), subscription)); } catch (DataAccessException e) { throw new SubscriptionPersistenceException(e); } return subscriptions; }
SubscriptionsRepository { public Map<String, Subscription> getAllSubscriptions() throws SubscriptionPersistenceException { Map<String, Subscription> subscriptions = new ConcurrentHashMap<>(); try { List<Subscription> subscriptionList = jdbcTemplate.query("select id, expirationDate, subscribeContext from t_subscriptions", (ResultSet rs, int rowNum) -> { Subscription subscription = new Subscription(); try { subscription.setSubscriptionId(rs.getString("id")); subscription.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); subscription.setSubscribeContext(mapper.readValue(rs.getString("subscribeContext"), SubscribeContext.class)); } catch (IOException e) { throw new SQLException(e); } return subscription; }); subscriptionList.forEach(subscription -> subscriptions.put(subscription.getSubscriptionId(), subscription)); } catch (DataAccessException e) { throw new SubscriptionPersistenceException(e); } return subscriptions; } }
SubscriptionsRepository { public Map<String, Subscription> getAllSubscriptions() throws SubscriptionPersistenceException { Map<String, Subscription> subscriptions = new ConcurrentHashMap<>(); try { List<Subscription> subscriptionList = jdbcTemplate.query("select id, expirationDate, subscribeContext from t_subscriptions", (ResultSet rs, int rowNum) -> { Subscription subscription = new Subscription(); try { subscription.setSubscriptionId(rs.getString("id")); subscription.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); subscription.setSubscribeContext(mapper.readValue(rs.getString("subscribeContext"), SubscribeContext.class)); } catch (IOException e) { throw new SQLException(e); } return subscription; }); subscriptionList.forEach(subscription -> subscriptions.put(subscription.getSubscriptionId(), subscription)); } catch (DataAccessException e) { throw new SubscriptionPersistenceException(e); } return subscriptions; }  }
SubscriptionsRepository { public Map<String, Subscription> getAllSubscriptions() throws SubscriptionPersistenceException { Map<String, Subscription> subscriptions = new ConcurrentHashMap<>(); try { List<Subscription> subscriptionList = jdbcTemplate.query("select id, expirationDate, subscribeContext from t_subscriptions", (ResultSet rs, int rowNum) -> { Subscription subscription = new Subscription(); try { subscription.setSubscriptionId(rs.getString("id")); subscription.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); subscription.setSubscribeContext(mapper.readValue(rs.getString("subscribeContext"), SubscribeContext.class)); } catch (IOException e) { throw new SQLException(e); } return subscription; }); subscriptionList.forEach(subscription -> subscriptions.put(subscription.getSubscriptionId(), subscription)); } catch (DataAccessException e) { throw new SubscriptionPersistenceException(e); } return subscriptions; }  void saveSubscription(Subscription subscription); void updateSubscription(Subscription subscription); Map<String, Subscription> getAllSubscriptions(); void removeSubscription(String subscriptionId); }
SubscriptionsRepository { public Map<String, Subscription> getAllSubscriptions() throws SubscriptionPersistenceException { Map<String, Subscription> subscriptions = new ConcurrentHashMap<>(); try { List<Subscription> subscriptionList = jdbcTemplate.query("select id, expirationDate, subscribeContext from t_subscriptions", (ResultSet rs, int rowNum) -> { Subscription subscription = new Subscription(); try { subscription.setSubscriptionId(rs.getString("id")); subscription.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); subscription.setSubscribeContext(mapper.readValue(rs.getString("subscribeContext"), SubscribeContext.class)); } catch (IOException e) { throw new SQLException(e); } return subscription; }); subscriptionList.forEach(subscription -> subscriptions.put(subscription.getSubscriptionId(), subscription)); } catch (DataAccessException e) { throw new SubscriptionPersistenceException(e); } return subscriptions; }  void saveSubscription(Subscription subscription); void updateSubscription(Subscription subscription); Map<String, Subscription> getAllSubscriptions(); void removeSubscription(String subscriptionId);  }