Skip to content

Commit 9a9230d

Browse files
committed
Parameterize tests (issue #676)
1 parent c85656a commit 9a9230d

File tree

4 files changed

+200
-170
lines changed

4 files changed

+200
-170
lines changed
Submodule csl-styles updated 37 files

jablib/src/test/java/org/jabref/logic/citationkeypattern/BracketedPatternTest.java

Lines changed: 48 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class BracketedPatternTest {
3939
void setUp() {
4040
bibentry = new BibEntry().withField(StandardField.AUTHOR, "O. Kitsune")
4141
.withField(StandardField.YEAR, "2017")
42-
.withField(StandardField.PAGES, "213--216");
42+
.withField(StandardField.PAGES, "213--216")
43+
.withField(StandardField.TITLE, "Open Source Software And The Private Collective Innovation Model Issues");
4344

4445
dbentry = new BibEntry(StandardEntryType.Article)
4546
.withCitationKey("HipKro03")
@@ -547,28 +548,25 @@ void lowerFormatterWorksOnVonNamePrefixes() {
547548
BracketedPattern.expandBrackets("[author:lower]", ';', dbentry, database));
548549
}
549550

550-
@Test
551-
void resolvedFieldAndFormat() {
551+
static Stream<Arguments> resolvedFieldAndFormat() {
552+
return Stream.of(
553+
Arguments.of("[author]", "Eric von Hippel and Georg von Krogh"),
554+
Arguments.of("[unknownkey]", ""),
555+
Arguments.of("[:]", ""),
556+
Arguments.of("[:lower]", ""),
557+
Arguments.of("[author:lower]", "eric von hippel and georg von krogh"),
558+
Arguments.of("[citationkey]", ""),
559+
Arguments.of("[citationkey:]", "")
560+
);
561+
}
562+
563+
@ParameterizedTest
564+
@MethodSource
565+
void resolvedFieldAndFormat(String pattern, String expected) {
552566
BibEntry child = new BibEntry().withField(StandardField.CROSSREF, "HipKro03");
553567
database.insertEntry(child);
554-
555568
Character separator = ';';
556-
assertEquals("Eric von Hippel and Georg von Krogh",
557-
BracketedPattern.expandBrackets("[author]", separator, child, database));
558-
559-
assertEquals("", BracketedPattern.expandBrackets("[unknownkey]", separator, child, database));
560-
561-
assertEquals("", BracketedPattern.expandBrackets("[:]", separator, child, database));
562-
563-
assertEquals("", BracketedPattern.expandBrackets("[:lower]", separator, child, database));
564-
565-
assertEquals("eric von hippel and georg von krogh",
566-
BracketedPattern.expandBrackets("[author:lower]", separator, child, database));
567-
568-
// the citation key is not inherited
569-
assertEquals("", BracketedPattern.expandBrackets("[citationkey]", separator, child, database));
570-
571-
assertEquals("", BracketedPattern.expandBrackets("[citationkey:]", separator, child, database));
569+
assertEquals(expected, BracketedPattern.expandBrackets(pattern, separator, child, database));
572570
}
573571

574572
@Test
@@ -665,32 +663,29 @@ void expandBracketsShortTitleModifier(String expectedCitationKey, String title)
665663
BracketedPattern.expandBrackets("[title:shorttitle]", ';', bibEntry, null));
666664
}
667665

668-
/**
669-
* Test the [:camelN] modifier
670-
*/
671-
@Test
672-
void expandBracketsCamelNModifier() {
673-
BibEntry bibEntry = new BibEntry()
674-
.withField(StandardField.TITLE, "Open Source Software And The Private Collective Innovation Model Issues");
675-
assertEquals("Open",
676-
BracketedPattern.expandBrackets("[title:camel1]", ';', bibEntry, null));
677-
assertEquals("OpenSourceSoftwareAnd",
678-
BracketedPattern.expandBrackets("[title:camel4]", ';', bibEntry, null));
679-
assertEquals("OpenSourceSoftwareAndThePrivateCollectiveInnovationModelIssues",
680-
BracketedPattern.expandBrackets("[title:camel10]", ';', bibEntry, null));
666+
@ParameterizedTest
667+
@CsvSource({
668+
"'[title:camel1]', 'Open'",
669+
"'[title:camel4]', 'OpenSourceSoftwareAnd'",
670+
"'[title:camel10]', 'OpenSourceSoftwareAndThePrivateCollectiveInnovationModelIssues'"
671+
})
672+
void expandBracketsCamelNModifier(String pattern, String expected) {
673+
assertEquals(expected,
674+
BracketedPattern.expandBrackets(pattern, ';', bibentry, null));
681675
}
682676

683677
/**
684678
* Test the [camelN] title marker.
685679
*/
686-
@Test
687-
void expandBracketsCamelNTitle() {
688-
assertEquals("Open",
689-
BracketedPattern.expandBrackets("[camel1]", ';', dbentry, database));
690-
assertEquals("OpenSourceSoftwareAnd",
691-
BracketedPattern.expandBrackets("[camel4]", ';', dbentry, database));
692-
assertEquals("OpenSourceSoftwareAndThePrivateCollectiveInnovationModelIssues",
693-
BracketedPattern.expandBrackets("[camel10]", ';', dbentry, database));
680+
@ParameterizedTest
681+
@CsvSource({
682+
"[camel1], Open",
683+
"[camel4], OpenSourceSoftwareAnd",
684+
"[camel10], OpenSourceSoftwareAndThePrivateCollectiveInnovationModelIssues"
685+
})
686+
void expandBracketsCamelNTitle(String pattern, String expected) {
687+
assertEquals(expected,
688+
BracketedPattern.expandBrackets(pattern, ';', dbentry, database));
694689
}
695690

696691
@Test
@@ -787,45 +782,18 @@ void expandBracketsUnmodifiedStringFromLongLastPageNumber() {
787782
assertEquals("2325967120921344", BracketedPattern.expandBrackets("[lastpage]", null, bibEntry, null));
788783
}
789784

790-
@Test
791-
void expandBracketsWithTestCasesFromRegExpBasedFileFinder() {
792-
BibEntry entry = new BibEntry(StandardEntryType.Article)
793-
.withCitationKey("HipKro03")
794-
.withField(StandardField.AUTHOR, "Eric von Hippel and Georg von Krogh")
795-
.withField(StandardField.TITLE, "Open Source Software and the \"Private-Collective\" Innovation Model: Issues for Organization Science")
796-
.withField(StandardField.JOURNAL, "Organization Science")
797-
.withField(StandardField.YEAR, "2003")
798-
.withField(StandardField.VOLUME, "14")
799-
.withField(StandardField.PAGES, "209--223")
800-
.withField(StandardField.NUMBER, "2")
801-
.withField(StandardField.ADDRESS, "Institute for Operations Research and the Management Sciences (INFORMS), Linthicum, Maryland, USA")
802-
.withField(StandardField.DOI, "http://dx.doi.org/10.1287/orsc.14.2.209.14992")
803-
.withField(StandardField.ISSN, "1526-5455")
804-
.withField(StandardField.PUBLISHER, "INFORMS");
805-
806-
BibDatabase database = new BibDatabase();
807-
database.insertEntry(entry);
808-
809-
assertEquals("", BracketedPattern.expandBrackets("", ',', entry, database));
810-
811-
assertEquals("dropped", BracketedPattern.expandBrackets("drop[unknownkey]ped", ',', entry, database));
812-
813-
assertEquals("Eric von Hippel and Georg von Krogh",
814-
BracketedPattern.expandBrackets("[author]", ',', entry, database));
815-
816-
assertEquals("Eric von Hippel and Georg von Krogh are two famous authors.",
817-
BracketedPattern.expandBrackets("[author] are two famous authors.", ',', entry, database));
818-
819-
assertEquals("Eric von Hippel and Georg von Krogh are two famous authors.",
820-
BracketedPattern.expandBrackets("[author] are two famous authors.", ',', entry, database));
821-
822-
assertEquals(
823-
"Eric von Hippel and Georg von Krogh have published Open Source Software and the \"Private-Collective\" Innovation Model: Issues for Organization Science in Organization Science.",
824-
BracketedPattern.expandBrackets("[author] have published [fulltitle] in [journal].", ',', entry, database));
825-
826-
assertEquals(
827-
"Eric von Hippel and Georg von Krogh have published Open Source Software and the \"Private Collective\" Innovation Model: Issues for Organization Science in Organization Science.",
828-
BracketedPattern.expandBrackets("[author] have published [title] in [journal].", ',', entry, database));
785+
@ParameterizedTest
786+
@CsvSource({
787+
"'', ''",
788+
"'drop[unknownkey]ped', 'dropped'",
789+
"'[author]', 'Eric von Hippel and Georg von Krogh'",
790+
"'[author] are two famous authors.', 'Eric von Hippel and Georg von Krogh are two famous authors.'",
791+
"'[author] have published [fulltitle] in [journal].', 'Eric von Hippel and Georg von Krogh have published Open Source Software and the \"Private-Collective\" Innovation Model: Issues for Organization Science in Organization Science.'",
792+
"'[author] have published [title] in [journal].', 'Eric von Hippel and Georg von Krogh have published Open Source Software and the \"Private Collective\" Innovation Model: Issues for Organization Science in Organization Science.'"
793+
})
794+
void expandBracketsWithTestCasesFromRegExpBasedFileFinder(String pattern, String expected) {
795+
assertEquals(expected,
796+
BracketedPattern.expandBrackets(pattern, ';', dbentry, database));
829797
}
830798

831799
@Test
@@ -848,7 +816,6 @@ void expandBracketsWithoutProtectiveBracesUsingUnprotectTermsModifier() {
848816
"'Newton', '[edtrshort]', 'Isaac Newton'",
849817
"'Newton', '[editorLast]', 'Isaac Newton'",
850818
"'I', '[editorLastForeIni]', 'Isaac Newton'",
851-
852819
"'EUASA', '[editors]', '{European Union Aviation Safety Agency}'"
853820
})
854821
void editorFieldMarkers(String expectedCitationKey, String pattern, String editor) {

0 commit comments

Comments
 (0)