364ec845bca4628eb035dfcd7eea4afd420cc578
[WeStealzYourDataz.git] / test / uk / ac / ntu / n0521366 / wsyd / libs / WSYD_MemberTest.java
1 /*
2  * The MIT License
3  *
4  * Copyright 2015 Eddie Berrisford-Lynch <n0521366@ntu.ac.uk>.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 package uk.ac.ntu.n0521366.wsyd.libs;
25
26 import org.junit.After;
27 import org.junit.AfterClass;
28 import org.junit.Before;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import static org.junit.Assert.*;
32
33 import java.text.SimpleDateFormat;
34 import java.util.Date;
35 import java.util.TreeSet;
36
37 /**
38  *
39  * @author TJ <hacker@iam.tj>
40  */
41 public class WSYD_MemberTest {
42     public WSYD_Member instance;
43     public String importCSV;
44     
45     public WSYD_MemberTest() {
46     }
47     
48     @BeforeClass
49     public static void setUpClass() {
50     }
51     
52     @AfterClass
53     public static void tearDownClass() {
54     }
55     
56     @Before
57     public void setUp() throws java.text.ParseException {
58         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
59         Date birthDate = df.parse("1993-04-05");
60         TreeSet<String> interests = new TreeSet<>();
61         TreeSet<Long> friends = new TreeSet<>();
62         TreeSet<Long> friendsRequestsSent = new TreeSet<>();
63         TreeSet<Long> friendsRequestsReceived = new TreeSet<>();
64         interests.add("Computers");
65         interests.add("Games");
66         interests.add("Gym");
67         interests.add("Music");
68         friends.add(new Long(1));
69         friends.add(new Long(5));
70         friendsRequestsSent.add(new Long(0));
71         friendsRequestsReceived.add(new Long(3));
72         
73         instance = new WSYD_Member(2, "Eddie", "letmein", "Nottingham", "Be glad when exams are over", birthDate, interests, friends, friendsRequestsSent, friendsRequestsReceived);
74         importCSV = "2,Eddie,letmein,Nottingham,Be glad when exams are over,1993-04-05,Computers~Games~Gym~Music,1~5,0,3";
75     }
76     
77     @After
78     public void tearDown() {
79     }
80
81     @Test
82     public void testCompareTo() {
83         System.out.println(java.text.MessageFormat.format("{0}.compareTo(value)", instance.getClass().getName()));
84         WSYD_Member b = new WSYD_Member();
85         WSYD_Member e = new WSYD_Member();
86         WSYD_Member h = new WSYD_Member();
87         WSYD_Member f = new WSYD_Member();
88         b._userName = "Below";
89         e._userName = "Eddie";
90         h._userName = "Higher";
91         f._userName = "Fit";
92         assertEquals(3, instance.compareTo(b)); // String.compareTo() returns the 'distance' between the letters
93         assertEquals(0, instance.compareTo(e));
94         assertEquals(-3, instance.compareTo(h));
95         assertEquals(-1, instance.compareTo(f));
96         
97     }
98     
99     @Test (expected=IllegalArgumentException.class)
100     public void testCompareToIAE() throws IllegalArgumentException {
101         System.out.println(java.text.MessageFormat.format("{0}.compareTo(null)", instance.getClass().getName()));
102         instance.compareTo(null);
103     }
104
105     @Test
106     public void testToString() {
107         System.out.println(java.text.MessageFormat.format("{0}.toString()", instance.getClass().getName()));
108         assertEquals("2,Eddie,letmein,Nottingham,Be glad when exams are over,1993-04-05,Computers~Games~Gym~Music,1~5,0,3", instance.toString());
109     }
110
111     @Test (expected=IllegalArgumentException.class)
112     public void testCreateWSYD_MemberIAE() throws IllegalArgumentException {
113         System.out.println(java.text.MessageFormat.format("{0}.createWSYD_Member(IllegalArgumentException)", instance.getClass().getName()));
114         WSYD_Member.createWSYD_Member("too many arguments," + importCSV);
115     }
116     
117     @Test
118     public void testCreateWSYD_Member() {
119         System.out.println(java.text.MessageFormat.format("{0}.createWSYD_Member(String)", instance.getClass().getName()));
120         assertEquals(instance.toString(), WSYD_Member.createWSYD_Member(importCSV).toString());
121     }
122 }