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.types;
17  
18  import java.util.Map;
19  
20  import org.yaml.snakeyaml.YamlDocument;
21  
22  /**
23   * @see http://yaml.org/type/omap.html
24   */
25  public class OmapTagTest extends AbstractTest {
26  
27      @SuppressWarnings("unchecked")
28      public void testOmap() {
29          YamlDocument document = new YamlDocument("types/omap.yaml");
30          Map<String, Map<String, String>> map = (Map<String, Map<String, String>>) document
31                  .getNativeData();
32          assertEquals(2, map.size());
33          Map<String, String> map1 = (Map<String, String>) map.get("Bestiary");
34          assertEquals(3, map1.size());
35          assertEquals("African pig-like ant eater. Ugly.", map1.get("aardvark"));
36          assertEquals("South-American ant eater. Two species.", map1.get("anteater"));
37          assertEquals("South-American constrictor snake. Scaly.", map1.get("anaconda"));
38          //
39          Map<String, String> map2 = (Map<String, String>) map.get("Numbers");
40          assertEquals(3, map2.size());
41          assertEquals(new Integer(1), map2.get("one"));
42          assertEquals(new Integer(2), map2.get("two"));
43          assertEquals(new Integer(3), map2.get("three"));
44      }
45  
46  }