View Javadoc

    1   /**
    2    * Copyright (c) 2008-2011, 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
    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  }