User and UserTest updated
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / core / UserTest.java
CommitLineData
ed6d035d
M
1/*\r
2 * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
3 *\r
4 * Project Smart Reservation System.\r
5 *\r
6 * Distributable under GPL license. See terms of license at gnu.org.\r
7 */\r
8package ch.bfh.ti.srs.core;\r
9\r
10import static org.junit.Assert.assertEquals;\r
11import static org.junit.Assert.assertFalse;\r
12import static org.junit.Assert.assertTrue;\r
13\r
14import org.junit.Rule;\r
15import org.junit.Test;\r
16import org.junit.rules.ExpectedException;\r
17\r
18public class UserTest {\r
19 //@Rule\r
20 //public ExpectedException createUserException = ExpectedException.none();\r
21 \r
22 @Test\r
23 public void createUserTest() throws Exception{\r
24 User testUser = new User("TestUser", "pass");\r
25 assertEquals("TestUser", testUser.getUserName());\r
26 \r
27 //Zweite Moeglichkeit um Exceptions zu testen, so lange keine Exception erwartet wird reicht es\r
28 //eine allfaellige mit 'throws Exception' an junit weiterzuleiten.\r
29 //--------------------------------------------------------------------------------------------\r
30 /*createUserException.expect(IllegalArgumentException.class);\r
31 createUserException.expectMessage("Invalid username");\r
32 User wrongArgumentUser1 = new User(null, "1234");\r
33 createUserException.expectMessage("Invalid password");\r
34 User wrongArgumentUser2 = new User("TestUser2", null);*/\r
35 }\r
36 \r
37 @Test(expected=IllegalArgumentException.class)\r
38 public void createUserInvalidUsernameTest() throws Exception{\r
39 User testUser = new User(null,"pass");\r
40 }\r
41 \r
42 @Test(expected=IllegalArgumentException.class)\r
43 public void createUserTooShortUsernameTest() throws Exception{\r
44 User testUser = new User(new String(),"pass");\r
45 User testUser2 = new User(new String("tes"),"pass");\r
46 }\r
47 \r
48 @Test(expected=IllegalArgumentException.class)\r
49 public void createUserInvalidPasswordTest() throws Exception{\r
50 User testUser = new User("TestUser", null);\r
51 }\r
52\r
53 @Test\r
54 public void checkPasswordTest() throws Exception{\r
55 User testUser = new User("TestUser", "pass");\r
56 assertTrue(testUser.checkPassword("pass"));\r
57 assertFalse(testUser.checkPassword("notmypass"));\r
58 }\r
59 \r
60 @Test(expected=IllegalArgumentException.class)\r
61 public void checkPasswordInvalidTest() throws Exception{\r
62 User testUser = new User("TestUser", "pass");\r
63 assertTrue(testUser.checkPassword(null));\r
64 }\r
65 \r
66 @Test\r
67 public void changePasswordTest() throws Exception{\r
68 User testUser = new User("TestUser", "pass");\r
69 assertTrue(testUser.checkPassword("pass"));\r
70 testUser.changePassword("newpass");\r
71 assertTrue(testUser.checkPassword("newpass"));\r
72 assertFalse(testUser.checkPassword("pass"));\r
73 assertFalse(testUser.checkPassword("notmypass"));\r
74 }\r
75 \r
76 @Test(expected=IllegalArgumentException.class)\r
77 public void changePasswordInvalid1Test() throws Exception{\r
78 User testUser = new User("TestUser", "pass");\r
79 testUser.changePassword(null);\r
80 }\r
81 \r
82 @Test(expected=IllegalArgumentException.class)\r
83 public void changePasswordInvalid2Test() throws Exception{\r
84 User testUser = new User("TestUser", "pass");\r
85 testUser.changePassword("pass");\r
86 }\r
87\r
88 @Test\r
89 public void setMailTest() throws Exception{\r
90 User testUser = new User("TestUser", "pass");\r
91 testUser.setMail("grosm9@bfh.ch");\r
92 }\r
93 \r
94 @Test(expected=IllegalArgumentException.class)\r
95 public void setMailIllegal1Test() throws Exception{\r
96 User testUser = new User("TestUser", "pass");\r
97 testUser.setMail("fda.ds");\r
98\r
99 }\r
100 \r
101 @Test(expected=IllegalArgumentException.class)\r
102 public void setMailIllegal2Test() throws Exception{\r
103 User testUser = new User("TestUser", "pass");\r
104 testUser.setMail("adfiug@fs");\r
105 }\r
106 \r
107 @Test(expected=IllegalArgumentException.class)\r
108 public void setMailIllegal3Test() throws Exception{\r
109 User testUser = new User("TestUser", "pass");\r
110 testUser.setMail(null);\r
111 }\r
112\r
113 @Test\r
114 public void getMailTest() throws Exception{\r
115 User testUser = new User("TestUser", "pass");\r
116 String mail = "grosm9@bfh.ch";\r
117\r
118 testUser.setMail(mail);\r
119 assertEquals(mail, testUser.getMail());\r
120 }\r
121\r
122 @Test\r
123 public void setAndGetNameTest() throws Exception{\r
124 User testUser = new User("TestUser", "pass");\r
125 testUser.setName("Tester");\r
126 assertEquals("Tester",testUser.getName());\r
127 testUser.setName(null);\r
128 assertEquals(null, testUser.getName());\r
129 }\r
130\r
131 @Test\r
132 public void setAndGetLastnameTest() throws Exception{\r
133 User testUser = new User("TestUser", "pass");\r
134 testUser.setLastname("Dummy");\r
135 assertEquals("Dummy", testUser.getLastname());\r
136 testUser.setLastname(null);\r
137 assertEquals(null, testUser.getLastname());\r
138 }\r
139}\r