Split UserController into 'Controller' and 'UserController extends
authorMichael <Michael@Michael-LT.bfh.ch>
Tue, 1 Dec 2015 14:59:40 +0000 (15:59 +0100)
committerMichael <Michael@Michael-LT.bfh.ch>
Tue, 1 Dec 2015 14:59:40 +0000 (15:59 +0100)
Controller', UserControllerTest updated.

src/main/java/ch/bfh/ti/srs/controller/Controller.java [copied from src/main/java/ch/bfh/ti/srs/controller/UserController.java with 74% similarity]
src/main/java/ch/bfh/ti/srs/controller/UserController.java
src/test/java/ch/bfh/ti/srs/controller/UserControllerTest.java

@@ -5,6 +5,9 @@
  *\r
  * Distributable under GPL license. See terms of license at gnu.org.\r
  */\r
+/**\r
+ * \r
+ */\r
 package ch.bfh.ti.srs.controller;\r
 \r
 import java.rmi.AlreadyBoundException;\r
@@ -23,13 +26,21 @@ import ch.bfh.ti.srs.dataschema.Resource;
 import ch.bfh.ti.srs.dataschema.User;\r
 \r
 /**\r
- * @author Michael Grossen\r
+ * @author Michael\r
+ *\r
  */\r
-public class UserController {\r
-       private User currentUser;\r
-       private DataHandler dh;\r
+public class Controller {\r
+       protected DataHandler dh;\r
+       protected User currentUser;\r
 \r
-       public UserController() {\r
+       /**\r
+        * Sets the <code>DataHandler</code> implementation for this Controller,\r
+        * must be set before using all other methods!\r
+        * @param dh\r
+        *            DataHandler implementation (i.e. DataHandlerForExcel)\r
+        */\r
+       public Controller(DataHandler dh) {\r
+               this.dh = dh;\r
        }\r
 \r
        /**\r
@@ -41,7 +52,7 @@ public class UserController {
        public void setDataHandler(DataHandler dh) {\r
                this.dh = dh;\r
        }\r
-\r
+       \r
        /**\r
         * Tries to log in a <code>User</code> with the given credentials\r
         * @param userName\r
@@ -110,84 +121,19 @@ public class UserController {
        }\r
 \r
        /**\r
-        * Gets the user name of the current user\r
-        * @deprecated use <code>getLoggedUser().getUserName()</code>\r
-        * @return user name\r
+        * Returns all stored resources of the set DataHandler\r
+        * @return <code>List</code> of resources\r
         * @throws Exception\r
         *             no <code>DataHandler</code> is set\r
         */\r
-       @Deprecated\r
-       public String getLoggedUserName() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getUserName();\r
-       }\r
-\r
-       /**\r
-        * Gets the mail address of the current user\r
-        * @deprecated use <code>getLoggedUser().getMail()</code>\r
-        * @return Mail address\r
-        * @throws Exception\r
-        *             no user is logged in\r
-        */\r
-       @Deprecated\r
-       public String getLoggedMail() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getMail();\r
-       }\r
-\r
-       /**\r
-        * Gets the first name of the current user\r
-        * @deprecated use <code>getLoggedUser().getName()</code>\r
-        * @return First name\r
-        * @throws Exception\r
-        *             no user is logged in\r
-        */\r
-       @Deprecated\r
-       public String getLoggedName() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getName();\r
-       }\r
-\r
-       /**\r
-        * Gets the last name of the current user\r
-        * @deprecated use <code>getLoggedUser().getLastName()</code>\r
-        * @return Last name\r
-        * @throws Exception\r
-        *             no user is logged in\r
-        */\r
-       @Deprecated\r
-       public String getLoggedLastname() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getLastname();\r
-       }\r
-\r
-       /**\r
-        * Gets the current logged <code>User</code>\r
-        * @return current <code>User</code>, or <code>null</code> if no\r
-        *         <code>User</code> is logged in\r
-        */\r
-       public User getLoggedUser() {\r
-               if (currentUser == null)\r
-                       return null;\r
-               return currentUser;\r
-       }\r
-\r
-       /**\r
-        * Searches the set DataHandler for a specific <code>User</code>\r
-        * @param userName\r
-        *            <code>User</code>\r
-        * @return clone of <code>User</code>\r
-        * @throws Exception\r
-        *             No <code>DataHandler</code> is set\r
-        */\r
-       public User getUser(String userName) throws Exception {\r
+       public List<Resource> getResources() throws Exception {\r
                if (dh == null)\r
                        throw new Exception("No DataHandler set");\r
-               return dh.findUser(userName).clone();\r
+               List<Resource> resourceList = new ArrayList<Resource>();\r
+               for (Resource resource : dh.getAllResources()) {\r
+                       resourceList.add(resource.clone());\r
+               }\r
+               return resourceList;\r
        }\r
 \r
        /**\r
@@ -217,26 +163,6 @@ public class UserController {
        }\r
 \r
        /**\r
-        * Returns the reservation or null if no reservation was found\r
-        * @param id\r
-        *            reservation identifier\r
-        * @return <code>Reservation</code> copy of reservation with given id,\r
-        *         <code>null</code> no reservation with this id found\r
-        * @throws Exception\r
-        *             No DataHandler set or id null\r
-        */\r
-       public Reservation getReservation(UUID id) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (id == null)\r
-                       throw new Exception("uuid must be defined");\r
-               if (dh.findReservation(id) == null)\r
-                       return null;\r
-               else\r
-                       return dh.findReservation(id).clone();\r
-       }\r
-\r
-       /**\r
         * Returns the reservations of the given user\r
         * @param user\r
         *            Owner, if <code>null</code> returns the reservations of the\r
@@ -246,14 +172,11 @@ public class UserController {
         *             either no <code>DataHandler</code> is set or no user is\r
         *             logged in while user param = null\r
         */\r
