SubscriptionDelegate { Subscriber getSubscriber(Identity subscriberIdentity) { Subscriber subscriber = subscriberDao.findSubscriber(subscriberIdentity); if (subscriber == null) { subscriber = subscriberDao.createAndSaveSubscriber(subscriberIdentity); } return subscriber; }  void deleteSubscription(NotificationSubscriptionContext subscriptionContext); void invalidateSubscriptionForSubscriptionContext(NotificationSubscriptionContext subscriptionContext); void invalidateSubscription(Publisher publisher, Subscriber subscriber); void invalidateSubscription(Subscription subscription); Subscription getSubscription(NotificationSubscriptionContext subscriptionContext); Subscription createAndSaveSubscription(NotificationSubscriptionContext subscriptionContext); List<Subscription> getSubscriptions(Identity identity);  }
@Test public void getSubscriber_SubscripberExist() { when(subscriptionDelegateTestObject.subscriberDao.findSubscriber(subscriberIdentity)).thenReturn(subscriber); Subscriber resultSubscriber = subscriptionDelegateTestObject.getSubscriber(subscriberIdentity); assertEquals("getSubscriber return wrong subscriber", subscriber, resultSubscriber); }
@Test public void getSubscriber_SubscripberMustBeCreated() { when(subscriptionDelegateTestObject.subscriberDao.findSubscriber(subscriberIdentity)).thenReturn(null); when(subscriptionDelegateTestObject.subscriberDao.createAndSaveSubscriber(subscriberIdentity)).thenReturn(subscriber); Subscriber resultSubscriber = subscriptionDelegateTestObject.getSubscriber(subscriberIdentity); assertEquals("getSubscriber returns wrong subscriber", subscriber, resultSubscriber); }