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

import net.ranides.assira.annotations.Meta;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class ReflectUtilsTest {
    
    @Test
    public void testLocation() {
        String metaDir = ReflectUtils.getLocation(Meta.class);
        String metaFQN = ReflectUtils.getFQLocation(Meta.class);
        assertTrue( metaFQN.startsWith(metaDir));
        assertTrue( metaDir.matches(".+/target/.*classes/.*") );
        assertTrue( metaFQN.contains("net/ranides/assira/annotations/Meta"));
        
        String testDir = ReflectUtils.getLocation(ReflectUtilsTest.class);
        String testFQN = ReflectUtils.getFQLocation(ReflectUtilsTest.class);
        
        assertTrue( testFQN.startsWith(testDir));
        assertTrue( testDir.contains("target/test-classes/"));
        assertTrue( testFQN.contains("net/ranides/assira/reflection/util/ReflectUtilsTest"));
    }
    
    @Test
    public void testSourceCode() {
        String magic = "very specific magic text inside file 45275394261.";
        Inner inner = new Inner();
        
        assertTrue(ReflectUtils.getSource(getClass()).contains(magic));
        assertTrue(ReflectUtils.getSource(inner.getClass()).contains(magic));
        assertTrue(ReflectUtils.getSource(inner.noname.getClass()).contains(magic));
        
    }

    private static class Inner {
        public Object noname = new Object() {};
    }
}
