### Question:
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);  }### Answer:
@Test public void testCreateDefaultSubscription() { Subscription aSubscription = getASubscription(); when(subscriptionRepository.findByClientId(defaultClientId)).thenReturn(Optional.empty()); underTest.subscribe(aSubscription); verify(subscriptionRepository, times(1)).save(aSubscription); }
@Test public void testUpdateSubscriptionWhenEndpointIsDifferent() { Subscription aSubscription = getASubscription(); Subscription dbSubscription = getASubscription(); dbSubscription.setEndpoint("http: when(subscriptionRepository.findByClientId(defaultClientId)) .thenReturn(Optional.of(dbSubscription)); underTest.subscribe(aSubscription); assertEquals("Updated endpoint address should match", defaultNotificationEndpoint, dbSubscription.getEndpoint()); verify(subscriptionRepository, times(1)).save(dbSubscription); }
@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); }