diff --git a/jablib/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java b/jablib/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java index 3e1f0e61ba8..dae6375f9be 100644 --- a/jablib/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java +++ b/jablib/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java @@ -45,7 +45,7 @@ * 2017_Kitsune_123 when expanded using the BibTeX entry @Article{ authors = {O. Kitsune}, year = {2017}, * pages={123-6}}. *

- * The embedding in JabRef is explained at Customize the citation key generator. + * The embedding in JabRef is explained at Customize the citation key generator. *

*/ public class BracketedPattern { @@ -807,7 +807,8 @@ private static String firstAuthorVonAndLast(AuthorList authorList) { * @param authorList an {@link AuthorList} * @return the surname of an author/editor */ - private static String lastAuthor(AuthorList authorList) { + @VisibleForTesting + static String lastAuthor(AuthorList authorList) { if (authorList.isEmpty()) { return ""; } @@ -1221,7 +1222,7 @@ protected static List parseFieldAndModifiers(String arg) { /** *

- * An author or editor may be and institution not a person. In that case the key generator builds very long keys, + * An author or editor may be an institution not a person. In that case the key generator builds very long keys, * e.g.: for “The Attributed Graph Grammar System (AGG)” -> “TheAttributedGraphGrammarSystemAGG”. *

* diff --git a/jablib/src/test/java/org/jabref/logic/citationkeypattern/BracketedPatternTest.java b/jablib/src/test/java/org/jabref/logic/citationkeypattern/BracketedPatternTest.java index 85b4e406c73..163037d934b 100644 --- a/jablib/src/test/java/org/jabref/logic/citationkeypattern/BracketedPatternTest.java +++ b/jablib/src/test/java/org/jabref/logic/citationkeypattern/BracketedPatternTest.java @@ -179,8 +179,8 @@ static Stream authShort() { @ParameterizedTest @MethodSource - void authIni1(String expected, AuthorList list) { - assertEquals(expected, BracketedPattern.authIniN(list, 1)); + void authShort(String expected, AuthorList list) { + assertEquals(expected, BracketedPattern.authShort(list)); } static Stream authIni1() { @@ -204,8 +204,8 @@ static Stream authIni1() { @ParameterizedTest @MethodSource - void authIni2(String expected, AuthorList list) { - assertEquals(expected, BracketedPattern.authIniN(list, 2)); + void authIni1(String expected, AuthorList list) { + assertEquals(expected, BracketedPattern.authIniN(list, 1)); } static Stream authIni2() { @@ -230,8 +230,8 @@ static Stream authIni2() { @ParameterizedTest @MethodSource - void authIni3(String expected, AuthorList list) { - assertEquals(expected, BracketedPattern.authIniN(list, 3)); + void authIni2(String expected, AuthorList list) { + assertEquals(expected, BracketedPattern.authIniN(list, 2)); } static Stream authIni3() { @@ -256,8 +256,8 @@ static Stream authIni3() { @ParameterizedTest @MethodSource - void authIni4(String expected, AuthorList list) { - assertEquals(expected, BracketedPattern.authIniN(list, 4)); + void authIni3(String expected, AuthorList list) { + assertEquals(expected, BracketedPattern.authIniN(list, 3)); } static Stream authIni4() { @@ -281,8 +281,8 @@ static Stream authIni4() { @ParameterizedTest @MethodSource - void authEtAlDotDotEal(String expected, AuthorList list) { - assertEquals(expected, BracketedPattern.authEtal(list, ".", ".etal")); + void authIni4(String expected, AuthorList list) { + assertEquals(expected, BracketedPattern.authIniN(list, 4)); } static Stream authEtAlDotDotEal() { @@ -306,8 +306,8 @@ static Stream authEtAlDotDotEal() { @ParameterizedTest @MethodSource - void authAuthEa(String expected, AuthorList list) { - assertEquals(expected, BracketedPattern.authAuthEa(list)); + void authEtAlDotDotEal(String expected, AuthorList list) { + assertEquals(expected, BracketedPattern.authEtal(list, ".", ".etal")); } static Stream authAuthEa() { @@ -331,8 +331,26 @@ static Stream authAuthEa() { @ParameterizedTest @MethodSource - void authShort(String expected, AuthorList list) { - assertEquals(expected, BracketedPattern.authShort(list)); + void authAuthEa(String expected, AuthorList list) { + assertEquals(expected, BracketedPattern.authAuthEa(list)); + } + + @ParameterizedTest + @CsvSource({ + "'Newton', 'Isaac Newton'", + "'Maxwell', 'Isaac Newton and James Maxwell'", + "'Einstein', 'Isaac Newton and James Maxwell and Albert Einstein'", + "'Bohr', 'Isaac Newton and James Maxwell and Albert Einstein and N. Bohr'", + "'Aachen', 'Aachen'", + "'Berlin', 'Aachen and Berlin'", + "'Chemnitz', 'Aachen and Berlin and Chemnitz'", + "'Düsseldorf', 'Aachen and Berlin and Chemnitz and Düsseldorf'", + "'Essen', 'Aachen and Berlin and Chemnitz and Düsseldorf and Essen'", + "'Aalst', 'Wil van der Aalst", + "'Lessen', 'Wil van der Aalst and Tammo van Lessen'" + }) + void authLast(String expected, AuthorList list) { + assertEquals(expected, BracketedPattern.lastAuthor(list)); } @ParameterizedTest