-       public Map<Reservation, Boolean> getUserReservations(User user) throws Exception {\r
+       public Map<Reservation, Boolean> getUserReservations_Super(User user) throws Exception {\r
                if (dh == null)\r
                        throw new Exception("No DataHandler set");\r
                if (user == null) {\r
-                       if (currentUser == null)\r
-                               throw new Exception("user must be defined, if no user is logged in");\r
-                       else\r
-                               user = currentUser;\r
+                       throw new Exception("user must be defined");\r
                }\r
 \r
                // Could be swapped out to private method for better performance (just\r
@@ -267,6 +190,26 @@ public class UserController {
        }\r
 \r
        /**\r
+        * Returns the reservation or null if no reservation was found\r
+        * @param id\r
+        *            reservation identifier\r
+        * @return <code>Reservation</code> copy of reservation with given id,\r
+        *         <code>null</code> no reservation with this id found\r
+        * @throws Exception\r
+        *             No DataHandler set or id null\r
+        */\r
+       public Reservation getReservation(UUID id) throws Exception {\r
+               if (dh == null)\r
+                       throw new Exception("No DataHandler set");\r
+               if (id == null)\r
+                       throw new Exception("uuid must be defined");\r
+               if (dh.findReservation(id) == null)\r
+                       return null;\r
+               else\r
+                       return dh.findReservation(id).clone();\r
+       }\r
+\r
+       /**\r
         * Returns <code>Map</code> of reservation group (recurring reservations)\r
         * @param groupId\r
         *            group identifier\r
@@ -352,18 +295,14 @@ public class UserController {
         *             if no <code>DataHandler</code> is set or the logged user is\r
         *             not authorized\r
         */\r
-       public boolean changeReservation(Reservation reservation) throws Exception {\r
+       public boolean changeReservation_Super(Reservation reservation) throws Exception {\r
                if (dh == null)\r
                        throw new Exception("No DataHandler set");\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
                if (reservation == null)\r
                        throw new IllegalArgumentException("Reservation must be defined");\r
-               if (!reservation.getUser().equals(currentUser))\r
-                       throw new Exception("You are not authorized to make this change");\r
                return dh.editReservation(reservation);\r
        }\r
-\r
+       \r
        /**\r
         * Deletes the given reservation in the set <code>DataHandler</code>\r
         * referring to the reservation id\r
@@ -377,31 +316,11 @@ public class UserController {
         *             if no <code>DataHandler</code> is set, no <code>User</code>\r
         *             is logged in or logged <code>User</code> is not authorized\r
         */\r
-       public boolean deleteReservation(Reservation reservation) throws Exception {\r
+       public boolean deleteReservation_Super(Reservation reservation) throws Exception {\r
                if (dh == null)\r
                        throw new Exception("No DataHandler set");\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
                if (reservation == null)\r
                        throw new IllegalArgumentException("Reservation must be defined");\r
-               if (!reservation.getUser().equals(currentUser))\r
-                       throw new Exception("You are not authorized to make this change");\r
                return dh.deleteReservation(reservation);\r
        }\r
-\r
-       /**\r
-        * Returns all stored resources of the set DataHandler\r
-        * @return <code>List</code> of resources\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> is set\r
-        */\r
-       public List<Resource> getResources() throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               List<Resource> resourceList = new ArrayList<Resource>();\r
-               for (Resource resource : dh.getAllResources()) {\r
-                       resourceList.add(resource.clone());\r
-               }\r
-               return resourceList;\r
-       }\r
 }\r
index 18ce351..201141c 100644 (file)
@@ -25,88 +25,10 @@ import ch.bfh.ti.srs.dataschema.User;
 /**\r
  * @author Michael Grossen\r
  */\r
-public class UserController {\r
-       private User currentUser;\r
-       private DataHandler dh;\r
+public class UserController extends Controller{\r
 \r
-       public UserController() {\r
-       }\r
-\r
-       /**\r
-        * Sets the <code>DataHandler</code> implementation for this Controller,\r
-        * must be set before using all other methods!\r
-        * @param dh\r
-        *            DataHandler implementation (i.e. DataHandlerForExcel)\r
-        */\r
-       public void setDataHandler(DataHandler dh) {\r
-               this.dh = dh;\r
-       }\r
-\r
-       /**\r
-        * Tries to log in a <code>User</code> with the given credentials\r
-        * @param userName\r
-        *            user name\r
-        * @param password\r
-        *            the stored password for the given user name\r
-        * @return <code>True</code> if the user could log in successfully,\r
-        *         <code>False</code> either the username or the password was not\r
-        *         correct.\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> set\r
-        * @throws AlreadyBoundException\r
-        *             a <code>User</code> is already logged in\r
-        */\r
-       public boolean logIn(String userName, String password) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (currentUser != null)\r
-                       throw new AlreadyBoundException("A user is already logged in");\r
-               User tempUser = dh.findUser(userName);\r
-               if (tempUser == null || !tempUser.checkPassword(password))\r
-                       return false;\r
-               else {\r
-                       currentUser = tempUser;\r
-                       return true;\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Logs out the current logged user\r
-        * @throws Exception\r
-        *             either no <code>DataHandler</code> is set or no user is\r
-        *             logged in\r
-        */\r
-       public void logOut() throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               currentUser = null;\r
-       }\r
-\r
-       /**\r
-        * Registers a new user to the current DataHandler\r
-        * @param userName\r
-        *            unique user name\r
-        * @param password\r
-        *            plain-text password\r
-        * @param email\r
-        *            e-mail address\r
-        * @param name\r
-        *            name\r
-        * @param lastname\r
-        *            last name\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> set\r
-        */\r
-       public void addUser(String userName, String password, String email, String name, String lastname) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               User newUser = new User(userName, password);\r
-               newUser.setMail(email);\r
-               newUser.setName(name);\r
-               newUser.setLastname(lastname);\r
-               dh.addUser(newUser);\r
+       public UserController(DataHandler dh) {\r
+               super(dh);\r
        }\r
 \r
        /**\r
@@ -191,52 +113,6 @@ public class UserController {
        }\r
 \r
        /**\r
-        * Returns all reservations overlapping the given dateRange in a\r
-        * <code>Map</code>\r
-        * @param dateRange\r
-        *            time span\r
-        * @return <code>Key</code> reservation, <code>Value</code> is editable\r
-        * @throws Exception\r
-        *             no <code>User</code> is logged in or no\r
-        *             <code>DataHandler</code> is set\r
-        */\r
-       public Map<Reservation, Boolean> getReservationsInDateRange(DateRange dateRange) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (dateRange == null)\r
-                       throw new Exception("dateRange must be defined");\r
-\r
-               // Could be swapped out to private method for better performance (just\r
-               // check currentUser once)\r
-               // and easier code maintenance\r
-               Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
-               for (Reservation reservation : dh.overlaps(dateRange)) {\r
-                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
-               }\r
-               return returnSet;\r
-       }\r
-\r
-       /**\r
-        * Returns the reservation or null if no reservation was found\r
-        * @param id\r
-        *            reservation identifier\r
-        * @return <code>Reservation</code> copy of reservation with given id,\r
-        *         <code>null</code> no reservation with this id found\r
-        * @throws Exception\r
-        *             No DataHandler set or id null\r
-        */\r
-       public Reservation getReservation(UUID id) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (id == null)\r
-                       throw new Exception("uuid must be defined");\r
-               if (dh.findReservation(id) == null)\r
-                       return null;\r
-               else\r
-                       return dh.findReservation(id).clone();\r
-       }\r
-\r
-       /**\r
         * Returns the reservations of the given user\r
         * @param user\r
         *            Owner, if <code>null</code> returns the reservations of the\r
@@ -247,96 +123,13 @@ public class UserController {
         *             logged in while user param = null\r
         */\r
        public Map<Reservation, Boolean> getUserReservations(User user) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
                if (user == null) {\r
                        if (currentUser == null)\r
                                throw new Exception("user must be defined, if no user is logged in");\r
                        else\r
                                user = currentUser;\r
                }\r
-\r
-               // Could be swapped out to private method for better performance (just\r
-               // check currentUser once)\r
-               // and easier code maintenance\r
-               Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
-               for (Reservation reservation : dh.userReservations(user)) {\r
-                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
-               }\r
-               return returnSet;\r
-       }\r
-\r
-       /**\r
-        * Returns <code>Map</code> of reservation group (recurring reservations)\r
-        * @param groupId\r
-        *            group identifier\r
-        * @return <code>Key</code> reservation, <code>Value</code> is editable\r
-        * @throws IllegalArgumentException\r
-        *             groupId is null\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> set\r
-        */\r
-       public Map<Reservation, Boolean> getReservationGroup(UUID groupId) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (groupId == null)\r
-                       throw new IllegalArgumentException("groupId has to be defined");\r
-\r
-               // Could be swapped out to private method for better performance (just\r
-               // check currentUser once)\r
-               // and easier code maintenance\r
-               Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
-               for (Reservation reservation : dh.findGroupReservations(groupId)) {\r
-                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
-               }\r
-               return returnSet;\r
-       }\r
-\r
-       /**\r
-        * Makes a reservation in the current set DataHandler\r
-        * @param user\r
-        *            user owning the reservation, if null currentUser is set\r
-        * @param resource\r
-        *            resource to reserve\r
-        * @param dateRangeList\r
-        *            <code>List</code> of DateRanges defining when the resource is\r
-        *            occupied\r
-        * @param remark\r
-        *            public remark for the reservation\r
-        * @return <code>Set</code> of Reservations that overlap an already stored\r
-        *         reservation (conflict), if not empty no reservation was saved\r
-        * @throws IllegalArgumentException\r
-        *             <code>resource</code> or <code>dateRangeList</code> is null,\r
-        *             or <code>dateRangeList</code> is empty\r
-        * @throws Exception\r
-        *             thrown by <code>DataHandler</code>\r
-        */\r
-       public Set<Reservation> makeReservation(User user, Resource resource, List<DateRange> dateRangeList, String remark)\r
-                       throws Exception {\r
-               if (user == null) {\r
-                       if (currentUser == null)\r
-                               throw new IllegalArgumentException("User must be defined if no user is logged in");\r
-                       user = currentUser;\r
-               }\r
-               if (resource == null)\r
-                       throw new IllegalArgumentException("Resource must be definded");\r
-               if (dateRangeList == null)\r
-                       throw new IllegalArgumentException("dateRangeList can not be null");\r
-               if (dateRangeList.isEmpty())\r
-                       throw new IllegalArgumentException("dateRangeList empty");\r
-\r
-               Set<Reservation> invalidReservations = new HashSet<Reservation>();\r
-               UUID groupId = UUID.randomUUID();\r
-               for (DateRange dateRange : dateRangeList) {\r
-                       Reservation reservation = new Reservation(groupId, user, resource, dateRange, remark);\r
-                       if (!dh.addReservation(reservation))\r
-                               invalidReservations.add(reservation);\r
-               }\r
-               if (invalidReservations.isEmpty()) {\r
-                       dh.saveChanges();\r
-                       return null;\r
-               } else\r
-                       return invalidReservations;\r
+               return super.getUserReservations_Super(user);\r
        }\r
 \r
        /**\r
@@ -353,15 +146,13 @@ public class UserController {
         *             not authorized\r
         */\r
        public boolean changeReservation(Reservation reservation) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
                if (currentUser == null)\r
                        throw new Exception("No user is logged in");\r
                if (reservation == null)\r
                        throw new IllegalArgumentException("Reservation must be defined");\r
