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.nodes;
18  
19  import junit.framework.TestCase;
20  
21  import org.yaml.snakeyaml.DumperOptions;
22  import org.yaml.snakeyaml.Yaml;
23  
24  public class TagsTest extends TestCase {
25  
26      public void testGetGlobalTagForClass() {
27          assertEquals(new Tag("tag:yaml.org,2002:java.lang.String"), new Tag(String.class));
28          assertEquals(new Tag("tag:yaml.org,2002:org.yaml.snakeyaml.nodes.TagsTest"), new Tag(
29                  TagsTest.class));
30      }
31  
32      /**
33       * test fix for issue 18 -
34       * http://code.google.com/p/snakeyaml/issues/detail?id=18
35       */
36      public void testLong() {
37          DumperOptions options = new DumperOptions();
38          options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
39          Yaml yaml = new Yaml(options);
40          Foo foo = new Foo();
41          String output = yaml.dump(foo);
42          // System.out.println(output);
43          Foo foo2 = (Foo) yaml.load(output);
44          assertEquals(new Long(42L), foo2.getBar());
45      }
46  
47      public static class Foo {
48          private Long bar = Long.valueOf(42L);
49  
50          public Long getBar() {
51              return bar;
52          }
53  
54          public void setBar(Long bar) {
55              this.bar = bar;
56          }
57      }
58  }