/
ExampleBeanTest.java
75 lines (53 loc) · 2.08 KB
/
ExampleBeanTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package de.galan.verjson.examples.simple;
import static org.assertj.core.api.Assertions.*;
import org.junit.Before;
import org.junit.Test;
import com.google.common.collect.Lists;
import de.galan.commons.test.AbstractTestParent;
import de.galan.verjson.core.Verjson;
/**
* Note: I "cheated" in this example, it is not necessary to copy and/or rename the models (ExampleBean1/ExampleBean2).
* This is done to keep seperate versions inside the same package and have a clear seperation for demonstration
* purposes. Usually it is intended (and the goal of Verjson) that you have only one version of your models.
*
* @author daniel
*/
public class ExampleBeanTest extends AbstractTestParent {
private Verjson<ExampleBean1> verjson1;
private Verjson<ExampleBean2> verjson2;
@Before
public void before() {
verjson1 = Verjson.create(ExampleBean1.class, null);
verjson2 = Verjson.create(ExampleBean2.class, new ExampleBeanVersions());
}
@Test
public void exampleBean1() throws Exception {
ExampleBean1 bean1 = new ExampleBean1();
bean1.text = "Hello";
bean1.number = 42L;
String serializedBean1 = verjson1.write(bean1);
ExampleBean1 deserializedBean1 = verjson1.read(serializedBean1);
assertThat(deserializedBean1.text).isEqualTo("Hello");
assertThat(deserializedBean1.number).isEqualTo(42L);
}
@Test
public void exampleBean2() throws Exception {
ExampleBean2 bean2 = new ExampleBean2();
bean2.texts = Lists.newArrayList("Hello");
bean2.counter = 42L;
String serializedBean2 = verjson2.write(bean2);
ExampleBean2 deserializedBean2 = verjson2.read(serializedBean2);
assertThat(deserializedBean2.texts).containsSequence("Hello");
assertThat(deserializedBean2.counter).isEqualTo(42L);
}
@Test
public void exampleBean1To2() throws Exception {
ExampleBean1 bean1 = new ExampleBean1();
bean1.text = "Hello";
bean1.number = 42L;
String serializedBean1 = verjson1.write(bean1);
ExampleBean2 deserializedBean2 = verjson2.read(serializedBean1);
assertThat(deserializedBean2.texts).containsSequence("Hello");
assertThat(deserializedBean2.counter).isEqualTo(42L);
}
}