Added isModified method to Resource, Reservation.
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / dataschema / ReservationTest.java
index c4c7a39..bfd3093 100644 (file)
@@ -8,7 +8,9 @@
 package ch.bfh.ti.srs.dataschema;\r
 \r
 import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
 import static org.junit.Assert.assertNotEquals;\r
+import static org.junit.Assert.assertTrue;\r
 \r
 import java.util.UUID;\r
 \r
@@ -51,6 +53,22 @@ public class ReservationTest {
                assertEquals("TestReservation", testReservation.getRemark());\r
        }\r
 \r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void createReservationInvalidUserTest() throws Exception {\r
+               Resource testResource = new Resource("N321", "class room");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
+                               DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), null, testResource, testDr, "TestReservation");\r
+       }\r
+\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void createReservationInvalidResourceTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
+                               DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, null, testDr, "TestReservation");\r
+       }\r
+\r
        @Test\r
        public void setAndGetNameTest() throws Exception {\r
                User testUser = new User("TestUser", "pass");\r
@@ -87,9 +105,9 @@ public class ReservationTest {
                Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
                                "TestReservation");\r
 \r
-               Resource OtherTestResource = new Resource("N421", "lecture hall");\r
-               testReservation.setResource(OtherTestResource);\r
-               assertEquals(OtherTestResource, testReservation.getResource());\r
+               Resource otherTestResource = new Resource("N421", "lecture hall");\r
+               testReservation.setResource(otherTestResource);\r
+               assertEquals(otherTestResource, testReservation.getResource());\r
        }\r
 \r
        @Test\r
@@ -106,4 +124,44 @@ public class ReservationTest {
                testReservation.setDateRange(otherTestDr);\r
                assertEquals(otherTestDr, testReservation.getDateRange());\r
        }\r
+\r
+       @Test\r
+       public void isModifiedTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               Resource testResource = new Resource("N321", "class room");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
+                               DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
+                               "TestReservation");\r
+               Reservation clonedTestReservation = testReservation.clone();\r
+               \r
+               assertTrue(testReservation.isModified(null));\r
+               assertFalse(testReservation.isModified(testReservation));\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+               \r
+               User otherTestUser = new User("otherTestUser", "pass");\r
+               clonedTestReservation.setUser(otherTestUser);\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+               \r
+               clonedTestReservation.setUser(testUser);\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+\r
+               Resource otherTestResource = new Resource("N421", "lecture hall");\r
+               clonedTestReservation.setResource(otherTestResource);\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+               \r
+               clonedTestReservation.setResource(testResource);\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+               \r
+               DateRange otherTestDr = factory.createDateRange(DateFactory.createDate(2015, 12, 9),\r
+                               DateFactory.createDate(2015, 12, 13));\r
+               clonedTestReservation.setDateRange(otherTestDr);\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+               \r
+               clonedTestReservation.setDateRange(testDr);\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+               \r
+               clonedTestReservation.setRemark("some other remark");\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+       }\r
 }\r