11package org .jabref .logic .quality .consistency ;
22
33import java .nio .file .Path ;
4- import java .util .HashSet ;
54import java .util .List ;
65import java .util .Map ;
76import java .util .Set ;
@@ -32,10 +31,7 @@ void checkSimpleLibrary(@TempDir Path tempDir) {
3231 BibEntry second = new BibEntry (StandardEntryType .Article , "second" )
3332 .withField (StandardField .AUTHOR , "Author One" )
3433 .withField (StandardField .PUBLISHER , "publisher" );
35- BibDatabase database = new BibDatabase ();
36- database .insertEntry (first );
37- database .insertEntry (second );
38-
34+ BibDatabase database = new BibDatabase (List .of (first , second ));
3935 BibDatabaseContext bibContext = new BibDatabaseContext (database );
4036 bibContext .setMode (BibDatabaseMode .BIBTEX );
4137 BibliographyConsistencyCheck .Result result = new BibliographyConsistencyCheck ().check (bibContext , (count , total ) -> { });
@@ -55,9 +51,7 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) {
5551 .withField (customField , "custom" ); // unknown
5652 BibEntry second = new BibEntry (StandardEntryType .Article , "second" )
5753 .withField (StandardField .AUTHOR , "Author One" );
58- List <BibEntry > bibEntriesList = List .of (first , second );
59- BibDatabase bibDatabase = new BibDatabase ();
60- bibDatabase .insertEntries (bibEntriesList );
54+ BibDatabase bibDatabase = new BibDatabase (List .of (first , second ));
6155 BibDatabaseContext bibContext = new BibDatabaseContext (bibDatabase );
6256 bibContext .setMode (BibDatabaseMode .BIBTEX );
6357 BibliographyConsistencyCheck .Result result = new BibliographyConsistencyCheck ().check (bibContext , (_ , _ ) -> { });
@@ -89,9 +83,7 @@ void checkComplexLibrary(@TempDir Path tempDir) {
8983 .withField (StandardField .AUTHOR , "Author One" )
9084 .withField (StandardField .YEAR , "2024" );
9185
92- List <BibEntry > bibEntriesList = List .of (first , second , third , fourth , fifth );
93- BibDatabase bibDatabase = new BibDatabase ();
94- bibDatabase .insertEntries (bibEntriesList );
86+ BibDatabase bibDatabase = new BibDatabase (List .of (first , second , third , fourth , fifth ));
9587 BibDatabaseContext bibContext = new BibDatabaseContext (bibDatabase );
9688
9789 BibliographyConsistencyCheck .Result result = new BibliographyConsistencyCheck ().check (bibContext , (_ , _ ) -> { });
@@ -113,10 +105,7 @@ void checkLibraryWithoutIssues(@TempDir Path tempDir) {
113105 BibEntry second = new BibEntry (StandardEntryType .Article , "second" )
114106 .withField (StandardField .AUTHOR , "Author One" )
115107 .withField (StandardField .PAGES , "some pages" );
116- List <BibEntry > bibEntriesList = List .of (first , second );
117- BibDatabase bibDatabase = new BibDatabase ();
118- bibDatabase .insertEntries (bibEntriesList );
119-
108+ BibDatabase bibDatabase = new BibDatabase (List .of (first , second ));
120109 BibDatabaseContext bibContext = new BibDatabaseContext (bibDatabase );
121110
122111 BibliographyConsistencyCheck .Result result = new BibliographyConsistencyCheck ().check (bibContext , (_ , _ ) -> { });
@@ -136,10 +125,7 @@ void filteredFieldsAreIgnored() {
136125 .withField (StandardField .COMMENT , "another note" )
137126 .withField (StandardField .PDF , "other.pdf" );
138127
139- List <BibEntry > bibEntriesList = List .of (a , b );
140- BibDatabase bibDatabase = new BibDatabase ();
141- bibDatabase .insertEntries (bibEntriesList );
142-
128+ BibDatabase bibDatabase = new BibDatabase (List .of (a , b ));
143129 BibDatabaseContext bibContext = new BibDatabaseContext (bibDatabase );
144130
145131 BibliographyConsistencyCheck .Result result = new BibliographyConsistencyCheck ()
@@ -155,9 +141,7 @@ void nonFilteredFieldDifferenceIsReported() {
155141 .withField (StandardField .AUTHOR , "Knuth" );
156142 BibEntry withoutAuthor = new BibEntry (StandardEntryType .Misc , "2" );
157143
158- List <BibEntry > bibEntriesList = List .of (withAuthor , withoutAuthor );
159- BibDatabase bibDatabase = new BibDatabase (bibEntriesList );
160- bibDatabase .insertEntries (bibEntriesList );
144+ BibDatabase bibDatabase = new BibDatabase (List .of (withAuthor , withoutAuthor ));
161145 BibDatabaseContext bibContext = new BibDatabaseContext (bibDatabase );
162146
163147 BibliographyConsistencyCheck .Result result = new BibliographyConsistencyCheck ()
@@ -179,10 +163,7 @@ void unsetRequriedFieldsReported() {
179163 .withCitationKey ("withoutDate" )
180164 .withField (StandardField .URLDATE , "urldate" );
181165
182- List <BibEntry > bibEntriesList = List .of (withDate , withoutDate );
183- BibDatabase bibDatabase = new BibDatabase (bibEntriesList );
184- bibDatabase .insertEntries (bibEntriesList );
185-
166+ BibDatabase bibDatabase = new BibDatabase (List .of (withDate , withoutDate ));
186167 BibDatabaseContext bibContext = new BibDatabaseContext (bibDatabase );
187168 bibContext .setMode (BibDatabaseMode .BIBLATEX );
188169
@@ -197,6 +178,7 @@ void unsetRequriedFieldsReported() {
197178
198179 @ Test
199180 void unsetFieldsReportedInBibtexMode () {
181+ // "Online" is unknown in BibTeX, thus "date" should be reported as inconsistent (set only in one entry)
200182 BibEntry withDate = new BibEntry (StandardEntryType .Online )
201183 .withCitationKey ("withDate" )
202184 .withField (StandardField .DATE , "date" )
@@ -205,28 +187,19 @@ void unsetFieldsReportedInBibtexMode() {
205187 .withCitationKey ("withoutDate" )
206188 .withField (StandardField .URLDATE , "urldate" );
207189
208- List <BibEntry > bibEntriesList = List .of (withDate , withoutDate );
209- BibDatabase bibDatabase = new BibDatabase (bibEntriesList );
210- bibDatabase .insertEntries (bibEntriesList );
211-
190+ BibDatabase bibDatabase = new BibDatabase (List .of (withDate , withoutDate ));
212191 BibDatabaseContext bibContext = new BibDatabaseContext (bibDatabase );
213192 bibContext .setMode (BibDatabaseMode .BIBTEX );
214193 BibliographyConsistencyCheck .Result result = new BibliographyConsistencyCheck ()
215194 .check (bibContext , (_ , _ ) -> { });
195+ BibliographyConsistencyCheck .EntryTypeResult typeResult =
196+ result .entryTypeToResultMap ().get (StandardEntryType .Online );
216197
217- assertEquals (Map .of (), result . entryTypeToResultMap ());
198+ assertEquals (List .of (withDate ), typeResult . sortedEntries (). stream (). toList ());
218199 }
219200
220201 @ Test
221202 void checkFieldEntriesWithFieldDifferences () {
222- Set <BibEntry > entries = new HashSet <>();
223- Set <Field > differingFields = Set .of (
224- StandardField .TITLE ,
225- StandardField .PAGES ,
226- new UnknownField ("customField" ),
227- StandardField .PUBLISHER
228- );
229-
230203 BibEntry entry1 = new BibEntry (StandardEntryType .Article , "id1" )
231204 .withField (StandardField .AUTHOR , "Author One" )
232205 .withField (StandardField .TITLE , "Title " )
@@ -247,18 +220,18 @@ void checkFieldEntriesWithFieldDifferences() {
247220 .withField (StandardField .AUTHOR , "Author Five" )
248221 .withField (StandardField .PUBLISHER , "Editor" );
249222
250- entries . add ( entry1 );
251- entries . add ( entry2 );
252- entries . add ( entry3 );
253- entries . add ( entry4 );
254- entries . add ( entry5 );
255-
256- BibliographyConsistencyCheck check = new BibliographyConsistencyCheck ();
257-
258- List < BibEntry > result = check . filterAndSortEntriesWithFieldDifferences ( entries , differingFields , Set . of ( StandardField . AUTHOR , StandardField . TITLE , StandardField . PAGES , StandardField . PDF ));
259- List < BibEntry > expected = List .of (entry1 , entry2 , entry3 , entry4 , entry5 );
223+ Set < Field > differingFields = Set . of (
224+ StandardField . TITLE ,
225+ StandardField . PAGES ,
226+ new UnknownField ( "customField" ),
227+ StandardField . PUBLISHER
228+ );
229+ List < BibEntry > result = new BibliographyConsistencyCheck (). filterAndSortEntriesWithFieldDifferences (
230+ Set . of ( entry1 , entry2 , entry3 , entry4 , entry5 ),
231+ differingFields ,
232+ Set .of (StandardField . AUTHOR , StandardField . TITLE , StandardField . PAGES , StandardField . PDF ) );
260233
261- assertEquals (Set . copyOf ( expected ), Set . copyOf ( result ) );
234+ assertEquals (List . of ( entry1 , entry2 , entry3 , entry4 , entry5 ), result );
262235 }
263236
264237 @ Test
@@ -284,19 +257,17 @@ void checkComplexLibraryWithAdditionalEntry(@TempDir Path tempDir) {
284257 BibEntry sixth = new BibEntry (StandardEntryType .InProceedings , "sixth" )
285258 .withField (StandardField .AUTHOR , "Author One" );
286259
287- List <BibEntry > bibEntriesList = List .of (first , second , third , fourth , fifth , sixth );
288- BibDatabase bibDatabase = new BibDatabase ();
289- bibDatabase .insertEntries (bibEntriesList );
260+ BibDatabase bibDatabase = new BibDatabase (List .of (first , second , third , fourth , fifth , sixth ));
290261 BibDatabaseContext bibContext = new BibDatabaseContext (bibDatabase );
291262
292- BibliographyConsistencyCheck .Result expectedArticle = new BibliographyConsistencyCheck ().check (bibContext , (_ , _ ) -> { });
263+ BibliographyConsistencyCheck .Result actualResult = new BibliographyConsistencyCheck ().check (bibContext , (_ , _ ) -> { });
293264
294265 BibliographyConsistencyCheck .EntryTypeResult articleResult = new BibliographyConsistencyCheck .EntryTypeResult (Set .of (StandardField .PAGES , StandardField .PUBLISHER ), List .of (first , second ));
295266 BibliographyConsistencyCheck .EntryTypeResult expectedInProceedings = new BibliographyConsistencyCheck .EntryTypeResult (Set .of (StandardField .PAGES , StandardField .PUBLISHER , StandardField .LOCATION , StandardField .YEAR ), List .of (fifth , fourth , sixth , third ));
296- BibliographyConsistencyCheck .Result expected = new BibliographyConsistencyCheck .Result (Map .of (
267+ BibliographyConsistencyCheck .Result expectedResult = new BibliographyConsistencyCheck .Result (Map .of (
297268 StandardEntryType .Article , articleResult ,
298269 StandardEntryType .InProceedings , expectedInProceedings
299270 ));
300- assertEquals (expected , expectedArticle );
271+ assertEquals (expectedResult , actualResult );
301272 }
302273}
0 commit comments