11package org .jabref .logic .bst .util ;
22
3+ import java .util .stream .Stream ;
4+
35import org .jabref .model .entry .AuthorList ;
46
57import org .junit .jupiter .api .Test ;
8+ import org .junit .jupiter .params .ParameterizedTest ;
9+ import org .junit .jupiter .params .provider .Arguments ;
10+ import org .junit .jupiter .params .provider .CsvSource ;
11+ import org .junit .jupiter .params .provider .MethodSource ;
612
713import static org .junit .jupiter .api .Assertions .assertEquals ;
814
915class BstNameFormatterTest {
1016
17+ private static final String EDOUARD_MASTERLY = "{\\ '{E}}douard Masterly" ;
18+ private static final String MEYER_AND_DE_LA_VALLEE_POUSSIN = "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\ 'e}e Poussin" ;
19+ private static final String UNDERWOOD_NET_AND_POT = "Ulrich {\\ \" {U}}nderwood and Ned {\\ ~N}et and Paul {\\ ={P}}ot" ;
20+ private static final String VICTOR_AND_CIERVA = "Paul {\\ 'E}mile Victor and and de la Cierva y Codorn{\\ ’\\ i}u, Juan" ;
21+
1122 @ Test
1223 void umlautsFullNames () {
1324 AuthorList list = AuthorList .parse ("Charles Louis Xavier Joseph de la Vall{\\ 'e}e Poussin" );
@@ -35,38 +46,35 @@ void umlautsAbbreviationsWithQuestionMark() {
3546 @ Test
3647 void formatName () {
3748 AuthorList list = AuthorList .parse ("Charles Louis Xavier Joseph de la Vall{\\ 'e}e Poussin" );
38-
3949 assertEquals ("dlVP" , BstNameFormatter .formatName (list .getAuthor (0 ), "{v{}}{l{}}" ));
40-
41- assertNameFormatA ("Meyer, J?" , "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\ 'e}e Poussin" );
42- assertNameFormatB ("J.~Meyer" , "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\ 'e}e Poussin" );
43- assertNameFormatC ("Jonathan Meyer" , "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\ 'e}e Poussin" );
44- assertNameFormatA ("Masterly, {\\ '{E}}?" , "{\\ '{E}}douard Masterly" );
45- assertNameFormatB ("{\\ '{E}}.~Masterly" , "{\\ '{E}}douard Masterly" );
46- assertNameFormatC ("{\\ '{E}}douard Masterly" , "{\\ '{E}}douard Masterly" );
47- assertNameFormatA ("{\\ \" {U}}nderwood, U?" , "Ulrich {\\ \" {U}}nderwood and Ned {\\ ~N}et and Paul {\\ ={P}}ot" );
48- assertNameFormatB ("U.~{\\ \" {U}}nderwood" , "Ulrich {\\ \" {U}}nderwood and Ned {\\ ~N}et and Paul {\\ ={P}}ot" );
49- assertNameFormatC ("Ulrich {\\ \" {U}}nderwood" , "Ulrich {\\ \" {U}}nderwood and Ned {\\ ~N}et and Paul {\\ ={P}}ot" );
50- assertNameFormatA ("Victor, P.~{\\ 'E}?" , "Paul {\\ 'E}mile Victor and and de la Cierva y Codorn{\\ ’\\ i}u, Juan" );
51- assertNameFormatB ("P.~{\\ 'E}. Victor" , "Paul {\\ 'E}mile Victor and and de la Cierva y Codorn{\\ ’\\ i}u, Juan" );
52- assertNameFormatC ("Paul~{\\ 'E}mile Victor" ,
53- "Paul {\\ 'E}mile Victor and and de la Cierva y Codorn{\\ ’\\ i}u, Juan" );
54- }
55-
56- private void assertNameFormat (String string , String string2 , int which , String format ) {
57- assertEquals (string , BstNameFormatter .formatName (string2 , which , format ));
58- }
59-
60- private void assertNameFormatC (String string , String string2 ) {
61- assertNameFormat (string , string2 , 1 , "{ff }{vv }{ll}{ jj}" );
6250 }
6351
64- private void assertNameFormatB (String string , String string2 ) {
65- assertNameFormat (string , string2 , 1 , "{f.~}{vv~}{ll}{, jj}" );
52+ static Stream <Arguments > provideNameFormattingCases () {
53+ return Stream .of (
54+ // Format pattern: "{vv~}{ll}{, jj}{, f}?"
55+ Arguments .of ("Meyer, J?" , MEYER_AND_DE_LA_VALLEE_POUSSIN , "{vv~}{ll}{, jj}{, f}?" ),
56+ Arguments .of ("Masterly, {\\ '{E}}?" , EDOUARD_MASTERLY , "{vv~}{ll}{, jj}{, f}?" ),
57+ Arguments .of ("{\\ \" {U}}nderwood, U?" , UNDERWOOD_NET_AND_POT , "{vv~}{ll}{, jj}{, f}?" ),
58+ Arguments .of ("Victor, P.~{\\ 'E}?" , VICTOR_AND_CIERVA , "{vv~}{ll}{, jj}{, f}?" ),
59+
60+ // Format pattern: "{f.~}{vv~}{ll}{, jj}"
61+ Arguments .of ("J.~Meyer" , MEYER_AND_DE_LA_VALLEE_POUSSIN , "{f.~}{vv~}{ll}{, jj}" ),
62+ Arguments .of ("{\\ '{E}}.~Masterly" , EDOUARD_MASTERLY , "{f.~}{vv~}{ll}{, jj}" ),
63+ Arguments .of ("U.~{\\ \" {U}}nderwood" , UNDERWOOD_NET_AND_POT , "{f.~}{vv~}{ll}{, jj}" ),
64+ Arguments .of ("P.~{\\ 'E}. Victor" , VICTOR_AND_CIERVA , "{f.~}{vv~}{ll}{, jj}" ),
65+
66+ // Format pattern: "{ff }{vv }{ll}{ jj}"
67+ Arguments .of ("Jonathan Meyer" , MEYER_AND_DE_LA_VALLEE_POUSSIN , "{ff }{vv }{ll}{ jj}" ),
68+ Arguments .of (EDOUARD_MASTERLY , EDOUARD_MASTERLY , "{ff }{vv }{ll}{ jj}" ),
69+ Arguments .of ("Ulrich {\\ \" {U}}nderwood" , UNDERWOOD_NET_AND_POT , "{ff }{vv }{ll}{ jj}" ),
70+ Arguments .of ("Paul~{\\ 'E}mile Victor" , VICTOR_AND_CIERVA , "{ff }{vv }{ll}{ jj}" )
71+ );
6672 }
6773
68- private void assertNameFormatA (String string , String string2 ) {
69- assertNameFormat (string , string2 , 1 , "{vv~}{ll}{, jj}{, f}?" );
74+ @ ParameterizedTest
75+ @ MethodSource ("provideNameFormattingCases" )
76+ void formatNameVariations (String expected , String authorList , String formatString ) {
77+ assertEquals (expected , BstNameFormatter .formatName (authorList , 1 , formatString ));
7078 }
7179
7280 @ Test
@@ -90,23 +98,22 @@ void consumeToMatchingBrace() {
9098 assertEquals ("{HE{L{}L}O}" , sb .toString ());
9199 }
92100
93- @ Test
94- void getFirstCharOfString () {
95- assertEquals ("C" , BstNameFormatter .getFirstCharOfString ("Charles" ));
96- assertEquals ("V" , BstNameFormatter .getFirstCharOfString ("Vall{\\ 'e}e" ));
97- assertEquals ("{\\ 'e}" , BstNameFormatter .getFirstCharOfString ("{\\ 'e}" ));
98- assertEquals ("{\\ 'e" , BstNameFormatter .getFirstCharOfString ("{\\ 'e" ));
99- assertEquals ("E" , BstNameFormatter .getFirstCharOfString ("{E" ));
101+ @ ParameterizedTest
102+ @ CsvSource ({"C, Charles" , "V, Vall{\\ 'e}e" , "{\\ 'e}, {\\ 'e}" , "{\\ 'e, {\\ 'e" , "E, {E" })
103+ void getFirstCharOfString (String expected , String s ) {
104+ assertEquals (expected , BstNameFormatter .getFirstCharOfString (s ));
100105 }
101106
102- @ Test
103- void numberOfChars () {
104- assertEquals (6 , BstNameFormatter .numberOfChars ("Vall{\\ 'e}e" , -1 ));
105- assertEquals (2 , BstNameFormatter .numberOfChars ("Vall{\\ 'e}e" , 2 ));
106- assertEquals (1 , BstNameFormatter .numberOfChars ("Vall{\\ 'e}e" , 1 ));
107- assertEquals (6 , BstNameFormatter .numberOfChars ("Vall{\\ 'e}e" , 6 ));
108- assertEquals (6 , BstNameFormatter .numberOfChars ("Vall{\\ 'e}e" , 7 ));
109- assertEquals (8 , BstNameFormatter .numberOfChars ("Vall{e}e" , -1 ));
110- assertEquals (6 , BstNameFormatter .numberOfChars ("Vall{\\ 'e this will be skipped}e" , -1 ));
107+ @ ParameterizedTest
108+ @ CsvSource ({"6, Vall{\\ 'e}e, -1" ,
109+ "2, Vall{\\ 'e}e, 2" ,
110+ "1, Vall{\\ 'e}e, 1" ,
111+ "6, Vall{\\ 'e}e, 6" ,
112+ "6, Vall{\\ 'e}e, 7" ,
113+ "8, Vall{e}e, -1" ,
114+ "6, Vall{\\ 'e this will be skipped}e, -1"
115+ })
116+ void numberOfChars (int expected , String token , int inStop ) {
117+ assertEquals (expected , BstNameFormatter .numberOfChars (token , inStop ));
111118 }
112119}
0 commit comments