1 | package geniusweb.events;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.util.Arrays;
|
---|
7 | import java.util.LinkedList;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import org.junit.Test;
|
---|
11 |
|
---|
12 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
13 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
14 |
|
---|
15 | import tudelft.utilities.junit.GeneralTests;
|
---|
16 |
|
---|
17 | public class TournamentStartedTest extends GeneralTests<TournamentStarted> {
|
---|
18 |
|
---|
19 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
20 |
|
---|
21 | private static final Long SESSIONNR = 1l;
|
---|
22 | protected static final Long NOW = (long) 101;
|
---|
23 | protected static final Long NOW1 = NOW + 1;
|
---|
24 | private static final Long NSESSIONS = 5l;
|
---|
25 |
|
---|
26 | private static TournamentStarted tournamentStarted = new TournamentStarted(
|
---|
27 | NSESSIONS, NOW);
|
---|
28 | private static TournamentStarted tournamentStarteda = new TournamentStarted(
|
---|
29 | NSESSIONS, NOW);
|
---|
30 | private TournamentStarted otherTournamentStarted = new TournamentStarted(
|
---|
31 | NSESSIONS + 1, NOW);
|
---|
32 | private TournamentStarted tournamentStartedLater = new TournamentStarted(
|
---|
33 | NSESSIONS, NOW1);
|
---|
34 |
|
---|
35 | private String tournamentstartedstring = "{\"TournamentStarted\":{\"time\":101,\"numberOfSessions\":5}}";
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public List<List<TournamentStarted>> getGeneralTestData() {
|
---|
39 | List<List<TournamentStarted>> list = new LinkedList<>();
|
---|
40 | list.add(Arrays.asList(tournamentStarted, tournamentStarteda));
|
---|
41 | list.add(Arrays.asList(otherTournamentStarted));
|
---|
42 | list.add(Arrays.asList(tournamentStartedLater));
|
---|
43 | return list;
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public List<String> getGeneralTestStrings() {
|
---|
48 | return Arrays.asList(
|
---|
49 | "TournamentStarted\\[.*" + NOW + ".*" + NSESSIONS + ".*\\]",
|
---|
50 | "TournamentStarted\\[.*" + NOW + ".*" + (NSESSIONS + 1)
|
---|
51 | + ".*\\]",
|
---|
52 | "TournamentStarted\\[.*" + NOW1 + ".*" + NSESSIONS + ".*\\]");
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Test
|
---|
56 | public void serializeTournamentStartedTest()
|
---|
57 | throws JsonProcessingException {
|
---|
58 | System.out.println(jackson.writeValueAsString(tournamentStarted));
|
---|
59 | assertEquals(tournamentstartedstring,
|
---|
60 | jackson.writeValueAsString(tournamentStarted));
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Test
|
---|
64 | public void deserializeTournamentStartedTest() throws IOException {
|
---|
65 | NegotiationEvent evt = jackson.readValue(tournamentstartedstring,
|
---|
66 | NegotiationEvent.class);
|
---|
67 | assertEquals(TournamentStarted.class, evt.getClass());
|
---|
68 | TournamentStarted event = (TournamentStarted) evt;
|
---|
69 | // compare fields, as sessionended is a derived/new inner class
|
---|
70 | assertEquals(NSESSIONS, event.getNumberOfSessions());
|
---|
71 | assertEquals(NOW, event.getTime());
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Test(expected = IllegalArgumentException.class)
|
---|
75 | public void testNullTime() {
|
---|
76 | new TournamentStarted(NSESSIONS, null);
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Test(expected = IllegalArgumentException.class)
|
---|
80 | public void testNegativeTime() {
|
---|
81 | new TournamentStarted(NSESSIONS, -1l);
|
---|
82 | }
|
---|
83 |
|
---|
84 | }
|
---|