source: events/src/test/java/actions/PartyIdTest1.java@ 13

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

Initial Release

File size: 1.9 KB
Line 
1package actions;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.net.URISyntaxException;
7import java.util.Arrays;
8import java.util.List;
9
10import org.junit.Before;
11import org.junit.Test;
12
13import com.fasterxml.jackson.core.JsonParseException;
14import com.fasterxml.jackson.core.JsonProcessingException;
15import com.fasterxml.jackson.databind.JsonMappingException;
16import com.fasterxml.jackson.databind.ObjectMapper;
17
18import geniusweb.actions.PartyId;
19import tudelft.utilities.junit.GeneralTests;
20
21public class PartyIdTest1 extends GeneralTests<PartyId> {
22
23 private PartyId party1, party1a, party2, party3;
24 private String asJson = "\"party1\"";
25
26 @Before
27 public void before() throws URISyntaxException {
28 party1 = new PartyId("party1");
29 party1a = new PartyId("party1");
30 party2 = new PartyId("party2");
31 party3 = new PartyId("party3");
32 }
33
34 @Override
35 public List<List<PartyId>> getGeneralTestData() {
36 return Arrays.asList(Arrays.asList(party1, party1a),
37 Arrays.asList(party2), Arrays.asList(party3));
38 }
39
40 @Override
41 public List<String> getGeneralTestStrings() {
42 return Arrays.asList("party1", "party2", "party3");
43 }
44
45 @Test(expected = IllegalArgumentException.class)
46 public void smokeTest() throws URISyntaxException {
47 new PartyId("*Csh789&@#^!^@^&");
48 }
49
50 @Test(expected = IllegalArgumentException.class)
51 public void nullTest() throws URISyntaxException {
52 new PartyId(null);
53 }
54
55 @Test
56 public void testSerialize() throws JsonProcessingException {
57 ObjectMapper jackson = new ObjectMapper();
58
59 String json = jackson.writeValueAsString(party1);
60 System.out.println(json);
61 assertEquals(asJson, json);
62 }
63
64 @Test
65 public void testDeserialize()
66 throws JsonParseException, JsonMappingException, IOException {
67 ObjectMapper jackson = new ObjectMapper();
68 PartyId p = jackson.readValue(asJson, PartyId.class);
69 System.out.println(p);
70 assertEquals(party1, p);
71 }
72
73}
Note: See TracBrowser for help on using the repository browser.