1733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt/**
2733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt * Copyright (c) 2008, http://www.snakeyaml.org
3877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca *
4733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt * Licensed under the Apache License, Version 2.0 (the "License");
5733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt * you may not use this file except in compliance with the License.
6733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt * You may obtain a copy of the License at
7733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt *
8733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt *     http://www.apache.org/licenses/LICENSE-2.0
9733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt *
10733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt * Unless required by applicable law or agreed to in writing, software
11733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt * distributed under the License is distributed on an "AS IS" BASIS,
12733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt * See the License for the specific language governing permissions and
14733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt * limitations under the License.
15733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt */
16733d32f3765be84a7e908df7e99a278cadcee853Eric Anholtpackage org.yaml.snakeyaml;
17733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt
18733d32f3765be84a7e908df7e99a278cadcee853Eric Anholtimport junit.framework.TestCase;
19733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt
20733d32f3765be84a7e908df7e99a278cadcee853Eric Anholtimport org.junit.Test;
21877128505431adaf817dc8069172ebe4a1cdf5d8José Fonsecaimport org.yaml.snakeyaml.constructor.Constructor;
22733d32f3765be84a7e908df7e99a278cadcee853Eric Anholtimport org.yaml.snakeyaml.introspector.PropertyUtils;
23733d32f3765be84a7e908df7e99a278cadcee853Eric Anholtimport org.yaml.snakeyaml.representer.Representer;
24733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt
25733d32f3765be84a7e908df7e99a278cadcee853Eric Anholtpublic class PropertyUtilsSharingTest extends TestCase {
26733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt
27733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt    public void testYamlDefaults() {
28733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        Yaml yaml1 = new Yaml();
29733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        assertSame(yaml1.constructor.getPropertyUtils(), yaml1.representer.getPropertyUtils());
30733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt
31733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        Yaml yaml2 = new Yaml(new Constructor());
32733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        assertSame(yaml2.constructor.getPropertyUtils(), yaml2.representer.getPropertyUtils());
33733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt
34733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        Yaml yaml3 = new Yaml(new Representer());
35733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        assertSame(yaml3.constructor.getPropertyUtils(), yaml3.representer.getPropertyUtils());
36733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt    }
37733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt
38733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt    public void testYamlConstructorWithPropertyUtils() {
39733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        Constructor constructor1 = new Constructor();
40733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        PropertyUtils pu = new PropertyUtils();
41733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        constructor1.setPropertyUtils(pu);
42733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        Yaml yaml = new Yaml(constructor1);
43733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        assertSame(pu, yaml.constructor.getPropertyUtils());
44733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        assertSame(pu, yaml.representer.getPropertyUtils());
45733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt    }
46733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt
47733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt    public void testYamlRepresenterWithPropertyUtils() {
48733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        Representer representer2 = new Representer();
49733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        PropertyUtils pu = new PropertyUtils();
50733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        representer2.setPropertyUtils(pu);
51733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        Yaml yaml = new Yaml(representer2);
52733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        assertSame(pu, yaml.constructor.getPropertyUtils());
53733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        assertSame(pu, yaml.representer.getPropertyUtils());
54733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt    }
55733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt
56733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt    @Test
57733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt    public void testYamlConstructorANDRepresenterWithPropertyUtils() {
58733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        Constructor constructor = new Constructor();
59733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        PropertyUtils pu_c = new PropertyUtils();
60733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        constructor.setPropertyUtils(pu_c);
61733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        Representer representer = new Representer();
62733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        PropertyUtils pu_r = new PropertyUtils();
63733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        representer.setPropertyUtils(pu_r);
64733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        Yaml yaml = new Yaml(constructor, representer);
65733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        assertSame(pu_c, yaml.constructor.getPropertyUtils());
66733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt        assertSame(pu_r, yaml.representer.getPropertyUtils());
67733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt    }
68733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt}
69733d32f3765be84a7e908df7e99a278cadcee853Eric Anholt