1 | package geniusweb.deadline;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.util.Arrays;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import org.junit.Test;
|
---|
10 |
|
---|
11 | import com.fasterxml.jackson.core.JsonParseException;
|
---|
12 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
13 | import com.fasterxml.jackson.databind.JsonMappingException;
|
---|
14 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
15 |
|
---|
16 | import tudelft.utilities.junit.GeneralTests;
|
---|
17 |
|
---|
18 | public class DeadlineTest extends GeneralTests<Deadline> {
|
---|
19 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
20 | private final String deadlinestring = "{\"deadlinerounds\":{\"rounds\":100,\"durationms\":999}}";
|
---|
21 | private final DeadlineRounds deadlineRounds = new DeadlineRounds(100, 999);
|
---|
22 | private final DeadlineRounds deadlineRounds1 = new DeadlineRounds(100, 999);
|
---|
23 | private final DeadlineRounds deadlineRounds2 = new DeadlineRounds(100,
|
---|
24 | 9999);
|
---|
25 | private final String deadlinetimestring = "{\"deadlinetime\":{\"durationms\":2000}}";
|
---|
26 | private final DeadlineTime deadlineTime = new DeadlineTime(2000);
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public List<List<Deadline>> getGeneralTestData() {
|
---|
30 | return Arrays.asList(Arrays.asList(deadlineRounds, deadlineRounds1),
|
---|
31 | Arrays.asList(deadlineRounds2), Arrays.asList(deadlineTime));
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public List<String> getGeneralTestStrings() {
|
---|
36 | return Arrays.asList("DeadlineRounds\\[100,999\\]",
|
---|
37 | "DeadlineRounds\\[100,9999\\]", "DeadlineTime\\[2000\\]");
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Test
|
---|
41 | public void serializeRoundsTest() throws JsonProcessingException {
|
---|
42 | String text = jackson.writeValueAsString(deadlineRounds);
|
---|
43 | assertEquals(deadlinestring, text);
|
---|
44 |
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Test
|
---|
48 | public void DeserializeRoundsTest()
|
---|
49 | throws JsonParseException, JsonMappingException, IOException {
|
---|
50 | assertEquals(deadlineRounds,
|
---|
51 | jackson.readValue(deadlinestring, Deadline.class));
|
---|
52 |
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Test
|
---|
56 | public void serializeTimeTest() throws JsonProcessingException {
|
---|
57 | String text = jackson.writeValueAsString(deadlineTime);
|
---|
58 | assertEquals(deadlinetimestring, text);
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Test
|
---|
63 | public void deserializeTimeTest()
|
---|
64 | throws JsonParseException, JsonMappingException, IOException {
|
---|
65 | assertEquals(deadlineTime,
|
---|
66 | jackson.readValue(deadlinetimestring, Deadline.class));
|
---|
67 |
|
---|
68 | }
|
---|
69 |
|
---|
70 | @SuppressWarnings("unused")
|
---|
71 | @Test(expected = IllegalArgumentException.class)
|
---|
72 | public void testIllegalArg() {
|
---|
73 | new DeadlineRounds(-1, 999);
|
---|
74 | }
|
---|
75 |
|
---|
76 | @SuppressWarnings("unused")
|
---|
77 | @Test(expected = IllegalArgumentException.class)
|
---|
78 | public void testIllegalArg2() {
|
---|
79 | new DeadlineTime(-1);
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Test
|
---|
83 | public void getRounds() {
|
---|
84 | assertEquals((Integer) 11, new DeadlineRounds(11, 20).getRounds());
|
---|
85 | }
|
---|
86 |
|
---|
87 | }
|
---|