Added isModified method to Resource, Reservation.
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / dataschema / ResourceTest.java
1 /*
2 * Copyright (c) 2015 Berner Fachhochschule, Switzerland.
3 *
4 * Project Smart Reservation System.
5 *
6 * Distributable under GPL license. See terms of license at gnu.org.
7 */
8 package ch.bfh.ti.srs.dataschema;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotEquals;
13 import static org.junit.Assert.assertTrue;
14
15 import org.junit.Test;
16
17 import ch.bfh.ti.srs.dataschema.Resource;
18
19 public class ResourceTest {
20
21 @Test
22 public void createResurceTest() throws Exception {
23 Resource testResource = new Resource("N321", "class room");
24 assertNotEquals(null, testResource.getId());
25 assertEquals("N321", testResource.getName());
26 assertEquals("class room", testResource.getType());
27 }
28
29 @Test(expected = IllegalArgumentException.class)
30 public void createUserInvalidNameTest() throws Exception {
31 Resource testResource = new Resource(null, "class room");
32 }
33
34 @Test
35 public void setAndGetNameTest() throws Exception {
36 Resource testRessource = new Resource("N321", "class room");
37 testRessource.setName("N421");
38 assertEquals("N421", testRessource.getName());
39 testRessource.setName(null);
40 assertEquals(null, testRessource.getName());
41 }
42
43 @Test
44 public void setAndGetTypeTest() throws Exception {
45 Resource testRessource = new Resource("N321", "class room");
46 testRessource.setType("lecture hall");
47 assertEquals("lecture hall", testRessource.getType());
48 testRessource.setType(null);
49 assertEquals(null, testRessource.getType());
50 }
51
52 @Test
53 public void isModifiedTest() throws Exception {
54 Resource testRessource = new Resource("N321", "class room");
55 Resource clonedTestRessource = testRessource.clone();
56
57 assertFalse(testRessource.isModified(clonedTestRessource));
58 assertTrue(testRessource.isModified(null));
59 assertFalse(testRessource.isModified(testRessource));
60 clonedTestRessource.setName("N421");
61 assertTrue(testRessource.isModified(clonedTestRessource));
62 clonedTestRessource.setName("N321");
63 assertFalse(testRessource.isModified(clonedTestRessource));
64 clonedTestRessource.setType("lecture hall");
65 assertTrue(testRessource.isModified(clonedTestRessource));
66 }
67 }
68