package org.xbib.datastructures.immutable.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.xbib.datastructures.immutable.ImmutableList;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class CollectionTest {

    @Test
    public void givenUsingWhenUnmodifiableListIsCreatedThenNotModifiable() {
        assertThrows(UnsupportedOperationException.class, () -> {
            List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
            List<String> unmodifiableList = ImmutableList.copyOf(list);
            unmodifiableList.add("four");
        });
    }

    @Test
    public void givenUsingBuilderWhenUnmodifiableListIsCreatedThenNoLongerModifiable() {
        assertThrows(UnsupportedOperationException.class, () -> {
            List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
            ImmutableList<String> unmodifiableList = ImmutableList.<String>builder().addAll(list).build();
            unmodifiableList.add("four");
        });
    }
}
