package com.atlassian.stash.internal.notification.handlers;

import com.atlassian.bitbucket.i18n.I18nKey;
import com.atlassian.stash.internal.notification.usersettings.SendMode;
import com.atlassian.bitbucket.user.ApplicationUser;
import org.junit.Before;
import org.mockito.Mock;

import java.util.Set;
import java.util.function.Function;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyMap;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;

public abstract class BaseNotificationHandlerTest {

    @Mock
    protected NotificationHelper notificationHelper;

    private final Set<ApplicationUser> filteredRecipients = mock(Set.class);

    @Before
    public void setupFilteredRecipients() {
        when(notificationHelper.filterBySendMode(any(Iterable.class), anySet())).thenReturn(filteredRecipients);
    }

    protected void verifySend(Object notification, Iterable<ApplicationUser> recipients, Set<SendMode> sendModes) {
        verify(notificationHelper).filterBySendMode(recipients, sendModes);
        verify(notificationHelper).renderAndSend(eq(notification), eq(filteredRecipients),
                any(I18nKey.class), anyString(), anyMap(), any(Function.class));
    }

    protected void verifyNoSend() {
        verify(notificationHelper, never()).renderAndSend(any(), any(Iterable.class),
                any(I18nKey.class), anyString(), anyMap(), any(Function.class));
    }
}