-               if (!reservation.getUser().equals(currentUser))\r
+               if (!reservation.getUser().equals(super.currentUser))\r
                        throw new Exception("You are not authorized to make this change");\r
-               return dh.editReservation(reservation);\r
+               return super.changeReservation_Super(reservation);\r
        }\r
 \r
        /**\r
@@ -378,30 +169,13 @@ public class UserController {
         *             is logged in or logged <code>User</code> is not authorized\r
         */\r
        public boolean deleteReservation(Reservation reservation) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
                if (currentUser == null)\r
                        throw new Exception("No user is logged in");\r
                if (reservation == null)\r
                        throw new IllegalArgumentException("Reservation must be defined");\r
                if (!reservation.getUser().equals(currentUser))\r
                        throw new Exception("You are not authorized to make this change");\r
-               return dh.deleteReservation(reservation);\r
+               return super.deleteReservation_Super(reservation);\r
        }\r
 \r
-       /**\r
-        * Returns all stored resources of the set DataHandler\r
-        * @return <code>List</code> of resources\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> is set\r
-        */\r
-       public List<Resource> getResources() throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               List<Resource> resourceList = new ArrayList<Resource>();\r
-               for (Resource resource : dh.getAllResources()) {\r
-                       resourceList.add(resource.clone());\r
-               }\r
-               return resourceList;\r
-       }\r
 }\r
