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

import java.io.IOException;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class PackageScannerTest {

    @Test
    public void testNameStream() throws IOException {
        String ns1 = "net.ranides.assira.junit";
        String ec1 = "net.ranides.assira.junit.LogObserver";
        
        String ns2 = "net.ranides.assira.reflection.util";
        String ec2 = "net.ranides.assira.reflection.util.PackageScanner";
        String ec3 = "net.ranides.assira.reflection.util.PackageScannerTest";
        
        assertTrue(PackageScanner.getNameStream(ns1).anyMatch(ec1::equals));
        assertTrue(PackageScanner.getNameStream(ns2).anyMatch(ec2::equals));
        assertTrue(PackageScanner.getNameStream(ns2).anyMatch(ec3::equals));
    }
    
    @Test
    public void testNames() throws IOException {
        String ns1 = "net.ranides.assira.junit";
        String ec1 = "net.ranides.assira.junit.LogObserver";
        
        String ns2 = "net.ranides.assira.reflection.util";
        String ec2 = "net.ranides.assira.reflection.util.PackageScanner";
        String ec3 = "net.ranides.assira.reflection.util.PackageScannerTest";
        
        assertTrue(PackageScanner.getNames(ns1).contains(ec1));
        assertTrue(PackageScanner.getNames(ns2).contains(ec2));
        assertTrue(PackageScanner.getNames(ns2).contains(ec3));
    }
    
    @Test
    public void testTypeStream() throws IOException {
        String ns1  = "net.ranides.assira.junit";
        Class<?> ec1 = net.ranides.assira.junit.LogObserver.class;
        
        String ns2  = "net.ranides.assira.reflection.util";
        Class<?> ec2 = net.ranides.assira.reflection.util.PackageScanner.class;
        Class<?> ec3 = net.ranides.assira.reflection.util.PackageScannerTest.class;
        
        assertTrue(PackageScanner.getTypeStream(ns1).anyMatch(ec1::equals));
        assertTrue(PackageScanner.getTypeStream(ns2).anyMatch(ec2::equals));
        assertTrue(PackageScanner.getTypeStream(ns2).anyMatch(ec3::equals));
    }
    
    @Test
    public void testTypes() throws IOException {
        String ns1  = "net.ranides.assira.junit";
        Class<?> ec1 = net.ranides.assira.junit.LogObserver.class;
        
        String ns2  = "net.ranides.assira.reflection.util";
        Class<?> ec2 = net.ranides.assira.reflection.util.PackageScanner.class;
        Class<?> ec3 = net.ranides.assira.reflection.util.PackageScannerTest.class;
        
        assertTrue(PackageScanner.getTypes(ns1).contains(ec1));
        assertTrue(PackageScanner.getTypes(ns2).contains(ec2));
        assertTrue(PackageScanner.getTypes(ns2).contains(ec3));
    }
    
}
