@Test @Ignore public void shouldSubscribeOnlyOnceForContest() throws Exception { IActivitySubscription asp3 = activitiesService.subscribe(111132, ActivityCategory.CONTEST, 22241); IActivitySubscription asp4 = activitiesService.subscribe(111132, ActivityCategory.CONTEST, 22241); assertEquals(asp3.getId(), asp4.getId()); }
public IActivitySubscription subscribe(long userId, ActivityCategory activityCategory, long categoryId) { if (activitySubscriptionDao.isSubscribed(activityCategory, userId, categoryId)) { return activitySubscriptionDao .get(activityCategory, userId, categoryId) .orElseThrow(IllegalStateException::new); } switch (activityCategory) { case CONTEST: return subscribeContest(userId, categoryId); case PROPOSAL: return subscribeProposal(userId, categoryId, false); case DISCUSSION: return subscribeDiscussion(userId, categoryId, false); case MEMBER: return createSubscription(userId, activityCategory, categoryId, 0); default: throw new IllegalArgumentException( "ActivityCategory " + activityCategory.name() + " not supported"); } }
ActivitiesService { public IActivitySubscription subscribe(long userId, ActivityCategory activityCategory, long categoryId) { if (activitySubscriptionDao.isSubscribed(activityCategory, userId, categoryId)) { return activitySubscriptionDao .get(activityCategory, userId, categoryId) .orElseThrow(IllegalStateException::new); } switch (activityCategory) { case CONTEST: return subscribeContest(userId, categoryId); case PROPOSAL: return subscribeProposal(userId, categoryId, false); case DISCUSSION: return subscribeDiscussion(userId, categoryId, false); case MEMBER: return createSubscription(userId, activityCategory, categoryId, 0); default: throw new IllegalArgumentException( "ActivityCategory " + activityCategory.name() + " not supported"); } } }
ActivitiesService { public IActivitySubscription subscribe(long userId, ActivityCategory activityCategory, long categoryId) { if (activitySubscriptionDao.isSubscribed(activityCategory, userId, categoryId)) { return activitySubscriptionDao .get(activityCategory, userId, categoryId) .orElseThrow(IllegalStateException::new); } switch (activityCategory) { case CONTEST: return subscribeContest(userId, categoryId); case PROPOSAL: return subscribeProposal(userId, categoryId, false); case DISCUSSION: return subscribeDiscussion(userId, categoryId, false); case MEMBER: return createSubscription(userId, activityCategory, categoryId, 0); default: throw new IllegalArgumentException( "ActivityCategory " + activityCategory.name() + " not supported"); } } @Autowired  ActivitiesService(ActivitySubscriptionDao activitySubscriptionDao,
            IContestClient contestClient, IProposalClient proposalClient); }
ActivitiesService { public IActivitySubscription subscribe(long userId, ActivityCategory activityCategory, long categoryId) { if (activitySubscriptionDao.isSubscribed(activityCategory, userId, categoryId)) { return activitySubscriptionDao .get(activityCategory, userId, categoryId) .orElseThrow(IllegalStateException::new); } switch (activityCategory) { case CONTEST: return subscribeContest(userId, categoryId); case PROPOSAL: return subscribeProposal(userId, categoryId, false); case DISCUSSION: return subscribeDiscussion(userId, categoryId, false); case MEMBER: return createSubscription(userId, activityCategory, categoryId, 0); default: throw new IllegalArgumentException( "ActivityCategory " + activityCategory.name() + " not supported"); } } @Autowired  ActivitiesService(ActivitySubscriptionDao activitySubscriptionDao,
            IContestClient contestClient, IProposalClient proposalClient); IActivitySubscription subscribe(long userId,
            ActivityCategory activityCategory, long categoryId); boolean unsubscribe(long userId, ActivityCategory activityCategory, long categoryId); }
ActivitiesService { public IActivitySubscription subscribe(long userId, ActivityCategory activityCategory, long categoryId) { if (activitySubscriptionDao.isSubscribed(activityCategory, userId, categoryId)) { return activitySubscriptionDao .get(activityCategory, userId, categoryId) .orElseThrow(IllegalStateException::new); } switch (activityCategory) { case CONTEST: return subscribeContest(userId, categoryId); case PROPOSAL: return subscribeProposal(userId, categoryId, false); case DISCUSSION: return subscribeDiscussion(userId, categoryId, false); case MEMBER: return createSubscription(userId, activityCategory, categoryId, 0); default: throw new IllegalArgumentException( "ActivityCategory " + activityCategory.name() + " not supported"); } } @Autowired  ActivitiesService(ActivitySubscriptionDao activitySubscriptionDao,
            IContestClient contestClient, IProposalClient proposalClient); IActivitySubscription subscribe(long userId,
            ActivityCategory activityCategory, long categoryId); boolean unsubscribe(long userId, ActivityCategory activityCategory, long categoryId);  }