package org.implab.gradle.variants.sources.internal;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.gradle.api.InvalidUserDataException;
import org.junit.jupiter.api.Test;

class DefaultLateConfigurationPolicySpecTest {
    @Test
    void usesFailModeByDefault() {
        var policy = new DefaultLateConfigurationPolicySpec();

        assertEquals(LateConfigurationMode.FAIL, policy.mode());
    }

    @Test
    void switchesToWarnModeWhenSelected() {
        var policy = new DefaultLateConfigurationPolicySpec();

        policy.warnOnLateConfiguration();

        assertEquals(LateConfigurationMode.WARN, policy.mode());
    }

    @Test
    void switchesToApplyModeWhenSelected() {
        var policy = new DefaultLateConfigurationPolicySpec();

        policy.allowLateConfiguration();

        assertEquals(LateConfigurationMode.APPLY, policy.mode());
    }

    @Test
    void rejectsChangingPolicyAfterItWasSelected() {
        var policy = new DefaultLateConfigurationPolicySpec();

        policy.warnOnLateConfiguration();

        assertThrows(InvalidUserDataException.class, policy::failOnLateConfiguration);
    }

    @Test
    void rejectsChangingPolicyAfterItWasFinalized() {
        var policy = new DefaultLateConfigurationPolicySpec();

        policy.finalizePolicy();

        assertThrows(InvalidUserDataException.class, policy::allowLateConfiguration);
    }
}
