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