package com.atlassian.bitbucket.installer.scripts;

import org.junit.Test;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class InstallAsServiceScreenTest extends BaseInstallerTest {

    private InstallAsServiceScreen installAsServiceScreen = new InstallAsServiceScreen(getContext(), getUtils());

    @Test
    public void testShouldShowScreen() throws Exception {
        assertShouldReturnTrueForInstallerFlags(true, true);
        assertShouldReturnFalseForInstallerFlags(false, true);
        assertShouldReturnFalseForInstallerFlags(true, false);
        assertShouldReturnFalseForInstallerFlags(false, false);
    }


    public void assertShouldReturnTrueForInstallerFlags(Boolean isAdmin, Boolean isNewInstall) throws Exception {
        when(getInstallationDetails().isAdmin()).thenReturn(isAdmin);
        when(getInstallationDetails().isNewInstall()).thenReturn(isNewInstall);

        Boolean result = installAsServiceScreen.shouldShowScreen();

        assertTrue(result);
    }

    public void assertShouldReturnFalseForInstallerFlags(Boolean isAdmin, Boolean isNewInstall) throws Exception {
        when(getInstallationDetails().isAdmin()).thenReturn(isAdmin);
        when(getInstallationDetails().isNewInstall()).thenReturn(isNewInstall);

        Boolean result = installAsServiceScreen.shouldShowScreen();

        assertFalse(result);
    }
}