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

import org.junit.Test;

import static org.junit.Assert.*;

public class UserNotificationSettingsTest {

    @Test
    public void testBuildsEmptySettings() throws Exception {
        UserNotificationSettings settings = new UserNotificationSettings.Builder().build();
        assertNull(settings.getSendMode());
        assertEquals(0, settings.getBatchFeatureDiscoveryShowCount());
    }

    @Test
    public void testBuildSettings() throws Exception {
        UserNotificationSettings settings = new UserNotificationSettings.Builder()
                .sendMode(SendMode.BATCHED)
                .batchFeatureDiscoveryShowCount(5)
                .build();
        assertEquals(SendMode.BATCHED, settings.getSendMode());
        assertEquals(5, settings.getBatchFeatureDiscoveryShowCount());
    }

    @Test
    public void testBuildWithExistingSettings() throws Exception {
        UserNotificationSettings settings = new UserNotificationSettings.Builder()
                .sendMode(SendMode.IMMEDIATE)
                .batchFeatureDiscoveryShowCount(4)
                .build();
        UserNotificationSettings newSettings = new UserNotificationSettings.Builder(settings).build();
        assertEquals(SendMode.IMMEDIATE, newSettings.getSendMode());
        assertEquals(4, newSettings.getBatchFeatureDiscoveryShowCount());
    }

    @Test
    public void testEquality() throws Exception {
        UserNotificationSettings settings1 = new UserNotificationSettings.Builder()
                .sendMode(SendMode.IMMEDIATE)
                .batchFeatureDiscoveryShowCount(4)
                .build();

        UserNotificationSettings settings2 = new UserNotificationSettings.Builder()
                .sendMode(SendMode.IMMEDIATE)
                .batchFeatureDiscoveryShowCount(4)
                .build();

        UserNotificationSettings settings3 = new UserNotificationSettings.Builder()
                .sendMode(SendMode.IMMEDIATE)
                .batchFeatureDiscoveryShowCount(5)
                .build();

        assertEquals(settings1, settings2);
        assertNotEquals(settings2, settings3);

        assertEquals(settings1.hashCode(), settings2.hashCode());
        assertNotEquals(settings2.hashCode(), settings3.hashCode());
    }
}
