1 | package geniusweb.party.inform;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.net.URISyntaxException;
|
---|
7 | import java.util.Arrays;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import org.junit.Before;
|
---|
11 | import org.junit.Test;
|
---|
12 |
|
---|
13 | import com.fasterxml.jackson.core.JsonParseException;
|
---|
14 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
15 | import com.fasterxml.jackson.databind.JsonMappingException;
|
---|
16 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
17 |
|
---|
18 | import geniusweb.inform.Inform;
|
---|
19 | import geniusweb.inform.YourTurn;
|
---|
20 | import tudelft.utilities.junit.GeneralTests;
|
---|
21 |
|
---|
22 | public class YourTurnTest extends GeneralTests<YourTurn> {
|
---|
23 |
|
---|
24 | private YourTurn yourturn1, yourturn1b;
|
---|
25 |
|
---|
26 | private String asJson = "{\"YourTurn\":{}}";
|
---|
27 |
|
---|
28 | private YourTurn yourturnb;
|
---|
29 |
|
---|
30 | @Before
|
---|
31 | public void before() throws URISyntaxException {
|
---|
32 |
|
---|
33 | yourturn1 = new YourTurn();
|
---|
34 | yourturn1b = new YourTurn();
|
---|
35 | yourturnb = new YourTurn() {
|
---|
36 | @Override
|
---|
37 | public int hashCode() {
|
---|
38 | return 2;
|
---|
39 | }
|
---|
40 | };
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | public List<List<YourTurn>> getGeneralTestData() {
|
---|
45 | return Arrays.asList(Arrays.asList(yourturn1, yourturn1b),
|
---|
46 | Arrays.asList(yourturnb));
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public List<String> getGeneralTestStrings() {
|
---|
51 | return Arrays.asList("YourTurn*", "YourTurn*");
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Test
|
---|
55 | public void testSerialize() throws JsonProcessingException {
|
---|
56 | ObjectMapper jackson = new ObjectMapper();
|
---|
57 |
|
---|
58 | String json = jackson.writeValueAsString(yourturn1);
|
---|
59 | System.out.println(json);
|
---|
60 | assertEquals(asJson, json);
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Test
|
---|
64 | public void testDeserialize()
|
---|
65 | throws JsonParseException, JsonMappingException, IOException {
|
---|
66 | ObjectMapper jackson = new ObjectMapper();
|
---|
67 | YourTurn p = (YourTurn) jackson.readValue(asJson, Inform.class);
|
---|
68 | System.out.println(p);
|
---|
69 | assertEquals(yourturn1, p);
|
---|
70 | }
|
---|
71 |
|
---|
72 | }
|
---|