Skip to content

Commit d9ea011

Browse files
authored
Add rendered DOI tests for CSL APA 7th ed. (#13052)
* Add tests Signed-off-by: subhramit <[email protected]> * Add comment Signed-off-by: subhramit <[email protected]> --------- Signed-off-by: subhramit <[email protected]>
1 parent 869e80e commit d9ea011

File tree

1 file changed

+252
-0
lines changed

1 file changed

+252
-0
lines changed

jablib/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java

+252
Original file line numberDiff line numberDiff line change
@@ -649,4 +649,256 @@ void cslMapping(String expected, BibDatabaseMode mode, BibEntry entry, String cs
649649
ENTRY_TYPES_MANAGER).getFirst();
650650
assertEquals(expected, citation);
651651
}
652+
653+
static Stream<Arguments> doiFieldMapping() {
654+
return Stream.of(
655+
656+
// region: output format TEXT
657+
658+
// Test 1: Regular DOI format (no URL)
659+
Arguments.of(
660+
"Corti, R., Flammer, A. J., Hollenberg, N. K., & Lüscher, T. F. (2009). Cocoa and Cardiovascular Health. Circulation, 119(10), 1433–1441. https://doi.org/10.1161/circulationaha.108.827022\n",
661+
BibDatabaseMode.BIBLATEX,
662+
new BibEntry(StandardEntryType.Article)
663+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
664+
.withField(StandardField.DATE, "2009-03")
665+
.withField(StandardField.JOURNALTITLE, "Circulation")
666+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
667+
.withField(StandardField.DOI, "10.1161/circulationaha.108.827022")
668+
.withField(StandardField.ISSN, "1524-4539")
669+
.withField(StandardField.NUMBER, "10")
670+
.withField(StandardField.PAGES, "1433--1441")
671+
.withField(StandardField.VOLUME, "119")
672+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
673+
"apa.csl",
674+
CitationStyleOutputFormat.TEXT
675+
),
676+
677+
// Test 2: DOI with https://doi.org/ prefix (behavior: another https://doi.org/ prefix is added from APA style regardless)
678+
Arguments.of(
679+
"Corti, R., Flammer, A. J., Hollenberg, N. K., & Lüscher, T. F. (2009). Cocoa and Cardiovascular Health. Circulation, 119(10), 1433–1441. https://doi.org/https://doi.org/10.1161/circulationaha.108.827022\n",
680+
BibDatabaseMode.BIBLATEX,
681+
new BibEntry(StandardEntryType.Article)
682+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
683+
.withField(StandardField.DATE, "2009-03")
684+
.withField(StandardField.JOURNALTITLE, "Circulation")
685+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
686+
.withField(StandardField.DOI, "https://doi.org/10.1161/circulationaha.108.827022")
687+
.withField(StandardField.ISSN, "1524-4539")
688+
.withField(StandardField.NUMBER, "10")
689+
.withField(StandardField.PAGES, "1433--1441")
690+
.withField(StandardField.VOLUME, "119")
691+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
692+
"apa.csl",
693+
CitationStyleOutputFormat.TEXT
694+
),
695+
696+
// Test 3: DOI with dx.doi.org prefix
697+
Arguments.of(
698+
"Corti, R., Flammer, A. J., Hollenberg, N. K., & Lüscher, T. F. (2009). Cocoa and Cardiovascular Health. Circulation, 119(10), 1433–1441. https://doi.org/http://dx.doi.org/10.1161/circulationaha.108.827022\n",
699+
BibDatabaseMode.BIBLATEX,
700+
new BibEntry(StandardEntryType.Article)
701+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
702+
.withField(StandardField.DATE, "2009-03")
703+
.withField(StandardField.JOURNALTITLE, "Circulation")
704+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
705+
.withField(StandardField.DOI, "http://dx.doi.org/10.1161/circulationaha.108.827022")
706+
.withField(StandardField.ISSN, "1524-4539")
707+
.withField(StandardField.NUMBER, "10")
708+
.withField(StandardField.PAGES, "1433--1441")
709+
.withField(StandardField.VOLUME, "119")
710+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
711+
"apa.csl",
712+
CitationStyleOutputFormat.TEXT
713+
),
714+
715+
// Test 4: Missing DOI field
716+
Arguments.of(
717+
"Corti, R., Flammer, A. J., Hollenberg, N. K., & Lüscher, T. F. (2009). Cocoa and Cardiovascular Health. Circulation, 119(10), 1433–1441.\n",
718+
BibDatabaseMode.BIBLATEX,
719+
new BibEntry(StandardEntryType.Article)
720+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
721+
.withField(StandardField.DATE, "2009-03")
722+
.withField(StandardField.JOURNALTITLE, "Circulation")
723+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
724+
.withField(StandardField.ISSN, "1524-4539")
725+
.withField(StandardField.NUMBER, "10")
726+
.withField(StandardField.PAGES, "1433--1441")
727+
.withField(StandardField.VOLUME, "119")
728+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
729+
"apa.csl",
730+
CitationStyleOutputFormat.TEXT
731+
),
732+
733+
// Test 5: Empty DOI field
734+
Arguments.of(
735+
"Corti, R., Flammer, A. J., Hollenberg, N. K., & Lüscher, T. F. (2009). Cocoa and Cardiovascular Health. Circulation, 119(10), 1433–1441.\n",
736+
BibDatabaseMode.BIBLATEX,
737+
new BibEntry(StandardEntryType.Article)
738+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
739+
.withField(StandardField.DATE, "2009-03")
740+
.withField(StandardField.JOURNALTITLE, "Circulation")
741+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
742+
.withField(StandardField.DOI, "")
743+
.withField(StandardField.ISSN, "1524-4539")
744+
.withField(StandardField.NUMBER, "10")
745+
.withField(StandardField.PAGES, "1433--1441")
746+
.withField(StandardField.VOLUME, "119")
747+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
748+
"apa.csl",
749+
CitationStyleOutputFormat.TEXT
750+
),
751+
752+
// Test 6: DOI with unusual characters
753+
Arguments.of(
754+
"Corti, R., Flammer, A. J., Hollenberg, N. K., & Lüscher, T. F. (2009). Cocoa and Cardiovascular Health. Circulation, 119(10), 1433–1441. https://doi.org/10.1161/circ.108_827022 special\n",
755+
BibDatabaseMode.BIBLATEX,
756+
new BibEntry(StandardEntryType.Article)
757+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
758+
.withField(StandardField.DATE, "2009-03")
759+
.withField(StandardField.JOURNALTITLE, "Circulation")
760+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
761+
.withField(StandardField.DOI, "10.1161/circ.108_827022~special")
762+
.withField(StandardField.ISSN, "1524-4539")
763+
.withField(StandardField.NUMBER, "10")
764+
.withField(StandardField.PAGES, "1433--1441")
765+
.withField(StandardField.VOLUME, "119")
766+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
767+
"apa.csl",
768+
CitationStyleOutputFormat.TEXT
769+
),
770+
771+
// Test 7: Malformed DOI (invalid syntax)
772+
Arguments.of(
773+
"Corti, R., Flammer, A. J., Hollenberg, N. K., & Lüscher, T. F. (2009). Cocoa and Cardiovascular Health. Circulation, 119(10), 1433–1441. https://doi.org/invalid-doi-format\n",
774+
BibDatabaseMode.BIBLATEX,
775+
new BibEntry(StandardEntryType.Article)
776+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
777+
.withField(StandardField.DATE, "2009-03")
778+
.withField(StandardField.JOURNALTITLE, "Circulation")
779+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
780+
.withField(StandardField.DOI, "invalid-doi-format")
781+
.withField(StandardField.ISSN, "1524-4539")
782+
.withField(StandardField.NUMBER, "10")
783+
.withField(StandardField.PAGES, "1433--1441")
784+
.withField(StandardField.VOLUME, "119")
785+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
786+
"apa.csl",
787+
CitationStyleOutputFormat.TEXT
788+
),
789+
// endregion
790+
791+
// region: output format HTML
792+
793+
// Test 1: Regular DOI format (no URL)
794+
Arguments.of(
795+
" <div class=\"csl-entry\">Corti, R., Flammer, A. J., Hollenberg, N. K., &amp; L&uuml;scher, T. F. (2009). Cocoa and Cardiovascular Health. <span style=\"font-style: italic\">Circulation</span>, <span style=\"font-style: italic\">119</span>(10), 1433&ndash;1441. https://doi.org/10.1161/circulationaha.108.827022</div>\n",
796+
BibDatabaseMode.BIBLATEX,
797+
new BibEntry(StandardEntryType.Article)
798+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
799+
.withField(StandardField.DATE, "2009-03")
800+
.withField(StandardField.JOURNALTITLE, "Circulation")
801+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
802+
.withField(StandardField.DOI, "10.1161/circulationaha.108.827022")
803+
.withField(StandardField.ISSN, "1524-4539")
804+
.withField(StandardField.NUMBER, "10")
805+
.withField(StandardField.PAGES, "1433--1441")
806+
.withField(StandardField.VOLUME, "119")
807+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
808+
"apa.csl",
809+
CitationStyleOutputFormat.HTML
810+
),
811+
812+
// Test 2: DOI with https://doi.org/ prefix
813+
Arguments.of(
814+
" <div class=\"csl-entry\">Corti, R., Flammer, A. J., Hollenberg, N. K., &amp; L&uuml;scher, T. F. (2009). Cocoa and Cardiovascular Health. <span style=\"font-style: italic\">Circulation</span>, <span style=\"font-style: italic\">119</span>(10), 1433&ndash;1441. https://doi.org/https://doi.org/10.1161/circulationaha.108.827022</div>\n",
815+
BibDatabaseMode.BIBLATEX,
816+
new BibEntry(StandardEntryType.Article)
817+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
818+
.withField(StandardField.DATE, "2009-03")
819+
.withField(StandardField.JOURNALTITLE, "Circulation")
820+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
821+
.withField(StandardField.DOI, "https://doi.org/10.1161/circulationaha.108.827022")
822+
.withField(StandardField.ISSN, "1524-4539")
823+
.withField(StandardField.NUMBER, "10")
824+
.withField(StandardField.PAGES, "1433--1441")
825+
.withField(StandardField.VOLUME, "119")
826+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
827+
"apa.csl",
828+
CitationStyleOutputFormat.HTML
829+
),
830+
831+
// Test 3: DOI with dx.doi.org prefix
832+
Arguments.of(
833+
" <div class=\"csl-entry\">Corti, R., Flammer, A. J., Hollenberg, N. K., &amp; L&uuml;scher, T. F. (2009). Cocoa and Cardiovascular Health. <span style=\"font-style: italic\">Circulation</span>, <span style=\"font-style: italic\">119</span>(10), 1433&ndash;1441. https://doi.org/http://dx.doi.org/10.1161/circulationaha.108.827022</div>\n",
834+
BibDatabaseMode.BIBLATEX,
835+
new BibEntry(StandardEntryType.Article)
836+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
837+
.withField(StandardField.DATE, "2009-03")
838+
.withField(StandardField.JOURNALTITLE, "Circulation")
839+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
840+
.withField(StandardField.DOI, "http://dx.doi.org/10.1161/circulationaha.108.827022")
841+
.withField(StandardField.ISSN, "1524-4539")
842+
.withField(StandardField.NUMBER, "10")
843+
.withField(StandardField.PAGES, "1433--1441")
844+
.withField(StandardField.VOLUME, "119")
845+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
846+
"apa.csl",
847+
CitationStyleOutputFormat.HTML
848+
),
849+
850+
// Test 4: Missing DOI field
851+
Arguments.of(
852+
" <div class=\"csl-entry\">Corti, R., Flammer, A. J., Hollenberg, N. K., &amp; L&uuml;scher, T. F. (2009). Cocoa and Cardiovascular Health. <span style=\"font-style: italic\">Circulation</span>, <span style=\"font-style: italic\">119</span>(10), 1433&ndash;1441.</div>\n",
853+
BibDatabaseMode.BIBLATEX,
854+
new BibEntry(StandardEntryType.Article)
855+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
856+
.withField(StandardField.DATE, "2009-03")
857+
.withField(StandardField.JOURNALTITLE, "Circulation")
858+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
859+
.withField(StandardField.ISSN, "1524-4539")
860+
.withField(StandardField.NUMBER, "10")
861+
.withField(StandardField.PAGES, "1433--1441")
862+
.withField(StandardField.VOLUME, "119")
863+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
864+
"apa.csl",
865+
CitationStyleOutputFormat.HTML
866+
),
867+
868+
// Test 5: Empty DOI field
869+
Arguments.of(
870+
" <div class=\"csl-entry\">Corti, R., Flammer, A. J., Hollenberg, N. K., &amp; L&uuml;scher, T. F. (2009). Cocoa and Cardiovascular Health. <span style=\"font-style: italic\">Circulation</span>, <span style=\"font-style: italic\">119</span>(10), 1433&ndash;1441.</div>\n",
871+
BibDatabaseMode.BIBLATEX,
872+
new BibEntry(StandardEntryType.Article)
873+
.withField(StandardField.AUTHOR, "Corti, Roberto and Flammer, Andreas J. and Hollenberg, Norman K. and Lüscher, Thomas F.")
874+
.withField(StandardField.DATE, "2009-03")
875+
.withField(StandardField.JOURNALTITLE, "Circulation")
876+
.withField(StandardField.TITLE, "Cocoa and Cardiovascular Health")
877+
.withField(StandardField.DOI, "")
878+
.withField(StandardField.ISSN, "1524-4539")
879+
.withField(StandardField.NUMBER, "10")
880+
.withField(StandardField.PAGES, "1433--1441")
881+
.withField(StandardField.VOLUME, "119")
882+
.withField(StandardField.PUBLISHER, "Ovid Technologies (Wolters Kluwer Health)"),
883+
"apa.csl",
884+
CitationStyleOutputFormat.HTML
885+
)
886+
// endregion
887+
);
888+
}
889+
890+
@ParameterizedTest
891+
@MethodSource
892+
void doiFieldMapping(String expected, BibDatabaseMode mode, BibEntry entry, String cslFileName, CitationStyleOutputFormat outputFormat) {
893+
BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(List.of(entry)));
894+
context.setMode(mode);
895+
896+
String citation = CitationStyleGenerator.generateBibliography(
897+
List.of(entry),
898+
CSLStyleUtils.createCitationStyleFromFile(cslFileName).orElseThrow().getSource(),
899+
outputFormat,
900+
context,
901+
new BibEntryTypesManager()).getFirst();
902+
assertEquals(expected, citation);
903+
}
652904
}

0 commit comments

Comments
 (0)