1 | package geniusweb.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 tudelft.utilities.junit.GeneralTests;
|
---|
19 |
|
---|
20 | public class YourTurnTest extends GeneralTests<YourTurn> {
|
---|
21 |
|
---|
22 | private YourTurn yourturn1, yourturn1b;
|
---|
23 |
|
---|
24 | private String asJson = "{\"YourTurn\":{}}";
|
---|
25 |
|
---|
26 | private YourTurn yourturnb;
|
---|
27 |
|
---|
28 | @Before
|
---|
29 | public void before() throws URISyntaxException {
|
---|
30 |
|
---|
31 | yourturn1 = new YourTurn();
|
---|
32 | yourturn1b = new YourTurn();
|
---|
33 | yourturnb = new YourTurn() {
|
---|
34 | @Override
|
---|
35 | public int hashCode() {
|
---|
36 | return 2;
|
---|
37 | }
|
---|
38 | };
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public List<List<YourTurn>> getGeneralTestData() {
|
---|
43 | return Arrays.asList(Arrays.asList(yourturn1, yourturn1b),
|
---|
44 | Arrays.asList(yourturnb));
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public List<String> getGeneralTestStrings() {
|
---|
49 | return Arrays.asList("YourTurn*", "YourTurn*");
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Test
|
---|
53 | public void testSerialize() throws JsonProcessingException {
|
---|
54 | ObjectMapper jackson = new ObjectMapper();
|
---|
55 |
|
---|
56 | String json = jackson.writeValueAsString(yourturn1);
|
---|
57 | System.out.println(json);
|
---|
58 | assertEquals(asJson, json);
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Test
|
---|
62 | public void testDeserialize()
|
---|
63 | throws JsonParseException, JsonMappingException, IOException {
|
---|
64 | ObjectMapper jackson = new ObjectMapper();
|
---|
65 | YourTurn p = (YourTurn) jackson.readValue(asJson, Inform.class);
|
---|
66 | System.out.println(p);
|
---|
67 | assertEquals(yourturn1, p);
|
---|
68 | }
|
---|
69 |
|
---|
70 | }
|
---|