/*
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.generic;

import java.util.function.Function;
import java.util.function.IntFunction;

import static org.junit.Assert.*;
import org.junit.Test;

/**
 *
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 */
public class EnumUtilsTest {

    @Test
    public void testIntMap() {
        IntFunction<MyEnum> map = EnumUtils.lookupInt(MyEnum.class, e -> e.v);

        assertEquals(MyEnum.CONST, map.apply(8));
        assertEquals(MyEnum.ITEM, map.apply(4));
        assertNull(map.apply(17));
    }
    
    @Test
    public void testMap() {
        Function<String, MyEnum> map = EnumUtils.lookup(MyEnum.class, e -> e.name().toLowerCase());

        assertEquals(MyEnum.CONST, map.apply("const"));
        assertEquals(MyEnum.ENTRY, map.apply("entry"));
        assertNull(null, map.apply("ENTRY"));
        assertNull(null, map.apply("x"));
    }
    
    
    private enum MyEnum {
        VALUE(1),
        ITEM(4),
        ENTRY(2),
        CONST(8);
        
        private final int v;

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

    }
    
}
