UserControllerTest updated for better test coverage on abstract class
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / controller / UserControllerTest.java
index d113635..02ee9f4 100644 (file)
@@ -41,14 +41,24 @@ public class UserControllerTest {
                sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                sc.registUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
                sc.registUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
+               \r
+               UserController uc = new UserController(dh, sc);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
        }\r
 \r
        @Test(expected = Exception.class)\r
-       public void addUserExceptionTest() throws Exception {\r
+       public void addUserExceptionTest1() throws Exception {\r
                SessionController sc = new SessionController(null);\r
 \r
                sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
        }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void addUserExceptionTest2() throws Exception {\r
+               UserController uc = new UserController(null, null);\r
+               \r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+       }\r
        \r
        @Test\r
        public void getUserTest() throws Exception {\r
@@ -415,7 +425,37 @@ public class UserControllerTest {
 \r
                assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
        }\r
+       \r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void makeReservationException5Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
+\r
+               Resource resource1 = new Resource("Room101", "Class room");\r
+               Resource resource2 = new Resource("Room101", "Class room");\r
+               Resource resource3 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+               dh.addResource(resource2);\r
+               dh.addResource(resource3);\r
+\r
+               List<DateRange> dtList = new ArrayList<DateRange>();\r
+               for (int i = 1; i < 10; i++) {\r
+                       dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 12, 00, 00)));\r
+               }\r
 \r
+               assertEquals(null, uc.makeReservation(null, resource1, null, "remark"));\r
+       }\r
+       \r
        @SuppressWarnings("deprecation")\r
        @Test\r
        public void changeReservationTest() throws Exception {\r