View Javadoc

1   /**
2    * Copyright (c) 2008-2012, http://www.snakeyaml.org
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }