10
10
import org .jabref .logic .importer .fetcher .IsbnViaOttoBibFetcher ;
11
11
import org .jabref .logic .importer .fetcher .MrDLibFetcher ;
12
12
13
+ import io .github .classgraph .ClassGraph ;
14
+ import io .github .classgraph .ClassInfoList ;
15
+ import io .github .classgraph .ScanResult ;
13
16
import org .junit .jupiter .api .BeforeEach ;
14
- import org .junit .jupiter .api .Disabled ;
15
17
import org .junit .jupiter .api .Test ;
16
- import org .reflections .Reflections ;
17
18
18
19
import static org .junit .jupiter .api .Assertions .assertEquals ;
19
20
import static org .mockito .Mockito .mock ;
20
21
21
- // TODO: Reenable as soon as https://github.com/ronmamo/reflections/issues/202 is fixed
22
- @ Disabled
23
22
class WebFetchersTest {
24
23
25
- private Reflections reflections = new Reflections ("org.jabref" );
26
24
private ImportFormatPreferences importFormatPreferences ;
25
+ private ClassGraph classGraph = new ClassGraph ().enableAllInfo ().whitelistPackages ("org.jabref" );
27
26
28
27
@ BeforeEach
29
28
void setUp () throws Exception {
@@ -34,50 +33,69 @@ void setUp() throws Exception {
34
33
void getIdBasedFetchersReturnsAllFetcherDerivingFromIdBasedFetcher () throws Exception {
35
34
List <IdBasedFetcher > idFetchers = WebFetchers .getIdBasedFetchers (importFormatPreferences );
36
35
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
+ }
45
49
}
46
50
47
51
@ Test
48
52
void getEntryBasedFetchersReturnsAllFetcherDerivingFromEntryBasedFetcher () throws Exception {
49
53
List <EntryBasedFetcher > idFetchers = WebFetchers .getEntryBasedFetchers (importFormatPreferences );
50
54
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
+ }
55
63
}
56
64
57
65
@ Test
58
66
void getSearchBasedFetchersReturnsAllFetcherDerivingFromSearchBasedFetcher () throws Exception {
59
67
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 ());
60
71
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
+ }
64
75
}
65
76
66
77
@ Test
67
78
void getFullTextFetchersReturnsAllFetcherDerivingFromFullTextFetcher () throws Exception {
68
79
List <FulltextFetcher > fullTextFetchers = WebFetchers .getFullTextFetchers (importFormatPreferences );
69
80
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
+ }
72
86
}
73
87
74
88
@ Test
75
89
void getIdFetchersReturnsAllFetcherDerivingFromIdFetcher () throws Exception {
76
90
List <IdFetcher > idFetchers = WebFetchers .getIdFetchers (importFormatPreferences );
77
91
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
+ }
81
99
}
82
100
83
101
private Set <? extends Class <?>> getClasses (List <?> objects ) {
0 commit comments