package net.ranides.assira.generic;

import org.junit.Assume;
import org.junit.Test;

import static org.junit.Assert.*;

public class EnumFactoryTest {

    @Test
    public void testNewInstance() {
        try {
            EnumFactory<MyEnum> factory = EnumFactory.forType(MyEnum.class);
            MyEnum value1 = factory.newValue("LAST", 6, 1024);
            factory.register(value1);

            assertEquals(value1.name(), "LAST");
            assertEquals(value1.ordinal(), 6);
            assertEquals(value1.v, 1024);
            assertEquals(MyEnum.values().length, 7);
        } catch (UnsupportedOperationException cause) {
            Assume.assumeTrue(cause.getMessage(), false);
        }
    }

    private enum MyEnum {
        VALUE(1),
        ITEM(4),
        ENTRY(2),
        CONST(8);

        private final int v;

        MyEnum(int v) {
            this.v = v;
        }

    }

}