source: timeline/src/test/java/geniusweb/deadline/DeadlineTest.java@ 21

Last change on this file since 21 was 1, checked in by bart, 5 years ago

Initial Release

File size: 2.5 KB
Line 
1package geniusweb.deadline;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.util.Arrays;
7import java.util.List;
8
9import org.junit.Test;
10
11import com.fasterxml.jackson.core.JsonParseException;
12import com.fasterxml.jackson.core.JsonProcessingException;
13import com.fasterxml.jackson.databind.JsonMappingException;
14import com.fasterxml.jackson.databind.ObjectMapper;
15
16import geniusweb.deadline.Deadline;
17import geniusweb.deadline.DeadlineRounds;
18import geniusweb.deadline.DeadlineTime;
19import tudelft.utilities.junit.GeneralTests;
20
21public 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}
Note: See TracBrowser for help on using the repository browser.