User and UserTest updated
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / core / UserTest.java
index 3a6059b..b01d257 100644 (file)
-///*\r
-// * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
-// *\r
-// * Project Smart Reservation System.\r
-// *\r
-// * Distributable under GPL license. See terms of license at gnu.org.\r
-// */\r
-//package ch.bfh.ti.srs.core;\r
-//\r
-//import static org.junit.Assert.assertEquals;\r
-//import static org.junit.Assert.assertFalse;\r
-//import static org.junit.Assert.assertTrue;\r
-//\r
-//import org.junit.Rule;\r
-//import org.junit.Test;\r
-//import org.junit.rules.ExpectedException;\r
-//\r
-//public class UserTest {\r
-//     //@Rule\r
-//     //public ExpectedException createUserException = ExpectedException.none();\r
-//     \r
-//     @Test\r
-//     public void createUserTest() throws Exception{\r
-//             User testUser = new User("TestUser", "pass");\r
-//             assertEquals("TestUser", testUser.getUserName());\r
-//             \r
-//             //Zweite Moeglichkeit um Exceptions zu testen, so lange keine Exception erwartet wird reicht es\r
-//             //eine allfaellige mit 'throws Exception' an junit weiterzuleiten.\r
-//             //--------------------------------------------------------------------------------------------\r
-//             /*createUserException.expect(IllegalArgumentException.class);\r
-//             createUserException.expectMessage("Invalid username");\r
-//             User wrongArgumentUser1 = new User(null, "1234");\r
-//             createUserException.expectMessage("Invalid password");\r
-//             User wrongArgumentUser2 = new User("TestUser2", null);*/\r
-//     }\r
-//     \r
-//     @Test(expected=IllegalArgumentException.class)\r
-//     public void createUserInvalidUsernameTest() {\r
-//             User testUser = new User(new String(),"pass");\r
-//     }\r
-//     \r
-//     @Test(expected=IllegalArgumentException.class)\r
-//     public void createUserInvalidPasswordTest() {\r
-//             User testUser = new User("TestUser", new String());\r
-//     }\r
-//\r
-//     @Test\r
-//     public void checkPasswordTest() throws Exception{\r
-//             User testUser = new User("TestUser", "pass");\r
-//             assertTrue(testUser.checkPassword("pass"));\r
-//             assertFalse(testUser.checkPassword("notmypass"));\r
-//             assertFalse(testUser.checkPassword(null));\r
-//     }\r
-//     \r
-//     @Test\r
-//     public void changePasswordTest() throws Exception{\r
-//             User testUser = new User("TestUser", "pass");\r
-//             assertTrue(testUser.checkPassword("pass"));\r
-//             testUser.changePassword("newpass");\r
-//             assertTrue(testUser.checkPassword("newpass"));\r
-//             assertFalse(testUser.checkPassword("pass"));\r
-//             assertFalse(testUser.checkPassword("notmypass"));\r
-//             assertFalse(testUser.checkPassword(null));\r
-//     }\r
-//     \r
-//     @Test(expected=IllegalArgumentException.class)\r
-//     public void changePasswordInvalidPasswordTest() {\r
-//             User testUser = new User("TestUser", "pass");\r
-//             testUser.changePassword(null);\r
-//     }\r
-//\r
-//     @Test\r
-//     public void setMailTest() {\r
-//             User testUser = new User("TestUser", "pass");\r
-//             String goodMail = "grosm9@bfh.ch";\r
-//             String wrongMail1 = "ioajfd.ch";\r
-//             String wrongMail2 = "asjdfh@fds";\r
-//\r
-//             assertTrue(testUser.setMail(goodMail));\r
-//             assertFalse(testUser.setMail(wrongMail1));\r
-//             assertFalse(testUser.setMail(wrongMail2));\r
-//             assertFalse(testUser.setMail(null));\r
-//     }\r
-//\r
-//     @Test\r
-//     public void getMailTest() {\r
-//             User testUser = new User("TestUser", "pass");\r
-//             String mail = "grosm9@bfh.ch";\r
-//\r
-//             testUser.setMail(mail);\r
-//             assertEquals(mail, testUser.getMail());\r
-//     }\r
-//\r
-//     @Test\r
-//     public void setAndGetNameTest() {\r
-//             User testUser = new User("TestUser", "pass");\r
-//             testUser.setName("Tester");\r
-//             assertEquals("Tester",testUser.getName());\r
-//             testUser.setName(null);\r
-//             assertEquals(null, testUser.getName());\r
-//     }\r
-//\r
-//     @Test\r
-//     public void setAndGetLastnameTest() {\r
-//             User testUser = new User("TestUser", "pass");\r
-//             testUser.setLastname("Dummy");\r
-//             assertEquals("Dummy", testUser.getLastname());\r
-//             testUser.setLastname(null);\r
-//             assertEquals(null, testUser.getLastname());\r
-//     }\r
-//}\r
+/*\r
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
+ *\r
+ * Project Smart Reservation System.\r
+ *\r
+ * Distributable under GPL license. See terms of license at gnu.org.\r
+ */\r
+package ch.bfh.ti.srs.core;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+\r
+import org.junit.Rule;\r
+import org.junit.Test;\r
+import org.junit.rules.ExpectedException;\r
+\r
+public class UserTest {\r
+       //@Rule\r
+       //public ExpectedException createUserException = ExpectedException.none();\r
+       \r
+       @Test\r
+       public void createUserTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               assertEquals("TestUser", testUser.getUserName());\r
+               \r
+               //Zweite Moeglichkeit um Exceptions zu testen, so lange keine Exception erwartet wird reicht es\r
+               //eine allfaellige mit 'throws Exception' an junit weiterzuleiten.\r
+               //--------------------------------------------------------------------------------------------\r
+               /*createUserException.expect(IllegalArgumentException.class);\r
+               createUserException.expectMessage("Invalid username");\r
+               User wrongArgumentUser1 = new User(null, "1234");\r
+               createUserException.expectMessage("Invalid password");\r
+               User wrongArgumentUser2 = new User("TestUser2", null);*/\r
+       }\r
+       \r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void createUserInvalidUsernameTest() throws Exception{\r
+               User testUser = new User(null,"pass");\r
+       }\r
+       \r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void createUserTooShortUsernameTest() throws Exception{\r
+               User testUser = new User(new String(),"pass");\r
+               User testUser2 = new User(new String("tes"),"pass");\r
+       }\r
+       \r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void createUserInvalidPasswordTest() throws Exception{\r
+               User testUser = new User("TestUser", null);\r
+       }\r
+\r
+       @Test\r
+       public void checkPasswordTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               assertTrue(testUser.checkPassword("pass"));\r
+               assertFalse(testUser.checkPassword("notmypass"));\r
+       }\r
+       \r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void checkPasswordInvalidTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               assertTrue(testUser.checkPassword(null));\r
+       }\r
+       \r
+       @Test\r
+       public void changePasswordTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               assertTrue(testUser.checkPassword("pass"));\r
+               testUser.changePassword("newpass");\r
+               assertTrue(testUser.checkPassword("newpass"));\r
+               assertFalse(testUser.checkPassword("pass"));\r
+               assertFalse(testUser.checkPassword("notmypass"));\r
+       }\r
+       \r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void changePasswordInvalid1Test() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               testUser.changePassword(null);\r
+       }\r
+       \r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void changePasswordInvalid2Test() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               testUser.changePassword("pass");\r
+       }\r
+\r
+       @Test\r
+       public void setMailTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               testUser.setMail("grosm9@bfh.ch");\r
+       }\r
+       \r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void setMailIllegal1Test() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               testUser.setMail("fda.ds");\r
+\r
+       }\r
+       \r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void setMailIllegal2Test() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               testUser.setMail("adfiug@fs");\r
+       }\r
+       \r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void setMailIllegal3Test() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               testUser.setMail(null);\r
+       }\r
+\r
+       @Test\r
+       public void getMailTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               String mail = "grosm9@bfh.ch";\r
+\r
+               testUser.setMail(mail);\r
+               assertEquals(mail, testUser.getMail());\r
+       }\r
+\r
+       @Test\r
+       public void setAndGetNameTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               testUser.setName("Tester");\r
+               assertEquals("Tester",testUser.getName());\r
+               testUser.setName(null);\r
+               assertEquals(null, testUser.getName());\r
+       }\r
+\r
+       @Test\r
+       public void setAndGetLastnameTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               testUser.setLastname("Dummy");\r
+               assertEquals("Dummy", testUser.getLastname());\r
+               testUser.setLastname(null);\r
+               assertEquals(null, testUser.getLastname());\r
+       }\r
+}\r