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

Last change on this file since 53 was 52, checked in by ruud, 22 months ago

Fixed small issues in domaineditor.

File size: 2.5 KB
RevLine 
[52]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 tudelft.utilities.junit.GeneralTests;
17
18public 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}
Note: See TracBrowser for help on using the repository browser.