/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.reflection.impl;

import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.ranides.assira.collection.maps.HashMap;
import net.ranides.assira.generic.TypeToken;
import net.ranides.assira.reflection.IClass;
import org.junit.Test;
import static net.ranides.assira.junit.NewAssert.*;
import net.ranides.assira.reflection.IClasses;
import net.ranides.assira.reflection.mockup.ForIClass;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class GContextTest {
    
    @Test
    public void testGeneric() {
        IClass<?> exp = new TypeToken<List<Integer>>(){};
        IClass<?> nec = new TypeToken<List<String>>(){};

        IClass<?> ic = IClass.generic(List.class, Integer.class);
        assertSymEquals(exp, ic);
        assertEquals(Arrays.asList(ForIClass.I_INTEGER), ic.params());
        
        assertSymEquals(exp, ic.method("get").get().parent());
        assertNotEquals(nec, ic.method("get").get().parent());
        
        assertEquals(ForIClass.I_INTEGER, ic.method("get").get().returns());
        assertEquals(IClasses.typeinfo(int.class, Integer.class), ic.method("set").get().arguments().types());
    }
    
    @Test
    public void testGenericMap() {
        IClass<?> exp = new TypeToken<Map<List<Integer>, Float>>(){};
        IClass<?> nec = new TypeToken<Map<List<Double>, Float>>(){};
        
        IClass<?> ep1 = new TypeToken<List<Integer>>(){};
        IClass<?> ep2 = new TypeToken<Float>(){};
        
        IClass<?> ic = IClass.generic(Map.class, IClass.generic(List.class, Integer.class), ForIClass.FLOAT);
        assertSymEquals(ic, exp);
        assertEquals(Arrays.asList(ep1, ep2), ic.params());
        
        assertSymEquals(exp, ic.method("get").get().parent());
        assertNotEquals(nec, ic.method("get").get().parent());
        
        assertEquals(ep2, ic.method("get").get().returns());
        assertEquals(ep1, ic.method("put").get().arguments().types().first().get());
        
        Map<String, Type> expm = new HashMap<>();
        expm.put("K", List.class);
        expm.put("V", Float.class);
        assertEquals(expm, ic.context().map());
    }
    
}
