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.junit.jupiter.api.Test;

class DefaultCompileUnitNamingPolicyTest {
    @Test
    void usesFailPolicyByDefault() {
        var policy = new DefaultCompileUnitNamingPolicy();

        assertEquals(NameCollisionPolicy.FAIL, policy.policy());
    }

    @Test
    void switchesToResolvePolicyWhenSelected() {
        var policy = new DefaultCompileUnitNamingPolicy();

        policy.resolveNameCollision();

        assertEquals(NameCollisionPolicy.RESOLVE, policy.policy());
    }

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

        policy.resolveNameCollision();

        assertThrows(IllegalStateException.class, policy::failOnNameCollision);
    }

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

        policy.finalizePolicy();

        assertThrows(IllegalStateException.class, policy::resolveNameCollision);
    }
}
