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