Project

General

Profile

Download (8.51 KB) Statistics
| Branch: | Tag: | Revision:
1 518d0590 Andreas Müller
/**
2
* Copyright (C) 2007 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
10
package eu.etaxonomy.cdm.strategy.cache.agent;
11
12
13
import static org.junit.Assert.assertNotNull;
14
15 a13c5f66 Andreas Müller
import org.apache.commons.lang.StringUtils;
16 518d0590 Andreas Müller
import org.apache.log4j.Logger;
17
import org.junit.After;
18
import org.junit.AfterClass;
19 a13c5f66 Andreas Müller
import org.junit.Assert;
20 518d0590 Andreas Müller
import org.junit.Before;
21
import org.junit.BeforeClass;
22
import org.junit.Test;
23
24
import eu.etaxonomy.cdm.model.agent.Person;
25
26
/**
27
 * @author a.mueller
28
 * @created 29.09.2009
29
 * @version 1.0
30
 */
31
public class PersonDefaultCacheStrategyTest {
32
	@SuppressWarnings("unused")
33
	private static final Logger logger = Logger.getLogger(PersonDefaultCacheStrategyTest.class);
34
35
	private static Person person1;
36
	private static Person person2;
37
	private static Person person3;
38
	
39
	/**
40
	 * @throws java.lang.Exception
41
	 */
42
	@BeforeClass
43
	public static void setUpBeforeClass() throws Exception {
44
	}
45
46
	/**
47
	 * @throws java.lang.Exception
48
	 */
49
	@AfterClass
50
	public static void tearDownAfterClass() throws Exception {
51
		
52
		
53
	}
54
55
	/**
56
	 * @throws java.lang.Exception
57
	 */
58
	@Before
59
	public void setUp() throws Exception {
60
		person1 = Person.NewInstance();
61
		
62
		person1.setFirstname("P1FN");
63
		person1.setLastname("P1LN");
64
		person1.setPrefix("Dr1.");
65
		person1.setSuffix("Suff1");
66
		
67
		person2 = Person.NewInstance();
68
		person2.setNomenclaturalTitle("P2NomT");
69
		person2.setLastname("P2LN");
70
		person2.setFirstname("P2FN");
71
		person2.setSuffix("P2Suff");
72
		
73
		person3 = Person.NewInstance(); //empty person
74
		
75
	}
76
77
	/**
78
	 * @throws java.lang.Exception
79
	 */
80
	@After
81
	public void tearDown() throws Exception {
82
	}
83
	
84
//**************************************** TESTS **************************************
85
	
86
	/**
87
	 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy#NewInstance()}.
88
	 */
89
	@Test
90
	public final void testNewInstance() {
91
		PersonDefaultCacheStrategy cacheStrategy = PersonDefaultCacheStrategy.NewInstance();
92
		assertNotNull(cacheStrategy);
93
	}
94
95
	@Test
96
	public final void testGetNomenclaturalTitleCache(){
97
		Assert.assertNotNull("person1 nomenclatural title must not to be null", person1.getNomenclaturalTitle());
98
		Assert.assertEquals("Person1 nomenclatural title should be created by elements", "Dr1. P1FN P1LN Suff1", person1.getNomenclaturalTitle());
99
		person1.setSuffix(null);
100
		Assert.assertEquals("Person1 title should be Dr1. P1FN P1LN", "Dr1. P1FN P1LN", person1.getNomenclaturalTitle());
101
		//peson2
102
		Assert.assertEquals("Person2 title should be P2NomT", "P2NomT", person2.getNomenclaturalTitle());
103
		//person3
104
		Assert.assertNotNull("person3 nomenclatural title must not to be null", person3.getNomenclaturalTitle());
105 a13c5f66 Andreas Müller
		Assert.assertTrue("Person3 nomenclatural title must not be empty", StringUtils.isNotBlank(person3.getNomenclaturalTitle()));
106 518d0590 Andreas Müller
		//don't take to serious, may be also something different, but not empty
107
		Assert.assertEquals("Person3 title should start with Person#0", "Person#0", person3.getNomenclaturalTitle().substring(0, 8));
108
	}
109
	
110
111
	@Test
112
	public final void testGetTitleCache(){
113
		Assert.assertNotNull("person1 title cache must not to be null", person1.getTitleCache());
114
		Assert.assertEquals("Person1 title cache should be created by elements", "Dr1. P1FN P1LN Suff1", person1.getTitleCache());
115
		person1.setSuffix(null);
116
		Assert.assertEquals("Person1 title cache should be Dr1. P1FN P1LN", "Dr1. P1FN P1LN", person1.getTitleCache());
117
		//peson2
118
		Assert.assertEquals("Person2 title cache should be P2NomT", "P2FN P2LN P2Suff", person2.getTitleCache());
119
		//person3
120
		Assert.assertNotNull("person3 title cache must not to be null", person3.getTitleCache());
121 a13c5f66 Andreas Müller
		Assert.assertTrue("Person3 title cache must not be empty", StringUtils.isNotBlank(person3.getTitleCache()));
122 518d0590 Andreas Müller
		//don't take to serious, may be also something different, but not empty
123
		Assert.assertEquals("Person3 title cache should start with Person#0", "Person#0", person3.getTitleCache().substring(0, 8));
124 892efc69 Andreas Kohlbecker
		person3.setFirstname("Klaus");
125
		Assert.assertEquals("Person3 title cache should be Klaus", "Klaus", person3.getTitleCache());
126 518d0590 Andreas Müller
	}
127 02390953 Andreas Müller
128
	@Test
129
    public final void testInitialsFromFirstname(){
130
	    PersonDefaultCacheStrategy formatter = PersonDefaultCacheStrategy.NewInstance();
131
	    boolean force = true;
132
133
	    String firstname = null;
134
        Assert.assertNull(formatter.getInitialsFromFirstname(firstname, force));
135
136
        firstname = "";
137
        Assert.assertEquals("", formatter.getInitialsFromFirstname(firstname, force));
138
139
        firstname = "  ";
140
        Assert.assertEquals("We expect blanks to be trimmed", "", formatter.getInitialsFromFirstname(firstname, force));
141
142
	    firstname = "John Michael ";
143
	    Assert.assertEquals("J.M.", formatter.getInitialsFromFirstname(firstname, force));
144
145
	    firstname = "Walter G.";
146
        Assert.assertEquals("W.G.", formatter.getInitialsFromFirstname(firstname, force));
147
148
        firstname = "A.L.";
149
        Assert.assertEquals("A.L.", formatter.getInitialsFromFirstname(firstname, force));
150
151
        firstname = "A.Ludw. W.";
152
        Assert.assertEquals("A.L.W.", formatter.getInitialsFromFirstname(firstname, force));
153
154
        firstname = "A. Ludw.  Norbert W.";
155
        Assert.assertEquals("A.L.N.W.", formatter.getInitialsFromFirstname(firstname, force));
156
157
        force = false;
158
        firstname = "A. Ludw.  Norbert W.";
159
        Assert.assertEquals("A.Ludw.N.W.", formatter.getInitialsFromFirstname(firstname, force));
160
161
        firstname = "W.-H.";
162
        Assert.assertEquals("W.-H.", formatter.getInitialsFromFirstname(firstname, force));
163
        firstname = "W.-Henning";
164
        Assert.assertEquals("W.-H.", formatter.getInitialsFromFirstname(firstname, force));
165
        firstname = "W.-Henn.";
166
        Assert.assertEquals("W.-Henn.", formatter.getInitialsFromFirstname(firstname, force));
167
        firstname = "Wolf-Henning";
168
        Assert.assertEquals("W.-H.", formatter.getInitialsFromFirstname(firstname, force));
169
        firstname = "Wolf\u2013 Henning";
170
        Assert.assertEquals("W.\u2013H.", formatter.getInitialsFromFirstname(firstname, force));
171
172
173
        firstname = "W";
174
        Assert.assertEquals("W.", formatter.getInitialsFromFirstname(firstname, force));
175
176
        firstname = "W K";
177
        Assert.assertEquals("W.K.", formatter.getInitialsFromFirstname(firstname, force));
178
179
        firstname = "WK";
180
        Assert.assertEquals("W.K.", formatter.getInitialsFromFirstname(firstname, force));
181
182
        firstname = "WKH";
183
        Assert.assertEquals("W.K.H.", formatter.getInitialsFromFirstname(firstname, force));
184
185
186
        //force
187
        force = true;
188
        firstname = "W.-H.";
189
        Assert.assertEquals("W.-H.", formatter.getInitialsFromFirstname(firstname, force));
190
        firstname = "W.-Henning";
191
        Assert.assertEquals("W.-H.", formatter.getInitialsFromFirstname(firstname, force));
192
        firstname = "W.-Henn.";
193
        Assert.assertEquals("W.-H.", formatter.getInitialsFromFirstname(firstname, force));
194
        firstname = "Wolf-Henning";
195
        Assert.assertEquals("W.-H.", formatter.getInitialsFromFirstname(firstname, force));
196
197
        firstname = "W";
198
        Assert.assertEquals("W.", formatter.getInitialsFromFirstname(firstname, force));
199
200
        firstname = "W K";
201
        Assert.assertEquals("W.K.", formatter.getInitialsFromFirstname(firstname, force));
202
203
        firstname = "WK";
204
        Assert.assertEquals("W.K.", formatter.getInitialsFromFirstname(firstname, force));
205
206
        firstname = "WKH";
207
        Assert.assertEquals("W.K.H.", formatter.getInitialsFromFirstname(firstname, force));
208
209
        force = false;
210
        firstname = "Pe. Y.";
211
        Assert.assertEquals("Pe.Y.", formatter.getInitialsFromFirstname(firstname, force));
212
213
214
        //must not throw exception (exact result may change in future)
215
        firstname = "W.-H.-";
216
        Assert.assertEquals("W.-H.-", formatter.getInitialsFromFirstname(firstname, force));
217
        firstname = "W.-Hennin-";
218
        Assert.assertEquals("W.-H.-", formatter.getInitialsFromFirstname(firstname, force));
219
220
        force = false;
221
        firstname = "W.-H.-";
222
        Assert.assertEquals("W.-H.-", formatter.getInitialsFromFirstname(firstname, force));
223
        firstname = "W.-Hennin-";
224
        Assert.assertEquals("W.-H.-", formatter.getInitialsFromFirstname(firstname, force));
225
226
	}
227
228 518d0590 Andreas Müller
}