DataHandlerForTestsTest updated
authorMichael <Michael@Michael-LT.fritz.box>
Sat, 9 Jan 2016 19:31:02 +0000 (20:31 +0100)
committerMichael <Michael@Michael-LT.fritz.box>
Sat, 9 Jan 2016 19:31:02 +0000 (20:31 +0100)
src/main/java/ch/bfh/ti/srs/datahandler/DataHandlerForTests.java
src/test/java/ch/bfh/ti/srs/controller/UserControllerTest.java
src/test/java/ch/bfh/ti/srs/datahandler/DataHandlerForTestsTest.java

index 7c76508..39d8897 100644 (file)
@@ -272,8 +272,8 @@ public class DataHandlerForTests implements DataHandler {
                if (user == null) {
                        throw new IllegalArgumentException("User object must not be null!");
                }
                if (user == null) {
                        throw new IllegalArgumentException("User object must not be null!");
                }
-               if (findUser(user.getName()) != null) {
-                       userList.remove(findUser(user.getName()));
+               if (findUser(user.getUserName()) != null) {
+                       userList.remove(findUser(user.getUserName()));
                        userList.add(user);
                        return true;
                }
                        userList.add(user);
                        return true;
                }
index 02ee9f4..0d14dab 100644 (file)
@@ -134,9 +134,11 @@ public class UserControllerTest {
                Reservation reservation2 = new Reservation(groupId, sc.getLoggedUser(), resource2, dateRange,\r
                                "Test reservation2");\r
                Reservation reservation3 = new Reservation(groupId, testUser2, resource3, dateRange, "Test reservation3");\r
                Reservation reservation2 = new Reservation(groupId, sc.getLoggedUser(), resource2, dateRange,\r
                                "Test reservation2");\r
                Reservation reservation3 = new Reservation(groupId, testUser2, resource3, dateRange, "Test reservation3");\r
+               Reservation reservation4 = new Reservation(UUID.randomUUID(), testUser2, resource3, dateRange, "Test reservation3");\r
                dh.addReservation(reservation1);\r
                dh.addReservation(reservation2);\r
                dh.addReservation(reservation3);\r
                dh.addReservation(reservation1);\r
                dh.addReservation(reservation2);\r
                dh.addReservation(reservation3);\r
+               dh.addReservation(reservation4);\r
 \r
                Map<Reservation, Boolean> loggedUserReservation = uc.getUserReservations(null);\r
                Map<Reservation, Boolean> reservationMap = uc.getUserReservations(testUser2);\r
 \r
                Map<Reservation, Boolean> loggedUserReservation = uc.getUserReservations(null);\r
                Map<Reservation, Boolean> reservationMap = uc.getUserReservations(testUser2);\r
index bb3737c..bfdb9f2 100644 (file)
@@ -8,6 +8,8 @@
 package ch.bfh.ti.srs.datahandler;
 
 import static org.junit.Assert.assertEquals;
 package ch.bfh.ti.srs.datahandler;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
 import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
@@ -308,4 +310,71 @@ public class DataHandlerForTestsTest {
 
                assertEquals(3, allReservations.size());
        }
 
                assertEquals(3, allReservations.size());
        }
+       
+       @Test
+       public void editUserTest() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+               dh.addUser(new User("TestUser1","pass1"));
+               assertTrue(dh.editUser(new User("TestUser1","pass1")));
+       }
+
+       @Test(expected = IllegalArgumentException.class)
+       public void editUserException1Test() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+               
+               dh.editUser(null);
+       }
+       
+       @Test
+       public void editUserException2Test() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+               dh.addUser(new User("TestUser1","pass1"));
+               assertFalse(dh.editUser(new User("TestUser2","pass1")));
+       }
+       
+       @Test
+       public void deleteResourceTest() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+               
+               Resource res = new Resource("Room1", "Testroom");
+               dh.addResource(res);
+               dh.deleteResource(res);
+       }
+       
+       @Test(expected = IllegalArgumentException.class)
+       public void deleteResourceExceptionTest() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+               
+               dh.deleteResource(null);
+       }
+
+       @Test
+       public void deleteResourceException1Test() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+               
+               dh.deleteResource(new Resource("Room1", "Testroom"));
+       }
+
+       @Test
+       public void editResourceTest() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+               
+               Resource res = new Resource("Room1", "Testroom");
+               dh.addResource(res);
+               dh.editResource(res);
+       }
+       
+       @Test(expected = IllegalArgumentException.class)
+       public void editResourceExceptionTest() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+               
+               dh.editResource(null);
+       }
+
+       @Test
+       public void editResourceException1Test() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+               
+               dh.editResource(new Resource("Room1", "Testroom"));
+       }
 }
 }