From 1197cb6723ecd82dfdc252f574d9a1d907e030df Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 4 Oct 2019 15:11:16 +0200 Subject: [PATCH 1/2] Renenable WebFetchers test Replace outdated reflection library with classgraph library --- build.gradle | 5 +- src/main/java/module-info.java | 1 + .../logic/importer/WebFetchersTest.java | 68 ++++++++++++------- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/build.gradle b/build.gradle index 2a95dc4d428..06104953c9d 100644 --- a/build.gradle +++ b/build.gradle @@ -197,6 +197,8 @@ dependencies { exclude module: "log4j-core" } + + compile "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/main/java/module-info.java b/src/main/java/module-info.java index 791e2e50698..93a21e2bbf0 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -65,4 +65,5 @@ requires de.saxsys.mvvmfx.validation; requires richtextfx; requires unirest.java; + requires 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) { From c9fa7455fc9e414564f5c308994173e2ebac01ae Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 5 Oct 2019 18:54:01 +0200 Subject: [PATCH 2/2] move to testcompile --- build.gradle | 2 +- src/main/java/module-info.java | 1 - src/test/java/module-info.test | 6 ++++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index d66d566aff1..6ffe8939ed0 100644 --- a/build.gradle +++ b/build.gradle @@ -198,7 +198,7 @@ dependencies { } - compile "io.github.classgraph:classgraph:4.8.47" + 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' diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 93a21e2bbf0..791e2e50698 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -65,5 +65,4 @@ requires de.saxsys.mvvmfx.validation; requires richtextfx; requires unirest.java; - requires io.github.classgraph; } 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