package com.atlassian.stash.internal.scheduling;

import com.atlassian.bitbucket.timezone.TimeZoneService;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import java.time.ZoneOffset;
import java.util.TimeZone;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;

public class ApplicationCaesiumSchedulerConfigurationTest {


    private static final int REFRESH_INTERVAL_IN_MINUTES = 1;
    private static final int WORKER_THREAD_COUNT = 1;
    @Rule
    public MockitoRule rule = MockitoJUnit.rule();

    @Mock
    private TimeZoneService service;

    private ApplicationCaesiumSchedulerConfiguration configuration;

    @Before
    public void setup() {
        configuration = new ApplicationCaesiumSchedulerConfiguration(service, REFRESH_INTERVAL_IN_MINUTES,
                WORKER_THREAD_COUNT);
    }

    @Test
    public void testGetDefaultTimeZoneReturnsJvmTz() {
        when(service.getDefaultTimeZone()).thenReturn(ZoneOffset.MAX);

        //We return the JVM timezone because we want the tasks to be scheduled against the server's actual clock.
        assertThat(configuration.getDefaultTimeZone(), Matchers.equalTo(TimeZone.getTimeZone(ZoneOffset.MAX)));
    }
}