forked from classgraph/classgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test cases for package whitelisting and subclasses. Some are broken.
- Loading branch information
caillette
committed
Jul 23, 2015
1 parent
94b9a89
commit 0922b9f
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/test/java/io/github/lukehutch/fastclasspathscanner/FastClasspathScannerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.github.lukehutch.fastclasspathscanner; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
|
||
public class FastClasspathScannerTest { | ||
|
||
@Test | ||
public void scanAll() throws Exception { | ||
final FastClasspathScanner scanner = new FastClasspathScanner() ; | ||
scanner.scan() ; | ||
final List< String > subclasses = scanner.getSubclassesOf( FastClasspathScannerTest.class ) ; | ||
|
||
assertTrue( subclasses.size() > 0 ) ; | ||
assertTrue( subclasses.contains( Subclass.class.getName() ) ) ; | ||
} | ||
|
||
@Test | ||
public void scanWithWhitelist() throws Exception { | ||
final FastClasspathScanner scanner = new FastClasspathScanner( PACKAGE_NAME ) ; | ||
scanner.scan() ; | ||
final List< String > subclasses = scanner.getSubclassesOf( FastClasspathScannerTest.class ) ; | ||
|
||
assertTrue( subclasses.size() > 0 ) ; | ||
assertTrue( subclasses.contains( Subclass.class.getName() ) ) ; | ||
} | ||
|
||
@Test | ||
public void scanWithFileFilter() throws Exception { | ||
final FastClasspathScanner scanner = new FastClasspathScanner() ; | ||
scanner | ||
.matchFilenamePattern( | ||
".*" + PACKAGE_NAME + "[$_a-zA-Z0-9]+\\.class", | ||
( absolutePath, relativePath, inputStream ) -> { } | ||
) | ||
.scan() ; | ||
final List< String > subclasses = scanner.getSubclassesOf( FastClasspathScannerTest.class ) ; | ||
|
||
assertTrue( subclasses.size() > 0 ) ; | ||
assertTrue( subclasses.contains( Subclass.class.getName() ) ) ; | ||
} | ||
|
||
@Test | ||
public void match() throws Exception { | ||
final List< Class > collector = new ArrayList<>() ; | ||
final FastClasspathScanner scanner = new FastClasspathScanner() | ||
.matchSubclassesOf( FastClasspathScanner.class, collector::add ) | ||
; | ||
scanner.scan() ; | ||
|
||
assertTrue( collector.size() > 0 ) ; | ||
assertTrue( collector.contains( Subclass.class ) ) ; | ||
} | ||
|
||
@Test | ||
public void matchWithWhitelist() throws Exception { | ||
final List< Class > collector = new ArrayList<>() ; | ||
final FastClasspathScanner scanner = new FastClasspathScanner( PACKAGE_NAME ) | ||
.matchSubclassesOf( FastClasspathScanner.class, collector::add ) | ||
; | ||
scanner.scan() ; | ||
|
||
assertTrue( collector.size() > 0 ) ; | ||
assertTrue( collector.contains( Subclass.class ) ) ; | ||
} | ||
|
||
|
||
public static class Subclass extends FastClasspathScannerTest { } | ||
|
||
private static final String PACKAGE_NAME = FastClasspathScannerTest.class.getPackage().getName() ; | ||
|
||
|
||
} |