1
|
/**
|
2
|
* Copyright (C) 2021 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.format.reference;
|
10
|
|
11
|
import org.junit.Assert;
|
12
|
import org.junit.Before;
|
13
|
import org.junit.Test;
|
14
|
|
15
|
import eu.etaxonomy.cdm.common.DOI;
|
16
|
import eu.etaxonomy.cdm.common.URI;
|
17
|
import eu.etaxonomy.cdm.model.agent.Person;
|
18
|
import eu.etaxonomy.cdm.model.agent.Team;
|
19
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
20
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
21
|
import eu.etaxonomy.cdm.model.reference.IArticle;
|
22
|
import eu.etaxonomy.cdm.model.reference.IBook;
|
23
|
import eu.etaxonomy.cdm.model.reference.IBookSection;
|
24
|
import eu.etaxonomy.cdm.model.reference.ICdDvd;
|
25
|
import eu.etaxonomy.cdm.model.reference.IDatabase;
|
26
|
import eu.etaxonomy.cdm.model.reference.IJournal;
|
27
|
import eu.etaxonomy.cdm.model.reference.IWebPage;
|
28
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
29
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
30
|
import eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy;
|
31
|
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
32
|
|
33
|
/**
|
34
|
* @author a.mueller
|
35
|
* @since 03.05.2021
|
36
|
*/
|
37
|
public class NomenclaturalSourceFormatterTest {
|
38
|
|
39
|
private static final String SEP = TimePeriod.SEP;
|
40
|
|
41
|
//article
|
42
|
private static IArticle article1;
|
43
|
private static IJournal journal1;
|
44
|
private static Team articleTeam1;
|
45
|
private static Team articleTeam2;
|
46
|
|
47
|
//book // book section
|
48
|
private static IBook book1;
|
49
|
private static Team bookTeam1;
|
50
|
|
51
|
//book section
|
52
|
private static IBookSection bookSection1;
|
53
|
private static Team sectionTeam1;
|
54
|
|
55
|
//Generic
|
56
|
private static Reference generic1;
|
57
|
private static Team genericTeam1;
|
58
|
|
59
|
//common
|
60
|
private static NomenclaturalSourceFormatter formatter = NomenclaturalSourceFormatter.INSTANCE();
|
61
|
private static final String detail1 = "55";
|
62
|
|
63
|
@Before
|
64
|
public void setUp() throws Exception {
|
65
|
//article
|
66
|
article1 = ReferenceFactory.newArticle();
|
67
|
journal1 = ReferenceFactory.newJournal();
|
68
|
articleTeam1 = Team.NewInstance();
|
69
|
articleTeam2 = Team.NewInstance();
|
70
|
articleTeam1.setTitleCache("Team1", true);
|
71
|
articleTeam1.setNomenclaturalTitleCache("T.", true);
|
72
|
articleTeam2.setTitleCache("Team2", true);
|
73
|
articleTeam2.setNomenclaturalTitleCache("TT.", true);
|
74
|
|
75
|
//book / section
|
76
|
book1 = ReferenceFactory.newBook();
|
77
|
bookTeam1 = Team.NewTitledInstance("Book Author", "TT.");
|
78
|
bookSection1 = ReferenceFactory.newBookSection();
|
79
|
sectionTeam1 = Team.NewTitledInstance("Section Author", "T.");
|
80
|
|
81
|
//Generic
|
82
|
generic1 = ReferenceFactory.newGeneric();
|
83
|
genericTeam1 = Team.NewTitledInstance("Authorteam", "AT.");
|
84
|
}
|
85
|
|
86
|
|
87
|
@Test
|
88
|
public void testArticleGetNomenclaturalCitation(){
|
89
|
journal1.setTitle("My journal");
|
90
|
journal1.setTitle("M. J.");
|
91
|
((Reference)journal1).setAuthorship(articleTeam2);
|
92
|
article1.setTitle("My article");
|
93
|
article1.setInJournal(journal1);
|
94
|
article1.setAuthorship(articleTeam1);
|
95
|
article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
|
96
|
Assert.assertEquals("in M. J.: 55. 1975", formatter.format((Reference)article1, detail1));
|
97
|
|
98
|
article1.setVolume("22");
|
99
|
Assert.assertEquals("in M. J. 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
100
|
article1.setSeriesPart("ser. 11");
|
101
|
Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
102
|
|
103
|
article1.setPages("33"); //#6496 don't show pages in nomencl. citation
|
104
|
Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* After ser. , sect. , abt. we want to have a comma, if there is not yet one following anyway
|
109
|
*/
|
110
|
@Test
|
111
|
public void testArticleGetNomenclaturalCitationSerSectAbt(){
|
112
|
article1.setInJournal(journal1);
|
113
|
article1.setVolume("22");
|
114
|
journal1.setAbbrevTitle("J. Pl. Eur.");
|
115
|
((Reference)journal1).setAuthorship(articleTeam2);
|
116
|
article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
|
117
|
//no ser, sect, abt
|
118
|
Assert.assertEquals("in J. Pl. Eur. 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
119
|
//ser
|
120
|
journal1.setAbbrevTitle("J. Pl. Eur., ser. 3");
|
121
|
Assert.assertEquals("in J. Pl. Eur., ser. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
122
|
journal1.setAbbrevTitle("J. Pl. Eur., Ser. 3");
|
123
|
Assert.assertEquals("in J. Pl. Eur., Ser. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
124
|
journal1.setAbbrevTitle("J. Pl. Eur., ser. 3, s.n.");
|
125
|
Assert.assertEquals("in J. Pl. Eur., ser. 3, s.n. 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
126
|
//sect
|
127
|
journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
|
128
|
Assert.assertEquals("in J. Pl. Eur., sect. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
129
|
journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3");
|
130
|
Assert.assertEquals("in J. Pl. Eur., Sect. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
131
|
journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3, something");
|
132
|
Assert.assertEquals("in J. Pl. Eur., Sect. 3, something 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
133
|
//abt
|
134
|
journal1.setAbbrevTitle("J. Pl. Eur., abt. 3");
|
135
|
Assert.assertEquals("in J. Pl. Eur., abt. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
136
|
journal1.setAbbrevTitle("J. Pl. Eur., Abt. 3");
|
137
|
Assert.assertEquals("in J. Pl. Eur., Abt. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
138
|
journal1.setAbbrevTitle("J. Pl. Eur., abt. 3, no comma");
|
139
|
Assert.assertEquals("in J. Pl. Eur., abt. 3, no comma 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
140
|
|
141
|
journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
|
142
|
article1.setSeriesPart("1");
|
143
|
Assert.assertEquals("in J. Pl. Eur., sect. 3, ser. 1, 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
144
|
article1.setSeriesPart("Series 2");
|
145
|
Assert.assertEquals("in J. Pl. Eur., sect. 3, Series 2, 22: 55. 1975", formatter.format((Reference)article1, detail1));
|
146
|
}
|
147
|
|
148
|
@Test
|
149
|
public void testBookGetNomenclaturalCitation(){
|
150
|
book1.setTitle("My book");
|
151
|
book1.setAuthorship(bookTeam1);
|
152
|
book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
|
153
|
Assert.assertEquals("My book: 55. 1975", formatter.format((Reference)book1, detail1));
|
154
|
book1.setAbbrevTitle("Analect. Bot.");
|
155
|
Assert.assertEquals("Analect. Bot. 1975", formatter.format((Reference)book1, null));
|
156
|
}
|
157
|
|
158
|
|
159
|
//https://dev.e-taxonomy.eu/redmine/issues/8881
|
160
|
@Test
|
161
|
public void testInRefAuthor(){
|
162
|
Person person1 = Person.NewInstance("Inauth.", "Inauthor", "A.B.", "Ala Bala");
|
163
|
Person person2 = Person.NewInstance("Twoauth.", "Twoauthor", "C.", "Cla");
|
164
|
Person person3 = Person.NewTitledInstance("Threeauth.");
|
165
|
Team team = Team.NewInstance(person1, person2, person3);
|
166
|
IBook book1 = ReferenceFactory.newBook();
|
167
|
book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
|
168
|
book1.setVolume("Fasc. 11");
|
169
|
book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
|
170
|
bookSection1.setTitle("My chapter");
|
171
|
bookSection1.setInBook(book1);
|
172
|
book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1956));
|
173
|
|
174
|
book1.setAuthorship(person1);
|
175
|
Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
|
176
|
book1.setAuthorship(team);
|
177
|
Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Twoauthor & Threeauth., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
|
178
|
team.setHasMoreMembers(true);
|
179
|
Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Twoauthor & al., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
|
180
|
book1.setAuthorship(Team.NewInstance(person1));
|
181
|
Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
|
182
|
|
183
|
//for the following the behavior is not yet finally discussed, may change in future
|
184
|
book1.setAuthorship(team);
|
185
|
team.setTitleCache("Teamcache", true);
|
186
|
Assert.assertEquals("Unexpected nomencl. reference", "in Teamcache, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
|
187
|
team.setTitleCache("Teamc.", true);
|
188
|
Assert.assertEquals("Unexpected nomencl. reference", "in Teamc., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
|
189
|
book1.setAuthorship(Team.NewInstance());
|
190
|
Assert.assertEquals("Unexpected nomencl. reference", "in "+TeamDefaultCacheStrategy.EMPTY_TEAM+", Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
|
191
|
}
|
192
|
|
193
|
//#3532
|
194
|
@Test
|
195
|
public void testUnexpectedNomenclaturalReferences(){
|
196
|
Reference reference;
|
197
|
|
198
|
//database
|
199
|
IDatabase database1 = ReferenceFactory.newDatabase();
|
200
|
reference = (Reference)database1;
|
201
|
|
202
|
database1.setTitle("My database");
|
203
|
//maybe we should have a trailing dot here
|
204
|
Assert.assertEquals("My database: 55", formatter.format(reference, detail1));
|
205
|
database1.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
|
206
|
Assert.assertEquals("My database: 55. 1998", formatter.format(reference, detail1));
|
207
|
|
208
|
database1.setTitleCache("Your database", true);
|
209
|
Assert.assertEquals("My database: 55. 1998", formatter.format(reference, detail1));
|
210
|
|
211
|
//unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
|
212
|
reference.setAbbrevTitleCache("You. Db.", true);
|
213
|
Assert.assertEquals("You. Db.: 55. 1998", formatter.format(reference, detail1));
|
214
|
|
215
|
|
216
|
//CD/DVD
|
217
|
ICdDvd cdDvd = ReferenceFactory.newCdDvd();
|
218
|
reference= (Reference)cdDvd;
|
219
|
cdDvd.setTitle("My Cd/Dvd");
|
220
|
//maybe we should have a trailing dot here
|
221
|
Assert.assertEquals("My Cd/Dvd: 55", formatter.format(reference, detail1));
|
222
|
cdDvd.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
|
223
|
Assert.assertEquals("My Cd/Dvd: 55. 1998", formatter.format(reference, detail1));
|
224
|
|
225
|
cdDvd.setTitleCache("Your Cd/Dvd", true);
|
226
|
Assert.assertEquals("My Cd/Dvd: 55. 1998", formatter.format(reference, detail1));
|
227
|
|
228
|
//unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
|
229
|
reference.setAbbrevTitleCache("You. Cd.", true);
|
230
|
Assert.assertEquals("You. Cd.: 55. 1998", formatter.format(reference, detail1));
|
231
|
|
232
|
|
233
|
//WebSite
|
234
|
IWebPage webPage = ReferenceFactory.newWebPage();
|
235
|
reference= (Reference)webPage;
|
236
|
webPage.setTitle("My WebPage");
|
237
|
//maybe we should have a trailing dot here
|
238
|
Assert.assertEquals("My WebPage: 55", formatter.format(reference, detail1));
|
239
|
webPage.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
|
240
|
Assert.assertEquals("My WebPage: 55. 1998", formatter.format(reference, detail1));
|
241
|
|
242
|
webPage.setTitleCache("Your WebPage", true);
|
243
|
Assert.assertEquals("My WebPage: 55. 1998", formatter.format(reference, detail1));
|
244
|
|
245
|
//unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
|
246
|
reference.setAbbrevTitleCache("You. WP.", true);
|
247
|
Assert.assertEquals("You. WP.: 55. 1998", formatter.format(reference, detail1));
|
248
|
|
249
|
//uri
|
250
|
webPage = ReferenceFactory.newWebPage();
|
251
|
reference= (Reference)webPage;
|
252
|
webPage.setUri(URI.create("http://www.abc.de"));
|
253
|
Assert.assertEquals("http://www.abc.de: 55", formatter.format(reference, detail1));
|
254
|
|
255
|
//TBC
|
256
|
}
|
257
|
|
258
|
@Test
|
259
|
public void testBookSectionGetNomenclaturalCitation(){
|
260
|
book1.setAuthorship(bookTeam1);
|
261
|
bookSection1.setInBook(book1);
|
262
|
bookSection1.setAuthorship(sectionTeam1);
|
263
|
book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
|
264
|
//#9705
|
265
|
Assert.assertEquals("in TT., 1975", formatter.format((Reference)bookSection1, null));
|
266
|
Assert.assertEquals("in TT., -: 55. 1975", formatter.format((Reference)bookSection1, detail1));
|
267
|
|
268
|
book1.setTitle("My book");
|
269
|
bookSection1.setTitle("My chapter");
|
270
|
//TODO still unclear which is correct
|
271
|
// Assert.assertEquals("in Book Author, My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
|
272
|
Assert.assertEquals("in TT., My book: 55. 1975", formatter.format((Reference)bookSection1, detail1));
|
273
|
|
274
|
book1.setSeriesPart("2");
|
275
|
Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", formatter.format((Reference)bookSection1, detail1));
|
276
|
//#6496 don't show pages in nom.ref. citations
|
277
|
bookSection1.setPages("35-39");
|
278
|
Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", formatter.format((Reference)bookSection1, detail1));
|
279
|
}
|
280
|
|
281
|
@Test
|
282
|
public void testGenericGetInRef(){
|
283
|
generic1.setTitle("auct.");
|
284
|
IBook book1 = ReferenceFactory.newBook();
|
285
|
book1.setTitle("My book title");
|
286
|
book1.setAuthorship(genericTeam1);
|
287
|
Reference inRef = (Reference)book1;
|
288
|
generic1.setInReference(inRef);
|
289
|
generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
|
290
|
//TODO author still unclear
|
291
|
// Assert.assertEquals("Unexpected title cache.", "in Authorteam, My book title: 2", generic1.getNomenclaturalCitation("2"));
|
292
|
Assert.assertEquals("Unexpected title cache.", "in AT., My book title: 2", formatter.format(generic1, "2"));
|
293
|
}
|
294
|
|
295
|
@Test
|
296
|
public void testGenericDoubleDotBeforeYear(){
|
297
|
generic1.setAuthorship(genericTeam1);
|
298
|
String detail = "sine no.";
|
299
|
generic1.setAbbrevTitle("My title");
|
300
|
generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
|
301
|
generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
|
302
|
Assert.assertEquals("My title: sine no. 1883"+SEP+"1884", formatter.format(generic1, detail));
|
303
|
}
|
304
|
|
305
|
|
306
|
@Test
|
307
|
public void testGenericGetAbbrevTitleCache(){
|
308
|
generic1.setTitle("Part Title");
|
309
|
generic1.setAbbrevTitle("Pt. Tit.");
|
310
|
generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1987"));
|
311
|
IBook book1 = ReferenceFactory.newBook();
|
312
|
book1.setTitle("My book title");
|
313
|
book1.setAbbrevTitle("My bk. tit.");
|
314
|
book1.setAuthorship(genericTeam1); //TODO handling not yet defined
|
315
|
Reference inRef = (Reference)book1;
|
316
|
generic1.setInReference(inRef);
|
317
|
generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
|
318
|
generic1.setAbbrevTitleCache(null, false); //reset cache in case aspectJ is not enabled
|
319
|
//TODO author still unclear
|
320
|
// Assert.assertEquals("Unexpected nom. ref.", "in Authorteam, My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
|
321
|
Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit.: pp. 44. 1987", formatter.format(generic1, "pp. 44"));
|
322
|
generic1.setVolume("23");
|
323
|
Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit. 23: pp. 44. 1987", formatter.format(generic1, "pp. 44"));
|
324
|
generic1.setSeriesPart("ser. 11");
|
325
|
//TODO
|
326
|
// Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit., ser. 11, 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
|
327
|
|
328
|
//protected
|
329
|
generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true); //TODO still needed?
|
330
|
|
331
|
generic1.setDatePublished((VerbatimTimePeriod)null);
|
332
|
Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", formatter.format(generic1, null));
|
333
|
Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", formatter.format(generic1, ""));
|
334
|
Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44", formatter.format(generic1, "pp. 44"));
|
335
|
|
336
|
generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1893"));
|
337
|
Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44. 1893", formatter.format(generic1, "pp. 44"));
|
338
|
}
|
339
|
|
340
|
@Test
|
341
|
public void testGenericGetInRefWithoutInRef(){
|
342
|
generic1.setTitle("My generic title");
|
343
|
generic1.setAuthorship(genericTeam1);
|
344
|
generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
|
345
|
Assert.assertEquals("Unexpected title cache.", "My generic title: 2", formatter.format(generic1, "2"));
|
346
|
}
|
347
|
|
348
|
@Test
|
349
|
public void testBookGetTitleCache2(){
|
350
|
//series
|
351
|
IBook book1 = ReferenceFactory.newBook();
|
352
|
book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
|
353
|
book1.setVolume("Fasc. 11");
|
354
|
book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
|
355
|
Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1955", formatter.format((Reference)book1, "248"));
|
356
|
book1.setSeriesPart("1");
|
357
|
Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", formatter.format((Reference)book1, "248"));
|
358
|
}
|
359
|
|
360
|
//#4338
|
361
|
@Test
|
362
|
public void testGenericMissingVolume(){
|
363
|
generic1.setTitle("My generic");
|
364
|
generic1.setAuthorship(genericTeam1);
|
365
|
generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
|
366
|
generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
|
367
|
Assert.assertEquals("My generic: 55. 1883"+SEP+"1884", formatter.format(generic1, detail1));
|
368
|
generic1.setVolume("7");
|
369
|
Assert.assertEquals("My generic 7: 55. 1883"+SEP+"1884", formatter.format(generic1, detail1));
|
370
|
|
371
|
//inRef
|
372
|
Reference generic2 = ReferenceFactory.newGeneric();
|
373
|
generic2.setTitle("My InRef");
|
374
|
Person person2 = Person.NewTitledInstance("InRefAuthor");
|
375
|
generic2.setAuthorship(person2);
|
376
|
generic2.setDatePublished(TimePeriodParser.parseStringVerbatim("1885"));
|
377
|
generic1.setInReference(generic2);
|
378
|
|
379
|
//only reference has a volume
|
380
|
Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883"+SEP+"1884", formatter.format(generic1, detail1));
|
381
|
|
382
|
//both have a volume
|
383
|
generic2.setVolume("9"); //still unclear what should happen if you have such dirty data
|
384
|
// Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883-1884", formatter.format(generic1, detail1));
|
385
|
|
386
|
//only inref has volume
|
387
|
generic1.setVolume(null);
|
388
|
Assert.assertEquals("in InRefAuthor, My InRef 9: 55. 1883"+SEP+"1884", formatter.format(generic1, detail1));
|
389
|
}
|
390
|
|
391
|
@Test //see also the corresponging method in ReferenceDefaultCacheStrategy
|
392
|
public void testSectionInArticle(){
|
393
|
//#9326, #3764
|
394
|
Reference journal = ReferenceFactory.newJournal();
|
395
|
journal.setTitle("Phytotaxa");
|
396
|
Reference article = ReferenceFactory.newArticle();
|
397
|
String articleTitle = "New diatom species Navicula davidovichii from Vietnam (Southeast Asia)";
|
398
|
article.setTitle(articleTitle);
|
399
|
Team articleTeam = Team.NewTitledInstance("Kulikovskiy, M., Chudaev, D.A., Glushchenko, A., Kuznetsova, I. & Kociolek, J.P.", null);
|
400
|
article.setAuthorship(articleTeam);
|
401
|
article.setInJournal(journal);
|
402
|
article.setVolume("452(1)");
|
403
|
article.setPages("83-91");
|
404
|
article.setDatePublished(TimePeriodParser.parseStringVerbatim("8 Jul 2020"));
|
405
|
article.setDoi(DOI.fromString("10.11646/phytotaxa.452.1.8"));
|
406
|
Reference section = ReferenceFactory.newSection();
|
407
|
Team sectionTeam = Team.NewTitledInstance("Chudaev, D.A., Glushchenko, A., Kulikovskiy, M. & Kociolek, J.P.", null);
|
408
|
section.setAuthorship(sectionTeam);
|
409
|
section.setInReference(article);
|
410
|
|
411
|
Assert.assertEquals("Unexpected title cache.",
|
412
|
"in Phytotaxa 452(1): 55. 8 Jul 2020",
|
413
|
formatter.format(section, detail1));
|
414
|
}
|
415
|
|
416
|
@Test //see also the corresponging method in ReferenceDefaultCacheStrategy
|
417
|
public void testSectionInBookSection(){
|
418
|
//#9326, #3764
|
419
|
Reference book = ReferenceFactory.newBook();
|
420
|
book.setTitle("Species Plantarum");
|
421
|
Person person = Person.NewInstance("L.", "Linne", "C.G.", "Carl-Gustav");
|
422
|
Team bookAuthor = Team.NewInstance(person); // Team.NewTitledInstance("Linne", null);
|
423
|
|
424
|
book.setAuthorship(bookAuthor);
|
425
|
book.setVolume("3");
|
426
|
Reference bookSection = ReferenceFactory.newBookSection();
|
427
|
String bookSectionTitle = "Trees";
|
428
|
bookSection.setTitle(bookSectionTitle);
|
429
|
Team bookSectionTeam = Team.NewTitledInstance("Chapter author", "Chap. Aut.");
|
430
|
bookSection.setAuthorship(bookSectionTeam);
|
431
|
bookSection.setInBook(book);
|
432
|
bookSection.setPages("83-91");
|
433
|
bookSection.setDatePublished(TimePeriodParser.parseStringVerbatim("1752"));
|
434
|
bookSection.setDoi(DOI.fromString("10.12345/speciesplantarum.3"));
|
435
|
Reference section = ReferenceFactory.newSection();
|
436
|
Team sectionTeam = Team.NewTitledInstance("Section author", null);
|
437
|
section.setAuthorship(sectionTeam);
|
438
|
section.setInReference(bookSection);
|
439
|
|
440
|
Assert.assertEquals("Unexpected title cache.",
|
441
|
"in Linne, Species Plantarum 3: 55. 1752",
|
442
|
formatter.format(section, detail1));
|
443
|
bookAuthor = Team.NewTitledInstance("Linneus", null);
|
444
|
book.setAuthorship(bookAuthor);
|
445
|
Assert.assertEquals("Unexpected title cache.",
|
446
|
"in Linneus, Species Plantarum 3: 55. 1752",
|
447
|
formatter.format(section, detail1));
|
448
|
}
|
449
|
|
450
|
@Test
|
451
|
public void testShortSources(){
|
452
|
//#9705
|
453
|
book1.setAuthorship(bookTeam1);
|
454
|
bookSection1.setInBook(book1);
|
455
|
book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1972));
|
456
|
Assert.assertEquals("in TT., -: 44. 1972", formatter.format((Reference)bookSection1, "44"));
|
457
|
|
458
|
//#9705 (better use titlecache then completely empty reference; this handles the case when the abbreviated titleCache was forgotten to set to protected)
|
459
|
Reference book = ReferenceFactory.newBook();
|
460
|
book.setTitleCache("Only titlecache", true);
|
461
|
Assert.assertEquals("Only titlecache: 36", formatter.format(book, "36"));
|
462
|
}
|
463
|
|
464
|
@Test
|
465
|
public void testEmptyWithProtectedTitleCache(){
|
466
|
Reference ref = ReferenceFactory.newBook();
|
467
|
ref.setProtectedTitleCache(true);
|
468
|
String result = formatter.format(ref, null);
|
469
|
Assert.assertEquals("", result);
|
470
|
ref.setTitleCache("xxx", true);
|
471
|
result = formatter.format(ref, null);
|
472
|
Assert.assertEquals("xxx", result);
|
473
|
}
|
474
|
}
|