class SubscriptionService {

    public void addSubscription(Subscription subscription, String alarmId) {
        validateSubscription(subscription);

        if (this.searchSubscription(subscription, alarmId) != null) {
            LOGGER.debug("Identical subscription found (alarm id: {}).", alarmId);
            throw new DuplicateSubscriptionException("Attempting to add a subscription that already exists on alarm " + alarmId);
        }

        seyrenRepository.addSubscription(subscription, alarmId);
    }

}

class SubscriptionServiceTest {

    @InjectMocks
    private final SubscriptionService subscriptionService;
    @Mock
    private SeyrenRepository seyrenRepository;

    @Test
    public void addSubscriptionFailWithNoDayToSendAlert() throws Exception {

        Subscription subscription = TestUtils.getDefaultSubscription();
        String subId = "subTestId";
        subscription.setId(subId);
        subscription.setTarget("test@anotherteam.org");
        subscription.setSu(true);

        subscription.setMo(false);
        subscription.setTu(false);
        subscription.setWe(false);
        subscription.setTh(false);
        subscription.setFr(false);
        subscription.setSa(false);
        subscription.setSu(false);

        try {
            subscriptionService.addSubscription(subscription, TestUtils.DEFAULT_ALARM_ID);
            fail("Create a subscription with no alerting day should throw an exception");
        } catch (CerebroException ce) {
            assertEquals(ErrorCode.SUBSCRIPTION_INVALID, ce.getErrorCode());
        }
    }

}