/*
 * @author Ranides Atterwim {@literal <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 {@literal <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.scanner().scope(ns1).names().matchAny(ec1::equals));
        assertTrue(PackageScanner.scanner().scope(ns2).names().matchAny(ec2::equals));
        assertTrue(PackageScanner.scanner().scope(ns2).names().matchAny(ec3::equals));
    }

    @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.scanner().scope(ns1).types().matchAny(ec1::equals));
        assertTrue(PackageScanner.scanner().scope(ns2).types().matchAny(ec2::equals));
        assertTrue(PackageScanner.scanner().scope(ns2).types().matchAny(ec3::equals));
    }

    @Test
    public void testFileStream() throws IOException {
        String ns1 = "net/ranides/assira/junit";
        String ec1 = "net/ranides/assira/junit/LogObserver.class";

        assertTrue(PackageScanner.scanner().directory(ns1).files().matchAny(ec1::equals));

        String ns2 = "reflective";
        String ec2 = "reflective/constructors-jdk8/4.txt";
        assertTrue(PackageScanner.scanner().directory(ns2).files().matchAny(ec2::equals));
    }
}
