[52] | 1 | package geniusweb.actions;
|
---|
| 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 PartyIdTest1 extends GeneralTests<PartyId> {
|
---|
| 21 |
|
---|
| 22 | private PartyId party1, party1a, party2, party3;
|
---|
| 23 | private String asJson = "\"party1\"";
|
---|
| 24 |
|
---|
| 25 | @Before
|
---|
| 26 | public void before() throws URISyntaxException {
|
---|
| 27 | party1 = new PartyId("party1");
|
---|
| 28 | party1a = new PartyId("party1");
|
---|
| 29 | party2 = new PartyId("party2");
|
---|
| 30 | party3 = new PartyId("party3");
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | @Override
|
---|
| 34 | public List<List<PartyId>> getGeneralTestData() {
|
---|
| 35 | return Arrays.asList(Arrays.asList(party1, party1a),
|
---|
| 36 | Arrays.asList(party2), Arrays.asList(party3));
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | @Override
|
---|
| 40 | public List<String> getGeneralTestStrings() {
|
---|
| 41 | return Arrays.asList("party1", "party2", "party3");
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | @SuppressWarnings("unused")
|
---|
| 45 | @Test(expected = IllegalArgumentException.class)
|
---|
| 46 | public void smokeTest() throws URISyntaxException {
|
---|
| 47 | new PartyId("*Csh789&@#^!^@^&");
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | @SuppressWarnings("unused")
|
---|
| 51 | @Test(expected = IllegalArgumentException.class)
|
---|
| 52 | public void nullTest() throws URISyntaxException {
|
---|
| 53 | new PartyId(null);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | @Test
|
---|
| 57 | public void testSerialize() throws JsonProcessingException {
|
---|
| 58 | ObjectMapper jackson = new ObjectMapper();
|
---|
| 59 |
|
---|
| 60 | String json = jackson.writeValueAsString(party1);
|
---|
| 61 | System.out.println(json);
|
---|
| 62 | assertEquals(asJson, json);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | @Test
|
---|
| 66 | public void testDeserialize()
|
---|
| 67 | throws JsonParseException, JsonMappingException, IOException {
|
---|
| 68 | ObjectMapper jackson = new ObjectMapper();
|
---|
| 69 | PartyId p = jackson.readValue(asJson, PartyId.class);
|
---|
| 70 | System.out.println(p);
|
---|
| 71 | assertEquals(party1, p);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | }
|
---|