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