Components registration - package scanning
This commit is contained in:
parent
0c23f613d6
commit
6d0753c7a8
11 changed files with 169 additions and 2 deletions
src/test/java
info/ebenoit/ebul/cmp
test
|
@ -5,12 +5,20 @@ import org.junit.Test;
|
|||
|
||||
import info.ebenoit.ebul.func.ThrowingBiConsumer;
|
||||
import info.ebenoit.ebul.func.ThrowingConsumer;
|
||||
import test.inherited.CBase;
|
||||
import test.inherited.CChild;
|
||||
import test.inherited.CChildOfAbstract;
|
||||
import test.interfaces.CImplementation;
|
||||
import test.simple.CSimple;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
|
||||
|
@ -889,4 +897,51 @@ public class TestNewComponentInfo
|
|||
injector.accept( cmp , inject );
|
||||
assertSame( inject , cmp.dependency );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test: {@link NewComponentInfo#scanPackage(String, boolean)} finds a simple {@link Component}-annotated class
|
||||
*/
|
||||
@Test
|
||||
public void testScanPackageSimple( )
|
||||
throws ComponentDefinitionException , ClassNotFoundException , IOException
|
||||
{
|
||||
ArrayList< NewComponentInfo< ? > > result = NewComponentInfo.scanPackage( "test.simple" , false );
|
||||
assertEquals( 1 , result.size( ) );
|
||||
assertSame( CSimple.class , result.get( 0 ).getSupplier( ).get( ).getClass( ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test: {@link NewComponentInfo#scanPackage(String, boolean)} finds components that inherit each other, ignoring
|
||||
* abstract classes
|
||||
*/
|
||||
@Test
|
||||
public void testScanPackageInheritance( )
|
||||
throws ComponentDefinitionException , ClassNotFoundException , IOException
|
||||
{
|
||||
ArrayList< NewComponentInfo< ? > > result = NewComponentInfo.scanPackage( "test.inherited" , false );
|
||||
assertEquals( 3 , result.size( ) );
|
||||
|
||||
Set< ? > classes = result.stream( ).map( x -> x.getSupplier( ).get( ).getClass( ) )
|
||||
.collect( Collectors.toSet( ) );
|
||||
assertTrue( classes.contains( CBase.class ) );
|
||||
assertTrue( classes.contains( CChild.class ) );
|
||||
assertTrue( classes.contains( CChildOfAbstract.class ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test: {@link NewComponentInfo#scanPackage(String, boolean)} finds components defined by implementing a
|
||||
* {@link Component}-annotated interface
|
||||
*/
|
||||
@Test
|
||||
public void testScanPackageInterfaces( )
|
||||
throws ComponentDefinitionException , ClassNotFoundException , IOException
|
||||
{
|
||||
ArrayList< NewComponentInfo< ? > > result = NewComponentInfo.scanPackage( "test.interfaces" , false );
|
||||
assertEquals( 1 , result.size( ) );
|
||||
|
||||
assertSame( CImplementation.class , result.get( 0 ).getSupplier( ).get( ).getClass( ) );
|
||||
}
|
||||
}
|
||||
|
|
9
src/test/java/test/inherited/CAbstractBase.java
Normal file
9
src/test/java/test/inherited/CAbstractBase.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package test.inherited;
|
||||
|
||||
import info.ebenoit.ebul.cmp.Component;
|
||||
|
||||
@Component
|
||||
public abstract class CAbstractBase
|
||||
{
|
||||
// EMPTY
|
||||
}
|
8
src/test/java/test/inherited/CAbstractChild.java
Normal file
8
src/test/java/test/inherited/CAbstractChild.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package test.inherited;
|
||||
|
||||
|
||||
public abstract class CAbstractChild
|
||||
extends CBase
|
||||
{
|
||||
// EMPTY
|
||||
}
|
12
src/test/java/test/inherited/CBase.java
Normal file
12
src/test/java/test/inherited/CBase.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package test.inherited;
|
||||
|
||||
|
||||
import info.ebenoit.ebul.cmp.Component;
|
||||
|
||||
|
||||
|
||||
@Component
|
||||
public class CBase
|
||||
{
|
||||
// EMPTY
|
||||
}
|
8
src/test/java/test/inherited/CChild.java
Normal file
8
src/test/java/test/inherited/CChild.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package test.inherited;
|
||||
|
||||
|
||||
public class CChild
|
||||
extends CBase
|
||||
{
|
||||
// EMPTY
|
||||
}
|
8
src/test/java/test/inherited/CChildOfAbstract.java
Normal file
8
src/test/java/test/inherited/CChildOfAbstract.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package test.inherited;
|
||||
|
||||
|
||||
public class CChildOfAbstract
|
||||
extends CAbstractBase
|
||||
{
|
||||
|
||||
}
|
8
src/test/java/test/interfaces/CImplementation.java
Normal file
8
src/test/java/test/interfaces/CImplementation.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package test.interfaces;
|
||||
|
||||
|
||||
public class CImplementation
|
||||
implements CInterface
|
||||
{
|
||||
// EMPTY
|
||||
}
|
12
src/test/java/test/interfaces/CInterface.java
Normal file
12
src/test/java/test/interfaces/CInterface.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package test.interfaces;
|
||||
|
||||
|
||||
import info.ebenoit.ebul.cmp.Component;
|
||||
|
||||
|
||||
|
||||
@Component
|
||||
public interface CInterface
|
||||
{
|
||||
// EMPTY
|
||||
}
|
12
src/test/java/test/simple/CSimple.java
Normal file
12
src/test/java/test/simple/CSimple.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package test.simple;
|
||||
|
||||
|
||||
import info.ebenoit.ebul.cmp.Component;
|
||||
|
||||
|
||||
|
||||
@Component
|
||||
public class CSimple
|
||||
{
|
||||
// EMPTY
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue