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

import java.util.AbstractMap;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import net.ranides.assira.collection.ListUtils;
import net.ranides.assira.collection.map.LazyMap;
import net.ranides.assira.reflection.mock.ForClassInspector.*;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class ClassInspectorTest {
    
    public ClassInspectorTest() {
    }

    @Test
    public void testForName() {
        assertEquals(Map.class, ClassInspector.forName("java.util.Map"));
        assertEquals(MapA.class, ClassInspector.forName("net.ranides.assira.reflection.mock.ForClassInspector$MapA"));
    }
    
    @Test
    public void testForObject() {
        assertEquals(Object.class, ClassInspector.forObject(new Object()));
        assertEquals(void.class, ClassInspector.forObject(null));
        assertEquals(Integer.class, ClassInspector.forObject(666));
        assertEquals(String.class, ClassInspector.forObject("Hello"));
        assertEquals(HashMap.class, ClassInspector.forObject(new HashMap<>()));
    }
    
    @Test
    public void testForObjects() {
        assertArrayEquals(new Class[]{Object.class}, ClassInspector.forObjects(new Object()));
        assertArrayEquals(new Class[]{}, ClassInspector.forObjects());
    }
    
    @Test
    public void testGetAncestors() {
        assertEquals(
            Arrays.asList(
                Object.class, 
                AbstractMap.class, 
                HashMap.class, 
                LazyMap.class, 
                MapA.class, 
                MapB.class, 
                MapC.class
            ), 
            ClassInspector.getAncestors(MapC.class)
        );
        assertEquals(
            Arrays.asList(MapA.class, MapB.class, MapC.class), 
            ClassInspector.getAncestors(MapC.class, LazyMap.class)
        );
    }
    
    @Test
    public void testInterfaces() {
        assertEquals(
            Arrays.asList(
                CB.class, 
                IntB.class, 
                CA.class, 
                IntA.class, 
                Object.class
            ), 
            ListUtils.asList(ClassInspector.getAncestorTree(CB.class))
        );
    }
    
    @Test
    public void testInterfacesOnly() {
        assertEquals(
            Arrays.asList(
                IntB.class, 
                IntA.class
            ), 
            ListUtils.asList(ClassInspector.getInterfaces(CB.class))
        );
    }
    
}
