• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2008, 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 examples;
17 
18 import java.util.List;
19 import java.util.Map;
20 
21 import junit.framework.TestCase;
22 
23 import org.yaml.snakeyaml.Util;
24 import org.yaml.snakeyaml.Yaml;
25 
26 public class AnyObjectExampleTest extends TestCase {
27     @SuppressWarnings("unchecked")
testLoad()28     public void testLoad() {
29         String doc = Util.getLocalResource("examples/any-object-example.yaml");
30         Yaml yaml = new Yaml();
31         Map<String, Object> object = (Map<String, Object>) yaml.load(doc);
32         assertEquals(6, object.size());
33         assertEquals("[null, null]", object.get("none").toString());
34         List<?> list1 = (List<?>) object.get("none");
35         assertEquals(2, list1.size());
36         for (Object object2 : list1) {
37             assertNull(object2);
38         }
39         //
40         assertEquals("[true, false, true, false]", object.get("bool").toString());
41         assertEquals(4, ((List<?>) object.get("bool")).size());
42         //
43         assertEquals(new Integer(42), object.get("int"));
44         assertEquals(new Double(3.14159), object.get("float"));
45         //
46         assertEquals("[LITE, RES_ACID, SUS_DEXT]", object.get("list").toString());
47         List<?> list2 = (List<?>) object.get("list");
48         assertEquals(3, list2.size());
49         for (Object object2 : list2) {
50             assertEquals(object2.toString(), object2.toString().toUpperCase());
51         }
52         //
53         assertEquals("{hp=13, sp=5}", object.get("dict").toString());
54         Map<String, Integer> map = (Map<String, Integer>) object.get("dict");
55         assertEquals(2, map.keySet().size());
56         assertEquals(new Integer(13), map.get("hp"));
57         assertEquals(new Integer(5), map.get("sp"));
58     }
59 }
60