SubscriptionsRepository { public void updateSubscription(Subscription subscription) throws SubscriptionPersistenceException { try { ObjectWriter writer = mapper.writer(); String susbcribeContextString = writer.writeValueAsString(subscription.getSubscribeContext()); String expirationDate = subscription.getExpirationDate().toString(); jdbcTemplate.update("update t_subscriptions set expirationDate=? , subscribeContext=? where id=?", expirationDate, susbcribeContextString, subscription.getSubscriptionId()); } catch (Exception e) { throw new SubscriptionPersistenceException(e); } }  void saveSubscription(Subscription subscription); void updateSubscription(Subscription subscription); Map<String, Subscription> getAllSubscriptions(); void removeSubscription(String subscriptionId);  }
@Test public void updateSubscriptionTest() throws URISyntaxException, SubscriptionPersistenceException { SubscribeContext subscribeContext = createSubscribeContextTemperature(); Subscription subscription = new Subscription("12345", Instant.now().plus(1, ChronoUnit.DAYS), subscribeContext); subscriptionsRepository.saveSubscription(subscription); Map<String, Subscription> subscriptions = subscriptionsRepository.getAllSubscriptions(); Assert.assertEquals(1, subscriptions.size()); Assert.assertEquals("P1M", subscriptions.get("12345").getSubscribeContext().getDuration()); subscribeContext.setDuration("PT1D"); subscription.setExpirationDate(Instant.now().plus(1, ChronoUnit.DAYS)); subscriptionsRepository.updateSubscription(subscription); subscriptions = subscriptionsRepository.getAllSubscriptions(); Assert.assertEquals(1, subscriptions.size()); Assert.assertEquals("PT1D", subscriptions.get("12345").getSubscribeContext().getDuration()); Assert.assertEquals(subscription.getExpirationDate(), subscriptions.get("12345").getExpirationDate()); }
@Test public void updateSubscriptionWithExceptionTest() throws URISyntaxException, SubscriptionPersistenceException { thrown.expect(SubscriptionPersistenceException.class); Subscription subscription = new Subscription(); subscription.setSubscribeContext(new SubscribeContext()); subscriptionsRepository.updateSubscription(subscription); }