SubscriptionDelegate { synchronized Publisher getPublisher(NotificationSubscriptionContext subscriptionContext) { Publisher publisher = publisherDao.findPublisher(subscriptionContext.getContextId(), subscriptionContext.getContextType(), subscriptionContext.getSourceId(), subscriptionContext.getSourceType()); if (publisher == null) { publisher = publisherDao.createAndSavePublisher(subscriptionContext.getContextId(), subscriptionContext.getContextType(), subscriptionContext.getSourceId(), subscriptionContext.getSourceType(), subscriptionContext.getSubcontextId()); } return publisher; }  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 getPublisher_PublisherExist() { when(subscriptionDelegateTestObject.publisherDao.findPublisher(contextId, contextType, sourceId, sourceType)).thenReturn(publisher); Publisher resultPublisher = subscriptionDelegateTestObject.getPublisher(subscriptionContext); assertEquals("getPublisher returns wrong publisher", publisher, resultPublisher); }
@Test public void getPublisher_PublisherMustBeCreated() { when(subscriptionDelegateTestObject.publisherDao.findPublisher(contextId, contextType, sourceId, sourceType)).thenReturn(null); when(subscriptionDelegateTestObject.publisherDao.createAndSavePublisher(contextId, contextType, sourceId, sourceType, subcontextId)).thenReturn(publisher); Publisher resultPublisher = subscriptionDelegateTestObject.getPublisher(subscriptionContext); assertEquals("getPublisher returns wrong publisher", publisher, resultPublisher); }