|
9 | 9 | import org.jabref.model.database.BibDatabaseContext; |
10 | 10 | import org.jabref.model.database.BibDatabaseMode; |
11 | 11 | import org.jabref.model.entry.BibEntry; |
| 12 | +import org.jabref.model.entry.BibEntryType; |
| 13 | +import org.jabref.model.entry.BibEntryTypeBuilder; |
| 14 | +import org.jabref.model.entry.BibEntryTypesManager; |
| 15 | +import org.jabref.model.entry.field.BibField; |
12 | 16 | import org.jabref.model.entry.field.Field; |
| 17 | +import org.jabref.model.entry.field.FieldPriority; |
13 | 18 | import org.jabref.model.entry.field.SpecialField; |
14 | 19 | import org.jabref.model.entry.field.StandardField; |
15 | 20 | import org.jabref.model.entry.field.UnknownField; |
16 | 21 | import org.jabref.model.entry.field.UserSpecificCommentField; |
| 22 | +import org.jabref.model.entry.types.EntryType; |
17 | 23 | import org.jabref.model.entry.types.StandardEntryType; |
| 24 | +import org.jabref.model.entry.types.UnknownEntryType; |
18 | 25 |
|
19 | 26 | import org.junit.jupiter.api.Test; |
20 | 27 | import org.junit.jupiter.api.io.TempDir; |
|
23 | 30 |
|
24 | 31 | class BibliographyConsistencyCheckTest { |
25 | 32 |
|
| 33 | + private static final EntryType CUSTOM_TYPE = new UnknownEntryType("customType"); |
| 34 | + |
26 | 35 | @Test |
27 | 36 | void checkSimpleLibrary(@TempDir Path tempDir) { |
28 | 37 | BibEntry first = new BibEntry(StandardEntryType.Article, "first") |
@@ -232,14 +241,14 @@ void checkFieldEntriesWithFieldDifferences() { |
232 | 241 | StandardField.TITLE, |
233 | 242 | StandardField.PAGES, |
234 | 243 | new UnknownField("customField"), |
235 | | - StandardField.PUBLISHER |
| 244 | + StandardField.PUBLISHER, |
| 245 | + StandardField.PDF |
236 | 246 | ); |
237 | 247 | List<BibEntry> result = new BibliographyConsistencyCheck().filterAndSortEntriesWithFieldDifferences( |
238 | 248 | Set.of(entry1, entry2, entry3, entry4, entry5), |
239 | | - differingFields, |
240 | | - Set.of(StandardField.AUTHOR, StandardField.TITLE, StandardField.PAGES, StandardField.PDF)); |
| 249 | + differingFields); |
241 | 250 |
|
242 | | - assertEquals(List.of(entry1, entry2, entry3, entry4, entry5), result); |
| 251 | + assertEquals(List.of(entry1, entry3, entry4, entry5), result); |
243 | 252 | } |
244 | 253 |
|
245 | 254 | @Test |
@@ -279,4 +288,31 @@ void checkComplexLibraryWithAdditionalEntry(@TempDir Path tempDir) { |
279 | 288 | )); |
280 | 289 | assertEquals(expectedResult, actualResult); |
281 | 290 | } |
| 291 | + |
| 292 | + @Test |
| 293 | + void checkCustomEntryTypes() { |
| 294 | + |
| 295 | + BibEntry first = new BibEntry(StandardEntryType.Article, "first") |
| 296 | + .withField(StandardField.AUTHOR, "Author One") |
| 297 | + .withField(StandardField.PAGES, "some pages"); |
| 298 | + BibEntry second = new BibEntry(StandardEntryType.Article, "second") |
| 299 | + .withField(StandardField.AUTHOR, "Author One") |
| 300 | + .withField(StandardField.PUBLISHER, "publisher"); |
| 301 | + BibDatabase database = new BibDatabase(List.of(first, second)); |
| 302 | + BibDatabaseContext bibContext = new BibDatabaseContext(database); |
| 303 | + bibContext.setMode(BibDatabaseMode.BIBTEX); |
| 304 | + |
| 305 | + BibEntryTypesManager entryTypesManager = new BibEntryTypesManager(); |
| 306 | + BibEntryType customEntryType = new BibEntryType(CUSTOM_TYPE, |
| 307 | + List.of(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT), new BibField(StandardField.ABSTRACT, FieldPriority.IMPORTANT)), |
| 308 | + Set.of()); |
| 309 | + entryTypesManager.addCustomOrModifiedType(customEntryType, bibContext.getMode()); |
| 310 | + |
| 311 | + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { |
| 312 | + }); |
| 313 | + |
| 314 | + BibliographyConsistencyCheck.EntryTypeResult entryTypeResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER), List.of(first, second)); |
| 315 | + BibliographyConsistencyCheck.Result expected = new BibliographyConsistencyCheck.Result(Map.of(StandardEntryType.Article, entryTypeResult)); |
| 316 | + assertEquals(expected, result); |
| 317 | + } |
282 | 318 | } |
0 commit comments