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.model.agent.Person;
|
16
|
import eu.etaxonomy.cdm.model.agent.Team;
|
17
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
18
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
19
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
20
|
|
21
|
/**
|
22
|
* @author a.mueller
|
23
|
* @since 03.05.2021
|
24
|
*/
|
25
|
public class OriginalSourceFormatterTest {
|
26
|
|
27
|
//book // book section
|
28
|
private static Reference book1;
|
29
|
private static Team bookTeam1;
|
30
|
|
31
|
private static OriginalSourceFormatter formatter = OriginalSourceFormatter.INSTANCE;
|
32
|
private static OriginalSourceFormatter formatterWithBrackets = OriginalSourceFormatter.INSTANCE_WITH_YEAR_BRACKETS;
|
33
|
|
34
|
@Before
|
35
|
public void setUp() throws Exception {
|
36
|
|
37
|
//book / section
|
38
|
book1 = ReferenceFactory.newBook();
|
39
|
bookTeam1 = Team.NewTitledInstance("Book Author", "TT.");
|
40
|
}
|
41
|
|
42
|
@Test
|
43
|
public void testCreateShortCitation(){
|
44
|
book1.setTitle("My book");
|
45
|
book1.setAuthorship(bookTeam1);
|
46
|
book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
|
47
|
Assert.assertEquals("Unexpected title cache.", "Book Author, My book. 1975", book1.getTitleCache());
|
48
|
|
49
|
book1.setTitleCache(null, false);
|
50
|
book1.setEdition("ed. 3");
|
51
|
|
52
|
Assert.assertEquals("Unexpected title cache.", "Book Author 1975", formatter.format(book1, null));
|
53
|
Assert.assertEquals("Unexpected title cache.", "Book Author 1975", formatter.format(book1, ""));
|
54
|
Assert.assertEquals("Unexpected title cache.", "Book Author 1975: 55", formatter.format(book1, "55"));
|
55
|
Assert.assertEquals("Unexpected title cache.", "Book Author (1975: 55)",
|
56
|
formatterWithBrackets.format(book1, "55"));
|
57
|
|
58
|
//1 person
|
59
|
Person person1 = Person.NewInstance("Pers.", "Person", "P.", "Percy");
|
60
|
Team team = Team.NewInstance(person1);
|
61
|
book1.setAuthorship(team);
|
62
|
Assert.assertEquals("Unexpected title cache.", "Person 1975: 55", formatter.format(book1, "55"));
|
63
|
team.setHasMoreMembers(true);
|
64
|
Assert.assertEquals("Unexpected title cache.", "Person & al. 1975: 55", formatter.format(book1, "55"));
|
65
|
team.setHasMoreMembers(false);
|
66
|
|
67
|
//2 persons
|
68
|
Person person2 = Person.NewInstance("Lers.", "Lerson", "L.", "Lercy");
|
69
|
team.addTeamMember(person2);
|
70
|
Assert.assertEquals("Unexpected title cache.", "Person & Lerson 1975: 55", formatter.format(book1, "55"));
|
71
|
team.setHasMoreMembers(true);
|
72
|
Assert.assertEquals("Unexpected title cache.", "Person & al. 1975: 55", formatter.format(book1, "55"));
|
73
|
team.setHasMoreMembers(false);
|
74
|
|
75
|
//3 persons
|
76
|
Person person3 = Person.NewInstance("Gers.", "Gerson", "G.", "Gercy");
|
77
|
team.addTeamMember(person3);
|
78
|
Assert.assertEquals("Unexpected title cache.", "Person & al. 1975: 55", formatter.format(book1, "55"));
|
79
|
team.setHasMoreMembers(true);
|
80
|
Assert.assertEquals("Unexpected title cache.", "Person & al. 1975: 55", formatter.format(book1, "55"));
|
81
|
team.setHasMoreMembers(false); //in case we want to continue test
|
82
|
}
|
83
|
}
|