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.issue73;
18  
19  import java.util.ArrayList;
20  
21  import junit.framework.TestCase;
22  
23  import org.yaml.snakeyaml.Yaml;
24  
25  /**
26   * Test bean when the implementation is defined: ArrayList instead of just the
27   * interface List
28   */
29  public class ArrayListTest extends TestCase {
30      public void testListImplementation() {
31          Bean1 bean = new Bean1();
32          bean.setId("ID123");
33          ArrayList<String> list = new ArrayList<String>(3);
34          list.add("zzz");
35          list.add("xxx");
36          list.add("ccc");
37          bean.setList(list);
38          Yaml yaml = new Yaml();
39          String doc = yaml.dump(bean);
40          // System.out.println(doc);
41          Bean1 loaded = (Bean1) yaml.load(doc);
42          assertEquals(3, loaded.getList().size());
43          assertEquals(ArrayList.class, loaded.getList().getClass());
44      }
45  
46      public static class Bean1 {
47          private ArrayList<String> list;
48          private String id;
49  
50          public ArrayList<String> getList() {
51              return list;
52          }
53  
54          public void setList(ArrayList<String> list) {
55              this.list = list;
56          }
57  
58          public String getId() {
59              return id;
60          }
61  
62          public void setId(String id) {
63              this.id = id;
64          }
65      }
66  }