@Test public void testUpdateSubscriptionWhenEndpointIsSame() { Subscription aSubscription = getASubscription(); Subscription dbSubscription = getASubscription(); when(subscriptionRepository.findByClientId(defaultClientId)) .thenReturn(Optional.of(dbSubscription)); underTest.subscribe(aSubscription); verify(subscriptionRepository, never()).save(aSubscription); }
public void subscribe(Subscription subscription) { subscriptionRepository.findByClientId(subscription.getClientId()).ifPresentOrElse( dbSubscription -> { if (!dbSubscription.getEndpoint().equals(subscription.getEndpoint())) { dbSubscription.setEndpoint(subscription.getEndpoint()); subscriptionRepository.save(dbSubscription); } }, () -> { subscriptionRepository.save(subscription); }); LOGGER.info("Subscription updated for this client with the endpoint [client: '{}', endpoint: '{}']", subscription.getClientId(), subscription.getEndpoint()); }
SubscriptionService { public void subscribe(Subscription subscription) { subscriptionRepository.findByClientId(subscription.getClientId()).ifPresentOrElse( dbSubscription -> { if (!dbSubscription.getEndpoint().equals(subscription.getEndpoint())) { dbSubscription.setEndpoint(subscription.getEndpoint()); subscriptionRepository.save(dbSubscription); } }, () -> { subscriptionRepository.save(subscription); }); LOGGER.info("Subscription updated for this client with the endpoint [client: '{}', endpoint: '{}']", subscription.getClientId(), subscription.getEndpoint()); } }
SubscriptionService { public void subscribe(Subscription subscription) { subscriptionRepository.findByClientId(subscription.getClientId()).ifPresentOrElse( dbSubscription -> { if (!dbSubscription.getEndpoint().equals(subscription.getEndpoint())) { dbSubscription.setEndpoint(subscription.getEndpoint()); subscriptionRepository.save(dbSubscription); } }, () -> { subscriptionRepository.save(subscription); }); LOGGER.info("Subscription updated for this client with the endpoint [client: '{}', endpoint: '{}']", subscription.getClientId(), subscription.getEndpoint()); }  }
SubscriptionService { public void subscribe(Subscription subscription) { subscriptionRepository.findByClientId(subscription.getClientId()).ifPresentOrElse( dbSubscription -> { if (!dbSubscription.getEndpoint().equals(subscription.getEndpoint())) { dbSubscription.setEndpoint(subscription.getEndpoint()); subscriptionRepository.save(dbSubscription); } }, () -> { subscriptionRepository.save(subscription); }); LOGGER.info("Subscription updated for this client with the endpoint [client: '{}', endpoint: '{}']", subscription.getClientId(), subscription.getEndpoint()); }  void subscribe(Subscription subscription); }
SubscriptionService { public void subscribe(Subscription subscription) { subscriptionRepository.findByClientId(subscription.getClientId()).ifPresentOrElse( dbSubscription -> { if (!dbSubscription.getEndpoint().equals(subscription.getEndpoint())) { dbSubscription.setEndpoint(subscription.getEndpoint()); subscriptionRepository.save(dbSubscription); } }, () -> { subscriptionRepository.save(subscription); }); LOGGER.info("Subscription updated for this client with the endpoint [client: '{}', endpoint: '{}']", subscription.getClientId(), subscription.getEndpoint()); }  void subscribe(Subscription subscription);  }