Skip to content

Commit 3dae09a

Browse files
authored
Merge pull request #5388 from JabRef/enableFetcherTEst
Renenable WebFetchers test
2 parents c4df3b2 + c9fa745 commit 3dae09a

File tree

3 files changed

+51
-28
lines changed

3 files changed

+51
-28
lines changed

build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ dependencies {
198198
exclude module: "log4j-core"
199199
}
200200

201+
202+
testCompile 'io.github.classgraph:classgraph:4.8.47'
201203
testCompile 'junit:junit:4.12'
202204
testImplementation 'org.junit.jupiter:junit-jupiter:5.5.2'
203205
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.5.2'
@@ -208,9 +210,6 @@ dependencies {
208210
testRuntime group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '3.0.0-20190915.182552-364'
209211
testCompile 'org.mockito:mockito-core:3.1.0'
210212
//testCompile 'com.github.tomakehurst:wiremock:2.24.1'
211-
testCompile ('org.reflections:reflections:0.9.11') {
212-
exclude module: "jsr305"
213-
}
214213
testCompile 'org.xmlunit:xmlunit-core:2.6.3'
215214
testCompile 'org.xmlunit:xmlunit-matchers:2.6.3'
216215
testCompile 'com.tngtech.archunit:archunit-junit5-api:0.11.0'

src/test/java/module-info.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@
3838
--add-opens
3939
// Needed for localization tests
4040
javafx.fxml/javafx.fxml=org.jabref
41+
42+
--add-modules
43+
io.github.classgraph
44+
45+
--add-reads
46+
org.jabref=io.github.classgraph

src/test/java/org/jabref/logic/importer/WebFetchersTest.java

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@
1010
import org.jabref.logic.importer.fetcher.IsbnViaOttoBibFetcher;
1111
import org.jabref.logic.importer.fetcher.MrDLibFetcher;
1212

13+
import io.github.classgraph.ClassGraph;
14+
import io.github.classgraph.ClassInfoList;
15+
import io.github.classgraph.ScanResult;
1316
import org.junit.jupiter.api.BeforeEach;
14-
import org.junit.jupiter.api.Disabled;
1517
import org.junit.jupiter.api.Test;
16-
import org.reflections.Reflections;
1718

1819
import static org.junit.jupiter.api.Assertions.assertEquals;
1920
import static org.mockito.Mockito.mock;
2021

21-
// TODO: Reenable as soon as https://github.com/ronmamo/reflections/issues/202 is fixed
22-
@Disabled
2322
class WebFetchersTest {
2423

25-
private Reflections reflections = new Reflections("org.jabref");
2624
private ImportFormatPreferences importFormatPreferences;
25+
private ClassGraph classGraph = new ClassGraph().enableAllInfo().whitelistPackages("org.jabref");
2726

2827
@BeforeEach
2928
void setUp() throws Exception {
@@ -34,50 +33,69 @@ void setUp() throws Exception {
3433
void getIdBasedFetchersReturnsAllFetcherDerivingFromIdBasedFetcher() throws Exception {
3534
List<IdBasedFetcher> idFetchers = WebFetchers.getIdBasedFetchers(importFormatPreferences);
3635

37-
Set<Class<? extends IdBasedFetcher>> expected = reflections.getSubTypesOf(IdBasedFetcher.class);
38-
expected.remove(AbstractIsbnFetcher.class);
39-
expected.remove(IdBasedParserFetcher.class);
40-
// Remove special ISBN fetcher since we don't want to expose them to the user
41-
expected.remove(IsbnViaChimboriFetcher.class);
42-
expected.remove(IsbnViaEbookDeFetcher.class);
43-
expected.remove(IsbnViaOttoBibFetcher.class);
44-
assertEquals(expected, getClasses(idFetchers));
36+
try (ScanResult scanResult = classGraph.scan()) {
37+
38+
ClassInfoList controlClasses = scanResult.getClassesImplementing(IdBasedFetcher.class.getCanonicalName());
39+
Set<Class<?>> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet());
40+
41+
expected.remove(AbstractIsbnFetcher.class);
42+
expected.remove(IdBasedParserFetcher.class);
43+
// Remove special ISBN fetcher since we don't want to expose them to the user
44+
expected.remove(IsbnViaChimboriFetcher.class);
45+
expected.remove(IsbnViaEbookDeFetcher.class);
46+
expected.remove(IsbnViaOttoBibFetcher.class);
47+
assertEquals(expected, getClasses(idFetchers));
48+
}
4549
}
4650

4751
@Test
4852
void getEntryBasedFetchersReturnsAllFetcherDerivingFromEntryBasedFetcher() throws Exception {
4953
List<EntryBasedFetcher> idFetchers = WebFetchers.getEntryBasedFetchers(importFormatPreferences);
5054

51-
Set<Class<? extends EntryBasedFetcher>> expected = reflections.getSubTypesOf(EntryBasedFetcher.class);
52-
expected.remove(EntryBasedParserFetcher.class);
53-
expected.remove(MrDLibFetcher.class);
54-
assertEquals(expected, getClasses(idFetchers));
55+
try (ScanResult scanResult = classGraph.scan()) {
56+
ClassInfoList controlClasses = scanResult.getClassesImplementing(EntryBasedFetcher.class.getCanonicalName());
57+
Set<Class<?>> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet());
58+
59+
expected.remove(EntryBasedParserFetcher.class);
60+
expected.remove(MrDLibFetcher.class);
61+
assertEquals(expected, getClasses(idFetchers));
62+
}
5563
}
5664

5765
@Test
5866
void getSearchBasedFetchersReturnsAllFetcherDerivingFromSearchBasedFetcher() throws Exception {
5967
List<SearchBasedFetcher> searchBasedFetchers = WebFetchers.getSearchBasedFetchers(importFormatPreferences);
68+
try (ScanResult scanResult = classGraph.scan()) {
69+
ClassInfoList controlClasses = scanResult.getClassesImplementing(SearchBasedFetcher.class.getCanonicalName());
70+
Set<Class<?>> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet());
6071

61-
Set<Class<? extends SearchBasedFetcher>> expected = reflections.getSubTypesOf(SearchBasedFetcher.class);
62-
expected.remove(SearchBasedParserFetcher.class);
63-
assertEquals(expected, getClasses(searchBasedFetchers));
72+
expected.remove(SearchBasedParserFetcher.class);
73+
assertEquals(expected, getClasses(searchBasedFetchers));
74+
}
6475
}
6576

6677
@Test
6778
void getFullTextFetchersReturnsAllFetcherDerivingFromFullTextFetcher() throws Exception {
6879
List<FulltextFetcher> fullTextFetchers = WebFetchers.getFullTextFetchers(importFormatPreferences);
6980

70-
Set<Class<? extends FulltextFetcher>> expected = reflections.getSubTypesOf(FulltextFetcher.class);
71-
assertEquals(expected, getClasses(fullTextFetchers));
81+
try (ScanResult scanResult = classGraph.scan()) {
82+
ClassInfoList controlClasses = scanResult.getClassesImplementing(FulltextFetcher.class.getCanonicalName());
83+
Set<Class<?>> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet());
84+
assertEquals(expected, getClasses(fullTextFetchers));
85+
}
7286
}
7387

7488
@Test
7589
void getIdFetchersReturnsAllFetcherDerivingFromIdFetcher() throws Exception {
7690
List<IdFetcher> idFetchers = WebFetchers.getIdFetchers(importFormatPreferences);
7791

78-
Set<Class<? extends IdFetcher>> expected = reflections.getSubTypesOf(IdFetcher.class);
79-
expected.remove(IdParserFetcher.class);
80-
assertEquals(expected, getClasses(idFetchers));
92+
try (ScanResult scanResult = classGraph.scan()) {
93+
ClassInfoList controlClasses = scanResult.getClassesImplementing(IdFetcher.class.getCanonicalName());
94+
Set<Class<?>> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet());
95+
96+
expected.remove(IdParserFetcher.class);
97+
assertEquals(expected, getClasses(idFetchers));
98+
}
8199
}
82100

83101
private Set<? extends Class<?>> getClasses(List<?> objects) {

0 commit comments

Comments
 (0)