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.issue50;
17  
18  import junit.framework.TestCase;
19  
20  import org.yaml.snakeyaml.Yaml;
21  
22  /**
23   * test issue 50.
24   */
25  public class SnakeyamlTest extends TestCase {
26      public static interface SomeBean {
27          String getAttribute1();
28  
29          String getAttribute2();
30      }
31  
32      /* public */static abstract class BaseSomeBean implements SomeBean {
33          private String attribute1;
34  
35          public String getAttribute1() {
36              return attribute1;
37          }
38  
39          public void setAttribute1(String attribute1) {
40              this.attribute1 = attribute1;
41          }
42      }
43  
44      public static final class SomeBeanImpl extends BaseSomeBean {
45          private String attribute2;
46  
47          public SomeBeanImpl(final String attribute1, final String attribute2) {
48              setAttribute1(attribute1);
49              setAttribute2(attribute2);
50          }
51  
52          public String getAttribute2() {
53              return attribute2;
54          }
55  
56          public void setAttribute2(String attribute2) {
57              this.attribute2 = attribute2;
58          }
59  
60          @Override
61          public String toString() {
62              return "SomeBeanImpl";
63          }
64      }
65  
66      public void testIntrospector() {
67          SomeBean someBean = new SomeBeanImpl("value1", "value2");
68          Yaml dumper = new Yaml();
69          String output = dumper.dump(someBean);
70          // System.out.println(output);
71          assertEquals(
72                  "!!org.yaml.snakeyaml.issues.issue50.SnakeyamlTest$SomeBeanImpl {attribute1: value1,\n  attribute2: value2}\n",
73                  output);
74      }
75  }