package p.studio.workspaces.framework;

import org.junit.jupiter.api.Test;

import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

final class StudioSubscriptionBagTest {
    @Test
    void clearUnsubscribesAllRegisteredSubscriptions() {
        final AtomicInteger unsubscribed = new AtomicInteger();
        final StudioSubscriptionBag bag = new StudioSubscriptionBag();

        bag.add(unsubscribed::incrementAndGet);
        bag.add(unsubscribed::incrementAndGet);

        assertFalse(bag.isEmpty());

        bag.clear();

        assertTrue(bag.isEmpty());
        org.junit.jupiter.api.Assertions.assertEquals(2, unsubscribed.get());
    }
}
