package de.assecutor.votianlt.service;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

class DemoSessionRegistryTest {

    private final DemoSessionRegistry registry = new DemoSessionRegistry();

    @Test
    void acquireAllowsSameSessionButBlocksOtherSessions() {
        assertThat(registry.acquire("session-a")).isTrue();
        assertThat(registry.acquire("session-a")).isTrue();
        assertThat(registry.acquire("session-b")).isFalse();
        assertThat(registry.isHeldBy("session-a")).isTrue();
        assertThat(registry.isHeldBy("session-b")).isFalse();
    }

    @Test
    void releaseFreesLockForNextSession() {
        assertThat(registry.acquire("session-a")).isTrue();

        registry.release("session-a");

        assertThat(registry.acquire("session-b")).isTrue();
        assertThat(registry.isHeldBy("session-b")).isTrue();
    }
}
