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.issues.issue115;
17  
18  import junit.framework.TestCase;
19  
20  import org.yaml.snakeyaml.Yaml;
21  
22  public class ParameterizedTest extends TestCase {
23  
24      public void testAsStandalone() {
25          Parameterized<Integer> parm = new Parameterized<Integer>();
26          parm.t = 3;
27          Yaml yaml = new Yaml();
28          String result = yaml.dump(parm);
29          assertEquals("!!org.yaml.snakeyaml.issues.issue115.Parameterized {t: 3}\n", result);
30          @SuppressWarnings("unchecked")
31          // load
32          Parameterized<Integer> parmParsed = (Parameterized<Integer>) yaml.load(result);
33          assertEquals(new Integer(3), parmParsed.t);
34      }
35  
36      public void testAsJavaBeanProperty() {
37          Yaml yaml = new Yaml();
38          Issue issue = new Issue();
39          Parameterized<Integer> parm = new Parameterized<Integer>();
40          parm.t = 555;
41          issue.parm = parm;
42          String result = yaml.dump(issue);
43          assertEquals("!!org.yaml.snakeyaml.issues.issue115.Issue\nparm: {t: 555}\n", result);
44          // load
45          Issue issueParsed = (Issue) yaml.load(result);
46          assertEquals(new Integer(555), issueParsed.parm.t);
47      }
48  }
49  
50  class Issue {
51      public Parameterized<Integer> parm = new Parameterized<Integer>();
52  }
53  
54  class Parameterized<T> {
55      public T t;
56  }