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