index 5b06f2a..0a29a09 100644 (file)
@@ -40,9 +40,9 @@ public class UserControllerTest {
        @Test\r
        public void addUserTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
@@ -52,7 +52,8 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void addUserExceptionTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
 \r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
        }\r
@@ -60,9 +61,9 @@ public class UserControllerTest {
        @Test\r
        public void logInTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
@@ -74,16 +75,17 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void logInException1Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
                uc.logIn("TestUser3", "pass3");\r
        }\r
 \r
        @Test(expected = Exception.class)\r
        public void logInException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
 \r
@@ -94,9 +96,9 @@ public class UserControllerTest {
        @Test\r
        public void logInInvalidCredetialsTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
 \r
@@ -108,9 +110,9 @@ public class UserControllerTest {
        @Test\r
        public void getLoggedUserNameTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
@@ -122,16 +124,18 @@ public class UserControllerTest {
 \r
        @Test(expected = Exception.class)\r
        public void getLoggedUserNameExceptionTest() throws Exception {\r
-               UserController uc = new UserController();\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
                String currentUserName = uc.getLoggedUserName();\r
        }\r
 \r
        @Test\r
        public void getLoggedUserMailTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "hanfli@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
@@ -143,16 +147,18 @@ public class UserControllerTest {
 \r
        @Test(expected = Exception.class)\r
        public void getLoggedMailExceptionTest() throws Exception {\r
-               UserController uc = new UserController();\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
                String currentMail = uc.getLoggedMail();\r
        }\r
 \r
        @Test\r
        public void getLoggedNameTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Hanfli", null);\r
@@ -164,16 +170,18 @@ public class UserControllerTest {
 \r
        @Test(expected = Exception.class)\r
        public void getLoggedNameExceptionTest() throws Exception {\r
-               UserController uc = new UserController();\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
                uc.getLoggedName();\r
        }\r
 \r
        @Test\r
        public void getLoggedLastnameTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
@@ -185,16 +193,18 @@ public class UserControllerTest {
 \r
        @Test(expected = Exception.class)\r
        public void getLoggedLastnameExceptionTest() throws Exception {\r
-               UserController uc = new UserController();\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
                String currentLastName = uc.getLoggedLastname();\r
        }\r
 \r
        @Test\r
        public void getLoggedUserTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                assertEquals(null, uc.getLoggedUser());\r
                uc.logIn("TestUser1", "pass1");\r
@@ -204,7 +214,7 @@ public class UserControllerTest {
        // @Test(expected=Exception.class)\r
        // public void getLoggedUserExceptionTest() throws Exception{\r
        // DataHandler dh = new DataHandlerForTests();\r
-       // UserController uc = new UserController();\r
+       // UserController uc = new UserController(dh);\r
        //\r
        // uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
        // uc.logIn("TestUser1", "pass1");\r
@@ -214,9 +224,9 @@ public class UserControllerTest {
        @Test\r
        public void getUserTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
                assertEquals("grosm9@bfh.ch", uc.getUser("TestUser1").getMail());\r
@@ -225,7 +235,8 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void getUserExceptionTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
 \r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -235,9 +246,9 @@ public class UserControllerTest {
        @Test\r
        public void logOutTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
@@ -251,7 +262,8 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void logOutException1Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
 \r
                uc.logOut();\r
        }\r
@@ -259,23 +271,25 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void logOutException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
 \r
-               uc.setDataHandler(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.logOut();\r
        }\r
 \r
        @Test(expected = Exception.class)\r
        public void getUserExpectionTest() throws Exception {\r
-               UserController uc = new UserController();\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
                uc.getUser(null);\r
        }\r
 \r
        @Test\r
        public void getReservationTests() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -330,65 +344,70 @@ public class UserControllerTest {
 \r
        @Test(expected = Exception.class)\r
        public void getReservationGroupException1Test() throws Exception {\r
-               UserController uc = new UserController();\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
                uc.getReservationGroup(null);\r
        }\r
 \r
        @Test(expected = IllegalArgumentException.class)\r
        public void getReservationGroupException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.getReservationGroup(null);\r
        }\r
 \r
        @Test(expected = Exception.class)\r
        public void getUserReservationException1Test() throws Exception {\r
-               UserController uc = new UserController();\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
                uc.getUserReservations(null);\r
        }\r
 \r
        @Test(expected = Exception.class)\r
        public void getUserReservationException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.getUserReservations(null);\r
        }\r
 \r
        @Test(expected = Exception.class)\r
        public void getReservationException1Test() throws Exception {\r
-               UserController uc = new UserController();\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
                uc.getReservation(null);\r
        }\r
 \r
        @Test(expected = Exception.class)\r
        public void getReservationException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.getReservation(null);\r
        }\r
 \r
        @Test(expected = Exception.class)\r
        public void getReservationsInDateRangeException1Test() throws Exception {\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(null);\r
                uc.getReservationsInDateRange(null);\r
        }\r
 \r
        @Test(expected = Exception.class)\r
        public void getReservationsInDateRangeException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.getReservationsInDateRange(null);\r
        }\r
 \r
        @Test\r
        public void makeReservationTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -412,8 +431,8 @@ public class UserControllerTest {
        @Test\r
        public void makeInvalidReservationTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -448,8 +467,8 @@ public class UserControllerTest {
        @Test(expected = IllegalArgumentException.class)\r
        public void makeReservationException1Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -473,8 +492,8 @@ public class UserControllerTest {
        @Test(expected = IllegalArgumentException.class)\r
        public void makeReservationException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -497,8 +516,8 @@ public class UserControllerTest {
        @Test(expected = IllegalArgumentException.class)\r
        public void makeReservationException3Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -521,8 +540,8 @@ public class UserControllerTest {
        @Test(expected = IllegalArgumentException.class)\r
        public void makeReservationException4Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -542,8 +561,8 @@ public class UserControllerTest {
        @Test\r
        public void changeReservationTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -573,8 +592,8 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void changeReservationException1Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -611,8 +630,8 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void changeReservationException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -649,8 +668,8 @@ public class UserControllerTest {
        @Test(expected = IllegalArgumentException.class)\r
        public void changeReservationException3Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -686,8 +705,8 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void changeReservationException4Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -725,8 +744,8 @@ public class UserControllerTest {
        @Test\r
        public void deleteReservationTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -756,8 +775,8 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void deleteReservationException1Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -788,8 +807,8 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void deleteReservationException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -820,8 +839,8 @@ public class UserControllerTest {
        @Test(expected = IllegalArgumentException.class)\r
        public void deleteReservationException3Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -851,8 +870,8 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void deleteReservationException4Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -884,8 +903,8 @@ public class UserControllerTest {
        @Test\r
        public void getResourcesTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
@@ -910,8 +929,8 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void getResourcesExceptionTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r