[595] | 1 | package geniusweb.issuevalue;
|
---|
| 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 DiscreteValueTest extends GeneralTests<DiscreteValue> {
|
---|
| 18 | private final DiscreteValue value = new DiscreteValue("a");
|
---|
| 19 | private final DiscreteValue value1 = new DiscreteValue("a");
|
---|
| 20 | private final DiscreteValue valueb = new DiscreteValue("b");
|
---|
| 21 | private final String serialized = "\"a\"";
|
---|
| 22 | private static final ObjectMapper jackson = new ObjectMapper();
|
---|
| 23 |
|
---|
| 24 | @Test
|
---|
| 25 | public void testSerialize() throws JsonProcessingException {
|
---|
| 26 | assertEquals(serialized, jackson.writeValueAsString(value));
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | @Test
|
---|
| 30 | public void testDeserialize() throws IOException {
|
---|
| 31 | assertEquals(value, jackson.readValue(serialized, DiscreteValue.class));
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | @Test
|
---|
| 35 | public void testDeserializeFromValue() throws IOException {
|
---|
| 36 | assertEquals(value, jackson.readValue(serialized, Value.class));
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | @Override
|
---|
| 40 | public List<List<DiscreteValue>> getGeneralTestData() {
|
---|
[846] | 41 | List<List<DiscreteValue>> testlist = new LinkedList<>();
|
---|
| 42 | testlist.add(Arrays.asList(value, value1));
|
---|
| 43 | testlist.add(Arrays.asList(valueb));
|
---|
| 44 | return testlist;
|
---|
[595] | 45 | }
|
---|
| 46 |
|
---|
| 47 | @Override
|
---|
| 48 | public List<String> getGeneralTestStrings() {
|
---|
| 49 | return Arrays.asList(serialized, "\"b\"");
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | } |
---|