diff --git a/build.gradle b/build.gradle index b3d7851f76a..6ffe8939ed0 100644 --- a/build.gradle +++ b/build.gradle @@ -197,6 +197,8 @@ dependencies { exclude module: "log4j-core" } + + testCompile 'io.github.classgraph:classgraph:4.8.47' testCompile 'junit:junit:4.12' testImplementation 'org.junit.jupiter:junit-jupiter:5.5.2' testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.5.2' @@ -207,9 +209,6 @@ dependencies { testRuntime group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '3.0.0-20190915.182552-364' testCompile 'org.mockito:mockito-core:3.0.0' //testCompile 'com.github.tomakehurst:wiremock:2.24.1' - testCompile ('org.reflections:reflections:0.9.11') { - exclude module: "jsr305" - } testCompile 'org.xmlunit:xmlunit-core:2.6.3' testCompile 'org.xmlunit:xmlunit-matchers:2.6.3' testCompile 'com.tngtech.archunit:archunit-junit5-api:0.11.0' diff --git a/src/test/java/module-info.test b/src/test/java/module-info.test index 46486381c1d..490bf7f6791 100644 --- a/src/test/java/module-info.test +++ b/src/test/java/module-info.test @@ -38,3 +38,9 @@ --add-opens // Needed for localization tests javafx.fxml/javafx.fxml=org.jabref + +--add-modules + io.github.classgraph + +--add-reads + org.jabref=io.github.classgraph diff --git a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java index 52eb02bbc46..58b2e3b15fd 100644 --- a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java +++ b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java @@ -10,20 +10,19 @@ import org.jabref.logic.importer.fetcher.IsbnViaOttoBibFetcher; import org.jabref.logic.importer.fetcher.MrDLibFetcher; +import io.github.classgraph.ClassGraph; +import io.github.classgraph.ClassInfoList; +import io.github.classgraph.ScanResult; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.reflections.Reflections; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -// TODO: Reenable as soon as https://github.com/ronmamo/reflections/issues/202 is fixed -@Disabled class WebFetchersTest { - private Reflections reflections = new Reflections("org.jabref"); private ImportFormatPreferences importFormatPreferences; + private ClassGraph classGraph = new ClassGraph().enableAllInfo().whitelistPackages("org.jabref"); @BeforeEach void setUp() throws Exception { @@ -34,50 +33,69 @@ void setUp() throws Exception { void getIdBasedFetchersReturnsAllFetcherDerivingFromIdBasedFetcher() throws Exception { List idFetchers = WebFetchers.getIdBasedFetchers(importFormatPreferences); - Set> expected = reflections.getSubTypesOf(IdBasedFetcher.class); - expected.remove(AbstractIsbnFetcher.class); - expected.remove(IdBasedParserFetcher.class); - // Remove special ISBN fetcher since we don't want to expose them to the user - expected.remove(IsbnViaChimboriFetcher.class); - expected.remove(IsbnViaEbookDeFetcher.class); - expected.remove(IsbnViaOttoBibFetcher.class); - assertEquals(expected, getClasses(idFetchers)); + try (ScanResult scanResult = classGraph.scan()) { + + ClassInfoList controlClasses = scanResult.getClassesImplementing(IdBasedFetcher.class.getCanonicalName()); + Set> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet()); + + expected.remove(AbstractIsbnFetcher.class); + expected.remove(IdBasedParserFetcher.class); + // Remove special ISBN fetcher since we don't want to expose them to the user + expected.remove(IsbnViaChimboriFetcher.class); + expected.remove(IsbnViaEbookDeFetcher.class); + expected.remove(IsbnViaOttoBibFetcher.class); + assertEquals(expected, getClasses(idFetchers)); + } } @Test void getEntryBasedFetchersReturnsAllFetcherDerivingFromEntryBasedFetcher() throws Exception { List idFetchers = WebFetchers.getEntryBasedFetchers(importFormatPreferences); - Set> expected = reflections.getSubTypesOf(EntryBasedFetcher.class); - expected.remove(EntryBasedParserFetcher.class); - expected.remove(MrDLibFetcher.class); - assertEquals(expected, getClasses(idFetchers)); + try (ScanResult scanResult = classGraph.scan()) { + ClassInfoList controlClasses = scanResult.getClassesImplementing(EntryBasedFetcher.class.getCanonicalName()); + Set> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet()); + + expected.remove(EntryBasedParserFetcher.class); + expected.remove(MrDLibFetcher.class); + assertEquals(expected, getClasses(idFetchers)); + } } @Test void getSearchBasedFetchersReturnsAllFetcherDerivingFromSearchBasedFetcher() throws Exception { List searchBasedFetchers = WebFetchers.getSearchBasedFetchers(importFormatPreferences); + try (ScanResult scanResult = classGraph.scan()) { + ClassInfoList controlClasses = scanResult.getClassesImplementing(SearchBasedFetcher.class.getCanonicalName()); + Set> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet()); - Set> expected = reflections.getSubTypesOf(SearchBasedFetcher.class); - expected.remove(SearchBasedParserFetcher.class); - assertEquals(expected, getClasses(searchBasedFetchers)); + expected.remove(SearchBasedParserFetcher.class); + assertEquals(expected, getClasses(searchBasedFetchers)); + } } @Test void getFullTextFetchersReturnsAllFetcherDerivingFromFullTextFetcher() throws Exception { List fullTextFetchers = WebFetchers.getFullTextFetchers(importFormatPreferences); - Set> expected = reflections.getSubTypesOf(FulltextFetcher.class); - assertEquals(expected, getClasses(fullTextFetchers)); + try (ScanResult scanResult = classGraph.scan()) { + ClassInfoList controlClasses = scanResult.getClassesImplementing(FulltextFetcher.class.getCanonicalName()); + Set> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet()); + assertEquals(expected, getClasses(fullTextFetchers)); + } } @Test void getIdFetchersReturnsAllFetcherDerivingFromIdFetcher() throws Exception { List idFetchers = WebFetchers.getIdFetchers(importFormatPreferences); - Set> expected = reflections.getSubTypesOf(IdFetcher.class); - expected.remove(IdParserFetcher.class); - assertEquals(expected, getClasses(idFetchers)); + try (ScanResult scanResult = classGraph.scan()) { + ClassInfoList controlClasses = scanResult.getClassesImplementing(IdFetcher.class.getCanonicalName()); + Set> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet()); + + expected.remove(IdParserFetcher.class); + assertEquals(expected, getClasses(idFetchers)); + } } private Set> getClasses(List objects) {