1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.yaml.snakeyaml;
18
19 import junit.framework.TestCase;
20
21 import org.junit.Test;
22 import org.yaml.snakeyaml.constructor.Constructor;
23 import org.yaml.snakeyaml.introspector.PropertyUtils;
24 import org.yaml.snakeyaml.representer.Representer;
25
26 public class PropertyUtilsSharingTest extends TestCase {
27
28 public void testYamlDefaults() {
29 Yaml yaml1 = new Yaml();
30 assertSame(yaml1.constructor.getPropertyUtils(), yaml1.representer.getPropertyUtils());
31
32 Yaml yaml2 = new Yaml(new Constructor());
33 assertSame(yaml2.constructor.getPropertyUtils(), yaml2.representer.getPropertyUtils());
34
35 Yaml yaml3 = new Yaml(new Representer());
36 assertSame(yaml3.constructor.getPropertyUtils(), yaml3.representer.getPropertyUtils());
37 }
38
39 public void testYamlConstructorWithPropertyUtils() {
40 Constructor constructor1 = new Constructor();
41 PropertyUtils pu = new PropertyUtils();
42 constructor1.setPropertyUtils(pu);
43 Yaml yaml = new Yaml(constructor1);
44 assertSame(pu, yaml.constructor.getPropertyUtils());
45 assertSame(pu, yaml.representer.getPropertyUtils());
46 }
47
48 public void testYamlRepresenterWithPropertyUtils() {
49 Representer representer2 = new Representer();
50 PropertyUtils pu = new PropertyUtils();
51 representer2.setPropertyUtils(pu);
52 Yaml yaml = new Yaml(representer2);
53 assertSame(pu, yaml.constructor.getPropertyUtils());
54 assertSame(pu, yaml.representer.getPropertyUtils());
55 }
56
57 @Test
58 public void testYamlConstructorANDRepresenterWithPropertyUtils() {
59 Constructor constructor = new Constructor();
60 PropertyUtils pu_c = new PropertyUtils();
61 constructor.setPropertyUtils(pu_c);
62 Representer representer = new Representer();
63 PropertyUtils pu_r = new PropertyUtils();
64 representer.setPropertyUtils(pu_r);
65 Yaml yaml = new Yaml(constructor, representer);
66 assertSame(pu_c, yaml.constructor.getPropertyUtils());
67 assertSame(pu_r, yaml.representer.getPropertyUtils());
68 }
69 }