6da25b1db0e686e0fb893a2d6fc50f95e6cb4aa1
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / datahandler / DataHandlerForTestsTest.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.datahandler;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.fail;
12
13 import org.junit.Test;
14
15 import ch.bfh.ti.srs.core.User;
16 import ch.bfh.ti.srs.datahandler.DataHandler;
17 import ch.bfh.ti.srs.datahandler.DataHandlerForTests;
18
19 /**
20 * @author Michael Grossen
21 */
22 public class DataHandlerForTestsTest {
23
24 @Test
25 public void addUserTest() throws Exception{
26 DataHandler dh = new DataHandlerForTests();
27 User testUser = null;
28 try {
29 testUser = new User("TestUser", "pass");
30 } catch (Exception e) {
31 fail("Check UserTest (Exception was thrown by User Cunstructor)!");
32 }
33 dh.addUser(testUser);
34 }
35
36 @Test(expected=IllegalArgumentException.class)
37 public void addIllegalUserTest() throws Exception{
38 DataHandler dh = new DataHandlerForTests();
39 User testUser = null;
40 dh.addUser(testUser);
41 }
42
43 @Test
44 public void findUserTest() throws Exception{
45 DataHandler dh = new DataHandlerForTests();
46 User addedUser = new User("TestUser", "pass");
47 dh.addUser(addedUser);
48 User foundUser = dh.findUser("TestUser");
49 assertEquals(addedUser.getUserName(), foundUser.getUserName());
50 }
51
52 @Test
53 public void findNotAddedUser() throws Exception{
54 DataHandler dh = new DataHandlerForTests();
55 assertEquals(null, dh.findUser("notAddedUser"));
56 User addedUser = new User("TestUser", "pass");
57 dh.addUser(addedUser);
58 assertEquals(null, dh.findUser("otherUser"));
59 }
60
61 }