unused imports removed
[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
ed6d035d 14import org.junit.Test;\r
1f7b5004
M
15import ch.bfh.ti.srs.extern.Password;\r
16\r
1ec0e01f
M
17/**\r
18 * @author Michael Grossen\r
19 */\r
ed6d035d
M
20public class UserTest {\r
21 //@Rule\r
22 //public ExpectedException createUserException = ExpectedException.none();\r
23 \r
24 @Test\r
25 public void createUserTest() throws Exception{\r
26 User testUser = new User("TestUser", "pass");\r
27 assertEquals("TestUser", testUser.getUserName());\r
28 \r
29 //Zweite Moeglichkeit um Exceptions zu testen, so lange keine Exception erwartet wird reicht es\r
30 //eine allfaellige mit 'throws Exception' an junit weiterzuleiten.\r
31 //--------------------------------------------------------------------------------------------\r
32 /*createUserException.expect(IllegalArgumentException.class);\r
33 createUserException.expectMessage("Invalid username");\r
34 User wrongArgumentUser1 = new User(null, "1234");\r
35 createUserException.expectMessage("Invalid password");\r
36 User wrongArgumentUser2 = new User("TestUser2", null);*/\r
37 }\r
38 \r
1f7b5004
M
39 @Test\r
40 public void createExistingTest() throws Exception{\r
41 User testUser = new User("TestUser", "pass", "grosm9@bfh.ch", "Test", "Dummy");\r
42 assertEquals("TestUser", testUser.getUserName());\r
43 assertEquals("pass", testUser.getEncryptedPassword());\r
44 assertEquals("grosm9@bfh.ch", testUser.getMail());\r
45 assertEquals("Test", testUser.getName());\r
46 assertEquals("Dummy", testUser.getLastname());\r
47 }\r
48 \r
49 @Test\r
50 public void getEncryptedPasswordTest() throws Exception{\r
51 String encryptedPass = Password.getSaltedHash("testPassword");\r
52 User testUser = new User("TestUser", encryptedPass, "grosm9@bfh.ch", "Test", "Dummy");\r
53 assertEquals(encryptedPass, testUser.getEncryptedPassword());\r
54 }\r
55 \r
ed6d035d
M
56 @Test(expected=IllegalArgumentException.class)\r
57 public void createUserInvalidUsernameTest() throws Exception{\r
58 User testUser = new User(null,"pass");\r
59 }\r
60 \r
61 @Test(expected=IllegalArgumentException.class)\r
62 public void createUserTooShortUsernameTest() throws Exception{\r
63 User testUser = new User(new String(),"pass");\r
64 User testUser2 = new User(new String("tes"),"pass");\r
65 }\r
66 \r
67 @Test(expected=IllegalArgumentException.class)\r
68 public void createUserInvalidPasswordTest() throws Exception{\r
69 User testUser = new User("TestUser", null);\r
70 }\r
71\r
72 @Test\r
73 public void checkPasswordTest() throws Exception{\r
74 User testUser = new User("TestUser", "pass");\r
75 assertTrue(testUser.checkPassword("pass"));\r
76 assertFalse(testUser.checkPassword("notmypass"));\r
77 }\r
78 \r
79 @Test(expected=IllegalArgumentException.class)\r
80 public void checkPasswordInvalidTest() throws Exception{\r
81 User testUser = new User("TestUser", "pass");\r
82 assertTrue(testUser.checkPassword(null));\r
83 }\r
84 \r
85 @Test\r
86 public void changePasswordTest() throws Exception{\r
87 User testUser = new User("TestUser", "pass");\r
88 assertTrue(testUser.checkPassword("pass"));\r
89 testUser.changePassword("newpass");\r
90 assertTrue(testUser.checkPassword("newpass"));\r
91 assertFalse(testUser.checkPassword("pass"));\r
92 assertFalse(testUser.checkPassword("notmypass"));\r
93 }\r
94 \r
95 @Test(expected=IllegalArgumentException.class)\r
96 public void changePasswordInvalid1Test() throws Exception{\r
97 User testUser = new User("TestUser", "pass");\r
98 testUser.changePassword(null);\r
99 }\r
100 \r
101 @Test(expected=IllegalArgumentException.class)\r
102 public void changePasswordInvalid2Test() throws Exception{\r
103 User testUser = new User("TestUser", "pass");\r
104 testUser.changePassword("pass");\r
105 }\r
106\r
107 @Test\r
108 public void setMailTest() throws Exception{\r
109 User testUser = new User("TestUser", "pass");\r
110 testUser.setMail("grosm9@bfh.ch");\r
111 }\r
112 \r
113 @Test(expected=IllegalArgumentException.class)\r
114 public void setMailIllegal1Test() throws Exception{\r
115 User testUser = new User("TestUser", "pass");\r
116 testUser.setMail("fda.ds");\r
117\r
118 }\r
119 \r
120 @Test(expected=IllegalArgumentException.class)\r
121 public void setMailIllegal2Test() throws Exception{\r
122 User testUser = new User("TestUser", "pass");\r
123 testUser.setMail("adfiug@fs");\r
124 }\r
125 \r
126 @Test(expected=IllegalArgumentException.class)\r
127 public void setMailIllegal3Test() throws Exception{\r
128 User testUser = new User("TestUser", "pass");\r
129 testUser.setMail(null);\r
130 }\r
131\r
132 @Test\r
133 public void getMailTest() throws Exception{\r
134 User testUser = new User("TestUser", "pass");\r
135 String mail = "grosm9@bfh.ch";\r
136\r
137 testUser.setMail(mail);\r
138 assertEquals(mail, testUser.getMail());\r
139 }\r
140\r
141 @Test\r
142 public void setAndGetNameTest() throws Exception{\r
143 User testUser = new User("TestUser", "pass");\r
144 testUser.setName("Tester");\r
145 assertEquals("Tester",testUser.getName());\r
146 testUser.setName(null);\r
147 assertEquals(null, testUser.getName());\r
148 }\r
149\r
150 @Test\r
151 public void setAndGetLastnameTest() throws Exception{\r
152 User testUser = new User("TestUser", "pass");\r
153 testUser.setLastname("Dummy");\r
154 assertEquals("Dummy", testUser.getLastname());\r
155 testUser.setLastname(null);\r
156 assertEquals(null, testUser.getLastname());\r
157 }\r
158}\r