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