1 | package geniusweb.profile.utilityspace;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.mockito.Mockito.mock;
|
---|
5 |
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.util.Arrays;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import org.junit.Test;
|
---|
11 |
|
---|
12 | import com.fasterxml.jackson.core.JsonParseException;
|
---|
13 | import com.fasterxml.jackson.databind.JsonMappingException;
|
---|
14 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
15 |
|
---|
16 | import geniusweb.issuevalue.DiscreteValue;
|
---|
17 | import geniusweb.issuevalue.Value;
|
---|
18 | import tudelft.utilities.junit.GeneralTests;
|
---|
19 |
|
---|
20 | public class ProductOfValueTest extends GeneralTests<ProductOfValue> {
|
---|
21 | private final static ObjectMapper jackson = new ObjectMapper();
|
---|
22 |
|
---|
23 | private final static Value value1 = new DiscreteValue("val1");
|
---|
24 | private final static Value value2 = new DiscreteValue("val2");
|
---|
25 | private final static ProductOfValue values1 = new ProductOfValue(
|
---|
26 | Arrays.asList(value1, value2));
|
---|
27 | private final static ProductOfValue values1a = new ProductOfValue(
|
---|
28 | Arrays.asList(value1, value2));
|
---|
29 | private final static ProductOfValue values2 = new ProductOfValue(
|
---|
30 | Arrays.asList(value2));
|
---|
31 | private final static DiscreteValue low = new DiscreteValue("low");
|
---|
32 | private final static DiscreteValue high = new DiscreteValue("high");
|
---|
33 |
|
---|
34 | private String jsontext = "[\"val1\",\"val2\"]";
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public List<List<ProductOfValue>> getGeneralTestData() {
|
---|
38 | return Arrays.asList(Arrays.asList(values1, values1a),
|
---|
39 | Arrays.asList(values2));
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public List<String> getGeneralTestStrings() {
|
---|
44 | return Arrays.asList(".*\"val1\", \"val2\".*", ".*\"val2\".*");
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Test
|
---|
48 | public void testSerialize()
|
---|
49 | throws JsonParseException, JsonMappingException, IOException {
|
---|
50 |
|
---|
51 | assertEquals(jsontext, jackson.writeValueAsString(values1));
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Test
|
---|
55 | public void testBasicDeserialize()
|
---|
56 | throws JsonParseException, JsonMappingException, IOException {
|
---|
57 | System.out.println(jsontext);
|
---|
58 | assertEquals(values1,
|
---|
59 | jackson.readValue(jsontext, ProductOfValue.class));
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Test
|
---|
63 | public void testMerge() {
|
---|
64 | Value val1 = mock(Value.class);
|
---|
65 | Value val2 = mock(Value.class);
|
---|
66 | Value val3 = mock(Value.class);
|
---|
67 | Value val4 = mock(Value.class);
|
---|
68 |
|
---|
69 | ProductOfValue prodOfVal1 = new ProductOfValue(
|
---|
70 | Arrays.asList(val1, val2));
|
---|
71 | ProductOfValue prodOfVal2 = new ProductOfValue(
|
---|
72 | Arrays.asList(val3, val4));
|
---|
73 |
|
---|
74 | ProductOfValue prodVal = prodOfVal1.merge(prodOfVal2);
|
---|
75 | assertEquals(4, prodVal.getValues().size());
|
---|
76 | }
|
---|
77 |
|
---|
78 | }
|
---|