b25970b6c8b4815a61ef22ae2706b5043398f8d2
[gigi.git] / tests / club / wpia / gigi / dbObjects / TestUser.java
1 package club.wpia.gigi.dbObjects;
2
3 import static org.junit.Assert.*;
4
5 import org.junit.Test;
6
7 import club.wpia.gigi.GigiApiException;
8 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
9 import club.wpia.gigi.testUtils.ClientBusinessTest;
10
11 public class TestUser extends ClientBusinessTest {
12
13     @Test
14     public void testGetInitials() throws GigiApiException {
15         User u0 = User.getById(createVerificationUser("Kurti", "Hansel", createUniqueName() + "@email.com", TEST_PASSWORD));
16
17         assertEquals("KH", u0.getInitials());
18
19         // single name as preferred name
20         Name sName = new Name(u0, new NamePart(NamePartType.SINGLE_NAME, "SingleName"));
21         u0.setPreferredName(sName);
22         assertEquals("S", u0.getInitials());
23
24         // second western style name as preferred name
25         NamePart[] np = {
26                 new NamePart(NamePartType.FIRST_NAME, "John"), new NamePart(NamePartType.FIRST_NAME, "Walker"), new NamePart(NamePartType.LAST_NAME, "Hansel")
27         };
28         sName = new Name(u0, np);
29         u0.setPreferredName(sName);
30         assertEquals("JWH", u0.getInitials());
31         // second western style name as preferred name
32
33         NamePart[] np1 = {
34                 new NamePart(NamePartType.FIRST_NAME, "Dieter"), new NamePart(NamePartType.LAST_NAME, "Hansel"), new NamePart(NamePartType.LAST_NAME, "von"), new NamePart(NamePartType.LAST_NAME, "Hof"), new NamePart(NamePartType.SUFFIX, "Meister")
35         };
36         sName = new Name(u0, np1);
37         u0.setPreferredName(sName);
38         assertEquals("DHVHM", u0.getInitials());
39
40         // western style name with dash as preferred name (Hans-Peter)
41         NamePart[] np2 = {
42                 new NamePart(NamePartType.FIRST_NAME, "Hans-Peter"), new NamePart(NamePartType.LAST_NAME, "Hansel")
43         };
44         sName = new Name(u0, np2);
45         u0.setPreferredName(sName);
46         assertEquals("HH", u0.getInitials());
47
48         // western style name with dash as separate entry as preferred name
49         // (Hans - Peter)
50         NamePart[] np3 = {
51                 new NamePart(NamePartType.FIRST_NAME, "Hans"), new NamePart(NamePartType.FIRST_NAME, "-"), new NamePart(NamePartType.FIRST_NAME, "Joachim"), new NamePart(NamePartType.LAST_NAME, "Hansel")
52         };
53         sName = new Name(u0, np3);
54         u0.setPreferredName(sName);
55         assertEquals("HJH", u0.getInitials());
56
57         // western style name with / as separate entry as preferred name
58         // (Hans / Peter)
59         NamePart[] np4 = {
60                 new NamePart(NamePartType.FIRST_NAME, "Hans"), new NamePart(NamePartType.FIRST_NAME, "/"), new NamePart(NamePartType.FIRST_NAME, "Peter"), new NamePart(NamePartType.LAST_NAME, "Hansel")
61         };
62         sName = new Name(u0, np4);
63         u0.setPreferredName(sName);
64         assertEquals("HPH", u0.getInitials());
65     }
66
67 }