66import java .net .URISyntaxException ;
77import java .nio .file .Files ;
88import java .nio .file .Path ;
9- import java .util .EnumSet ;
109import java .util .List ;
1110import java .util .Objects ;
1211
1514import org .jabref .logic .exporter .BibDatabaseWriter ;
1615import org .jabref .logic .exporter .ExportPreferences ;
1716import org .jabref .logic .exporter .SelfContainedSaveConfiguration ;
18- import org .jabref .logic .importer .ImportFormatPreferences ;
19- import org .jabref .logic .importer .ImporterPreferences ;
2017import org .jabref .logic .importer .fileformat .BibtexImporter ;
21- import org .jabref .logic .preferences .CliPreferences ;
22- import org .jabref .logic .search .SearchPreferences ;
2318import org .jabref .model .entry .BibEntry ;
24- import org .jabref .model .entry .BibEntryTypesManager ;
2519import org .jabref .model .metadata .SaveOrder ;
2620import org .jabref .model .metadata .SelfContainedSaveOrder ;
27- import org .jabref .model .search .SearchDisplayMode ;
28- import org .jabref .model .search .SearchFlags ;
2921import org .jabref .model .util .DummyFileUpdateMonitor ;
3022import org .jabref .support .BibEntryAssert ;
3123
32- import org .junit .jupiter .api .BeforeEach ;
3324import org .junit .jupiter .api .Test ;
3425import org .junit .jupiter .api .io .TempDir ;
35- import org .mockito .Answers ;
36- import picocli .CommandLine ;
3726
3827import static org .junit .jupiter .api .Assertions .assertEquals ;
3928import static org .junit .jupiter .api .Assertions .assertTrue ;
40- import static org .mockito .Mockito .mock ;
4129import static org .mockito .Mockito .when ;
4230
43- class ArgumentProcessorTest {
44-
45- private final CliPreferences preferences = mock (CliPreferences .class , Answers .RETURNS_DEEP_STUBS );
46- private final BibEntryTypesManager entryTypesManager = mock (BibEntryTypesManager .class );
47- private final ImporterPreferences importerPreferences = mock (ImporterPreferences .class , Answers .RETURNS_DEEP_STUBS );
48- private final ExportPreferences exportPreferences = mock (ExportPreferences .class , Answers .RETURNS_DEEP_STUBS );
49- private final ImportFormatPreferences importFormatPreferences = mock (ImportFormatPreferences .class , Answers .RETURNS_DEEP_STUBS );
50-
51- private CommandLine commandLine ;
52-
53- @ BeforeEach ()
54- void setup () {
55- when (importerPreferences .getCustomImporters ()).thenReturn (FXCollections .emptyObservableSet ());
56- when (exportPreferences .getCustomExporters ()).thenReturn (FXCollections .emptyObservableList ());
57-
58- when (preferences .getExportPreferences ()).thenReturn (exportPreferences );
59- when (preferences .getImporterPreferences ()).thenReturn (importerPreferences );
60- when (preferences .getImportFormatPreferences ()).thenReturn (importFormatPreferences );
61- when (preferences .getSearchPreferences ()).thenReturn (new SearchPreferences (
62- SearchDisplayMode .FILTER ,
63- EnumSet .noneOf (SearchFlags .class ),
64- false ,
65- false ,
66- 0 ,
67- 0 ,
68- 0 ));
69-
70- ArgumentProcessor argumentProcessor = new ArgumentProcessor (preferences , entryTypesManager );
71- commandLine = new CommandLine (argumentProcessor );
72- }
31+ class ArgumentProcessorTest extends AbstractJabKitTest {
7332
7433 @ Test
7534 void auxImport (@ TempDir Path tempDir ) throws URISyntaxException {
76- String fullBib = Path . of ( ArgumentProcessorTest . class . getResource ( "origin.bib" ). toURI ()). toAbsolutePath (). toString ( );
77- String auxFile = Path . of ( ArgumentProcessorTest . class . getResource ( "paper.aux" ). toURI ()). toAbsolutePath (). toString ( );
35+ String fullBib = getClassResourceAsFullyQualifiedString ( "origin.bib" );
36+ String auxFile = getClassResourceAsFullyQualifiedString ( "paper.aux" );
7837
7938 Path outputBib = tempDir .resolve ("output.bib" ).toAbsolutePath ();
8039
@@ -87,7 +46,7 @@ void auxImport(@TempDir Path tempDir) throws URISyntaxException {
8746
8847 @ Test
8948 void search (@ TempDir Path tempDir ) throws URISyntaxException , IOException {
90- Path originBib = Path . of ( Objects . requireNonNull ( ArgumentProcessorTest . class . getResource ( "origin.bib" )). toURI () );
49+ Path originBib = getClassResourceAsPath ( "origin.bib" );
9150 String originBibFile = originBib .toAbsolutePath ().toString ();
9251
9352 Path expectedBib = Path .of (
@@ -110,7 +69,7 @@ void search(@TempDir Path tempDir) throws URISyntaxException, IOException {
11069
11170 @ Test
11271 void convertBibtexToTableRefsAsBib (@ TempDir Path tempDir ) throws URISyntaxException {
113- Path originBib = Path . of ( Objects . requireNonNull ( ArgumentProcessorTest . class . getResource ( "origin.bib" )). toURI () );
72+ Path originBib = getClassResourceAsPath ( "origin.bib" );
11473 String originBibFile = originBib .toAbsolutePath ().toString ();
11574
11675 Path outputHtml = tempDir .resolve ("output.html" ).toAbsolutePath ();
@@ -134,8 +93,8 @@ void convertBibtexToTableRefsAsBib(@TempDir Path tempDir) throws URISyntaxExcept
13493 }
13594
13695 @ Test
137- void checkConsistency () throws URISyntaxException {
138- Path testBib = Path . of ( Objects . requireNonNull ( ArgumentProcessorTest . class . getResource ( "origin.bib" )). toURI () );
96+ void checkConsistency () {
97+ Path testBib = getClassResourceAsPath ( "origin.bib" );
13998 String testBibFile = testBib .toAbsolutePath ().toString ();
14099
141100 List <String > args = List .of ("check-consistency" , "--input" , testBibFile , "--output-format" , "txt" );
@@ -154,8 +113,8 @@ void checkConsistency() throws URISyntaxException {
154113 }
155114
156115 @ Test
157- void checkConsistencyPorcelain () throws URISyntaxException {
158- Path testBib = Path . of ( Objects . requireNonNull ( ArgumentProcessorTest . class . getResource ( "origin.bib" )). toURI () );
116+ void checkConsistencyPorcelain () {
117+ Path testBib = getClassResourceAsPath ( "origin.bib" );
159118 String testBibFile = testBib .toAbsolutePath ().toString ();
160119
161120 // "txt" is the default output format; thus not provided here
0 commit comments