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.types;
    18
    19  import java.io.IOException;
    20  import java.util.Map;
    21
    22  import org.yaml.snakeyaml.YamlDocument;
    23
    24  /**
    25   * @see http://yaml.org/type/map.html
    26   */
    27  public class MapTagTest extends AbstractTest {
    28
    29      @SuppressWarnings("unchecked")
    30      public void testMap() throws IOException {
    31          YamlDocument document = new YamlDocument("types/map.yaml");
    32          Map<String, Map<String, String>> map = (Map<String, Map<String, String>>) document
    33                  .getNativeData();
    34          assertEquals(2, map.size());
    35          Map<String, String> map1 = (Map<String, String>) map.get("Block style");
    36          assertEquals(3, map1.size());
    37          assertEquals("Evans", map1.get("Clark"));
    38          assertEquals("Ingerson", map1.get("Brian"));
    39          assertEquals("Ben-Kiki", map1.get("Oren"));
    40          //
    41          Map<String, String> map2 = (Map<String, String>) map.get("Flow style");
    42          assertEquals(3, map2.size());
    43          assertEquals("Evans", map2.get("Clark"));
    44          assertEquals("Ingerson", map2.get("Brian"));
    45          assertEquals("Ben-Kiki", map2.get("Oren"));
    46          //
    47          assertEquals(map1, map2);
    48          assertNotSame(map1, map2);
    49      }
    50
    51      @SuppressWarnings("unchecked")
    52      public void testMapYaml11() throws IOException {
    53          YamlDocument document = new YamlDocument("types/map_mixed_tags.yaml");
    54          Map<String, Map<String, String>> map = (Map<String, Map<String, String>>) document
    55                  .getNativeData();
    56          assertEquals(2, map.size());
    57          Map<String, String> map1 = (Map<String, String>) map.get("Block style");
    58          assertEquals(3, map1.size());
    59          assertEquals("Evans", map1.get("Clark"));
    60          assertEquals("Ingerson", map1.get("Brian"));
    61          assertEquals("Ben-Kiki", map1.get("Oren"));
    62          //
    63          Map<String, String> map2 = (Map<String, String>) map.get("Flow style");
    64          assertEquals(3, map2.size());
    65          assertEquals("Evans", map2.get("Clark"));
    66          assertEquals("Ingerson", map2.get("Brian"));
    67          assertEquals("Ben-Kiki", map2.get("Oren"));
    68          //
    69          assertEquals(map1, map2);
    70      }
    71
    72  }